index.cjs 1.7 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607
  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-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-format/src/utils/is-class.js"() {
  31191. }
  31192. });
  31193. // node_modules/@e22m4u/js-format/src/utils/index.js
  31194. var init_utils = __esm({
  31195. "node_modules/@e22m4u/js-format/src/utils/index.js"() {
  31196. init_is_class();
  31197. }
  31198. });
  31199. // 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 BASE_CTOR_NAMES.includes(input.constructor.name) ? input.constructor.name : `${input.constructor.name} (instance)`;
  31208. if (typeof input === "object" && input.constructor == null) return "Object";
  31209. return String(input);
  31210. }
  31211. var BASE_CTOR_NAMES;
  31212. var init_value_to_string = __esm({
  31213. "node_modules/@e22m4u/js-format/src/value-to-string.js"() {
  31214. init_utils();
  31215. BASE_CTOR_NAMES = [
  31216. "String",
  31217. "Number",
  31218. "Boolean",
  31219. "Object",
  31220. "Array",
  31221. "Function",
  31222. "Symbol",
  31223. "Map",
  31224. "Set",
  31225. "Date"
  31226. ];
  31227. }
  31228. });
  31229. // node_modules/@e22m4u/js-format/src/array-to-list.js
  31230. function arrayToList(input) {
  31231. if (Array.isArray(input) && input.length)
  31232. return input.map(valueToString).join(SEPARATOR);
  31233. return valueToString(input);
  31234. }
  31235. var SEPARATOR;
  31236. var init_array_to_list = __esm({
  31237. "node_modules/@e22m4u/js-format/src/array-to-list.js"() {
  31238. init_value_to_string();
  31239. SEPARATOR = ", ";
  31240. }
  31241. });
  31242. // node_modules/@e22m4u/js-format/src/format.js
  31243. function format(pattern) {
  31244. if (pattern instanceof Date) {
  31245. pattern = pattern.toISOString();
  31246. } else if (typeof pattern !== "string") {
  31247. pattern = String(pattern);
  31248. }
  31249. const re = /(%?)(%([sdjvl]))/g;
  31250. const args = Array.prototype.slice.call(arguments, 1);
  31251. if (args.length) {
  31252. pattern = pattern.replace(re, function(match, escaped, ptn, flag) {
  31253. let arg = args.shift();
  31254. switch (flag) {
  31255. case "s":
  31256. arg = String(arg);
  31257. break;
  31258. case "d":
  31259. arg = Number(arg);
  31260. break;
  31261. case "j":
  31262. arg = JSON.stringify(arg);
  31263. break;
  31264. case "v":
  31265. arg = valueToString(arg);
  31266. break;
  31267. case "l":
  31268. arg = arrayToList(arg);
  31269. break;
  31270. }
  31271. if (!escaped) return arg;
  31272. args.unshift(arg);
  31273. return match;
  31274. });
  31275. }
  31276. if (args.length) pattern += " " + args.join(" ");
  31277. pattern = pattern.replace(/%{2}/g, "%");
  31278. return "" + pattern;
  31279. }
  31280. var init_format = __esm({
  31281. "node_modules/@e22m4u/js-format/src/format.js"() {
  31282. init_array_to_list();
  31283. init_value_to_string();
  31284. }
  31285. });
  31286. // node_modules/@e22m4u/js-format/src/errorf.js
  31287. var Errorf;
  31288. var init_errorf = __esm({
  31289. "node_modules/@e22m4u/js-format/src/errorf.js"() {
  31290. init_format();
  31291. Errorf = class extends Error {
  31292. /**
  31293. * Constructor.
  31294. *
  31295. * @param {string|undefined} pattern
  31296. * @param {any} args
  31297. */
  31298. constructor(pattern = void 0, ...args) {
  31299. const message = pattern != null ? format(pattern, ...args) : void 0;
  31300. super(message);
  31301. }
  31302. };
  31303. }
  31304. });
  31305. // node_modules/@e22m4u/js-format/src/index.js
  31306. var init_src = __esm({
  31307. "node_modules/@e22m4u/js-format/src/index.js"() {
  31308. init_format();
  31309. init_errorf();
  31310. }
  31311. });
  31312. // node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js
  31313. var InvalidArgumentError;
  31314. var init_invalid_argument_error = __esm({
  31315. "node_modules/@e22m4u/js-service/src/errors/invalid-argument-error.js"() {
  31316. init_src();
  31317. InvalidArgumentError = class extends Errorf {
  31318. };
  31319. }
  31320. });
  31321. // node_modules/@e22m4u/js-service/src/errors/index.js
  31322. var init_errors = __esm({
  31323. "node_modules/@e22m4u/js-service/src/errors/index.js"() {
  31324. init_invalid_argument_error();
  31325. }
  31326. });
  31327. // node_modules/@e22m4u/js-service/src/service-container.js
  31328. var ServiceContainer;
  31329. var init_service_container = __esm({
  31330. "node_modules/@e22m4u/js-service/src/service-container.js"() {
  31331. init_service();
  31332. init_errors();
  31333. ServiceContainer = class _ServiceContainer {
  31334. /**
  31335. * Services map.
  31336. *
  31337. * @type {Map<any, any>}
  31338. * @private
  31339. */
  31340. _services = /* @__PURE__ */ new Map();
  31341. /**
  31342. * Parent container.
  31343. *
  31344. * @type {ServiceContainer}
  31345. * @private
  31346. */
  31347. _parent;
  31348. /**
  31349. * Constructor.
  31350. *
  31351. * @param {ServiceContainer|undefined} parent
  31352. */
  31353. constructor(parent = void 0) {
  31354. if (parent != null) {
  31355. if (!(parent instanceof _ServiceContainer))
  31356. throw new InvalidArgumentError(
  31357. 'The provided parameter "parent" of ServicesContainer.constructor must be an instance ServiceContainer, but %v given.',
  31358. parent
  31359. );
  31360. this._parent = parent;
  31361. }
  31362. }
  31363. /**
  31364. * Получить существующий или новый экземпляр.
  31365. *
  31366. * @param {*} ctor
  31367. * @param {*} args
  31368. * @return {*}
  31369. */
  31370. get(ctor, ...args) {
  31371. if (!ctor || typeof ctor !== "function")
  31372. throw new InvalidArgumentError(
  31373. "The first argument of ServicesContainer.get must be a class constructor, but %v given.",
  31374. ctor
  31375. );
  31376. if (!this._services.has(ctor) && this._parent && this._parent.has(ctor)) {
  31377. return this._parent.get(ctor);
  31378. }
  31379. let service = this._services.get(ctor);
  31380. if (!service || args.length) {
  31381. service = "prototype" in ctor && ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31382. this._services.set(ctor, service);
  31383. } else if (typeof service === "function") {
  31384. service = service();
  31385. this._services.set(ctor, service);
  31386. }
  31387. return service;
  31388. }
  31389. /**
  31390. * Проверка существования конструктора в контейнере.
  31391. *
  31392. * @param {*} ctor
  31393. * @return {boolean}
  31394. */
  31395. has(ctor) {
  31396. if (this._services.has(ctor)) return true;
  31397. if (this._parent) return this._parent.has(ctor);
  31398. return false;
  31399. }
  31400. /**
  31401. * Добавить конструктор в контейнер.
  31402. *
  31403. * @param {*} ctor
  31404. * @param {*} args
  31405. * @return {this}
  31406. */
  31407. add(ctor, ...args) {
  31408. if (!ctor || typeof ctor !== "function")
  31409. throw new InvalidArgumentError(
  31410. "The first argument of ServicesContainer.add must be a class constructor, but %v given.",
  31411. ctor
  31412. );
  31413. const factory = () => ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31414. this._services.set(ctor, factory);
  31415. return this;
  31416. }
  31417. /**
  31418. * Добавить конструктор и создать экземпляр.
  31419. *
  31420. * @param {*} ctor
  31421. * @param {*} args
  31422. * @return {this}
  31423. */
  31424. use(ctor, ...args) {
  31425. if (!ctor || typeof ctor !== "function")
  31426. throw new InvalidArgumentError(
  31427. "The first argument of ServicesContainer.use must be a class constructor, but %v given.",
  31428. ctor
  31429. );
  31430. const service = ctor.prototype instanceof Service ? new ctor(this, ...args) : new ctor(...args);
  31431. this._services.set(ctor, service);
  31432. return this;
  31433. }
  31434. /**
  31435. * Добавить конструктор и связанный экземпляр.
  31436. *
  31437. * @param {*} ctor
  31438. * @param {*} service
  31439. * @return {this}
  31440. */
  31441. set(ctor, service) {
  31442. if (!ctor || typeof ctor !== "function")
  31443. throw new InvalidArgumentError(
  31444. "The first argument of ServicesContainer.set must be a class constructor, but %v given.",
  31445. ctor
  31446. );
  31447. if (!service || typeof service !== "object" || Array.isArray(service))
  31448. throw new InvalidArgumentError(
  31449. "The second argument of ServicesContainer.set must be an Object, but %v given.",
  31450. service
  31451. );
  31452. this._services.set(ctor, service);
  31453. return this;
  31454. }
  31455. };
  31456. }
  31457. });
  31458. // node_modules/@e22m4u/js-service/src/service.js
  31459. var Service;
  31460. var init_service = __esm({
  31461. "node_modules/@e22m4u/js-service/src/service.js"() {
  31462. init_service_container();
  31463. Service = class {
  31464. /**
  31465. * Container.
  31466. *
  31467. * @type {ServiceContainer}
  31468. */
  31469. container;
  31470. /**
  31471. * Constructor.
  31472. *
  31473. * @param {ServiceContainer|undefined} container
  31474. */
  31475. constructor(container = void 0) {
  31476. this.container = container instanceof ServiceContainer ? container : new ServiceContainer();
  31477. }
  31478. /**
  31479. * Получить существующий или новый экземпляр.
  31480. *
  31481. * @param {*} ctor
  31482. * @param {*} args
  31483. * @return {*}
  31484. */
  31485. getService(ctor, ...args) {
  31486. return this.container.get(ctor, ...args);
  31487. }
  31488. /**
  31489. * Проверка существования конструктора в контейнере.
  31490. *
  31491. * @param {*} ctor
  31492. * @return {boolean}
  31493. */
  31494. hasService(ctor) {
  31495. return this.container.has(ctor);
  31496. }
  31497. /**
  31498. * Добавить конструктор в контейнер.
  31499. *
  31500. * @param {*} ctor
  31501. * @param {*} args
  31502. * @return {this}
  31503. */
  31504. addService(ctor, ...args) {
  31505. this.container.add(ctor, ...args);
  31506. return this;
  31507. }
  31508. /**
  31509. * Добавить конструктор и создать экземпляр.
  31510. *
  31511. * @param {*} ctor
  31512. * @param {*} args
  31513. * @return {this}
  31514. */
  31515. useService(ctor, ...args) {
  31516. this.container.use(ctor, ...args);
  31517. return this;
  31518. }
  31519. /**
  31520. * Добавить конструктор и связанный экземпляр.
  31521. *
  31522. * @param {*} ctor
  31523. * @param {*} service
  31524. * @return {this}
  31525. */
  31526. setService(ctor, service) {
  31527. this.container.set(ctor, service);
  31528. return this;
  31529. }
  31530. };
  31531. }
  31532. });
  31533. // node_modules/@e22m4u/js-service/src/index.js
  31534. var init_src2 = __esm({
  31535. "node_modules/@e22m4u/js-service/src/index.js"() {
  31536. init_service();
  31537. init_service_container();
  31538. }
  31539. });
  31540. // node_modules/@e22m4u/js-repository/src/errors/not-implemented-error.js
  31541. var NotImplementedError;
  31542. var init_not_implemented_error = __esm({
  31543. "node_modules/@e22m4u/js-repository/src/errors/not-implemented-error.js"() {
  31544. init_src();
  31545. NotImplementedError = class extends Errorf {
  31546. };
  31547. }
  31548. });
  31549. // node_modules/@e22m4u/js-repository/src/errors/invalid-argument-error.js
  31550. var InvalidArgumentError2;
  31551. var init_invalid_argument_error2 = __esm({
  31552. "node_modules/@e22m4u/js-repository/src/errors/invalid-argument-error.js"() {
  31553. init_src();
  31554. InvalidArgumentError2 = class extends Errorf {
  31555. };
  31556. }
  31557. });
  31558. // node_modules/@e22m4u/js-repository/src/errors/invalid-operator-value-error.js
  31559. var InvalidOperatorValueError;
  31560. var init_invalid_operator_value_error = __esm({
  31561. "node_modules/@e22m4u/js-repository/src/errors/invalid-operator-value-error.js"() {
  31562. init_src();
  31563. InvalidOperatorValueError = class extends Error {
  31564. /**
  31565. * Constructor.
  31566. *
  31567. * @param {string} operator
  31568. * @param {string} expected
  31569. * @param {*} value
  31570. */
  31571. constructor(operator, expected, value) {
  31572. super(
  31573. format(
  31574. "Condition of {%s: ...} should have %s, but %v given.",
  31575. operator,
  31576. expected,
  31577. value
  31578. )
  31579. );
  31580. }
  31581. };
  31582. }
  31583. });
  31584. // node_modules/@e22m4u/js-repository/src/errors/index.js
  31585. var init_errors2 = __esm({
  31586. "node_modules/@e22m4u/js-repository/src/errors/index.js"() {
  31587. init_not_implemented_error();
  31588. init_invalid_argument_error2();
  31589. init_invalid_operator_value_error();
  31590. }
  31591. });
  31592. // node_modules/@e22m4u/js-repository/src/filter/slice-clause-tool.js
  31593. var SliceClauseTool;
  31594. var init_slice_clause_tool = __esm({
  31595. "node_modules/@e22m4u/js-repository/src/filter/slice-clause-tool.js"() {
  31596. init_src2();
  31597. init_errors2();
  31598. SliceClauseTool = class extends Service {
  31599. /**
  31600. * Slice.
  31601. *
  31602. * @param {object[]} entities
  31603. * @param {number|undefined} skip
  31604. * @param {number|undefined} limit
  31605. * @returns {object[]}
  31606. */
  31607. slice(entities, skip = void 0, limit = void 0) {
  31608. if (!Array.isArray(entities))
  31609. throw new InvalidArgumentError2(
  31610. "The first argument of SliceClauseTool.slice should be an Array, but %v given.",
  31611. entities
  31612. );
  31613. if (skip != null && typeof skip !== "number")
  31614. throw new InvalidArgumentError2(
  31615. 'The provided option "skip" should be a Number, but %v given.',
  31616. skip
  31617. );
  31618. if (limit != null && typeof limit !== "number")
  31619. throw new InvalidArgumentError2(
  31620. 'The provided option "limit" should be a Number, but %v given.',
  31621. limit
  31622. );
  31623. skip = skip || 0;
  31624. limit = limit || entities.length;
  31625. return entities.slice(skip, skip + limit);
  31626. }
  31627. /**
  31628. * Validate skip clause.
  31629. *
  31630. * @param {number|undefined} skip
  31631. */
  31632. static validateSkipClause(skip) {
  31633. if (skip == null) return;
  31634. if (typeof skip !== "number")
  31635. throw new InvalidArgumentError2(
  31636. 'The provided option "skip" should be a Number, but %v given.',
  31637. skip
  31638. );
  31639. }
  31640. /**
  31641. * Validate limit clause.
  31642. *
  31643. * @param {number|undefined} limit
  31644. */
  31645. static validateLimitClause(limit) {
  31646. if (limit == null) return;
  31647. if (typeof limit !== "number")
  31648. throw new InvalidArgumentError2(
  31649. 'The provided option "limit" should be a Number, but %v given.',
  31650. limit
  31651. );
  31652. }
  31653. };
  31654. }
  31655. });
  31656. // node_modules/@e22m4u/js-repository/src/utils/is-ctor.js
  31657. var init_is_ctor = __esm({
  31658. "node_modules/@e22m4u/js-repository/src/utils/is-ctor.js"() {
  31659. }
  31660. });
  31661. // node_modules/@e22m4u/js-repository/src/utils/is-promise.js
  31662. function isPromise(value) {
  31663. if (!value) return false;
  31664. if (typeof value !== "object") return false;
  31665. return typeof value.then === "function";
  31666. }
  31667. var init_is_promise = __esm({
  31668. "node_modules/@e22m4u/js-repository/src/utils/is-promise.js"() {
  31669. }
  31670. });
  31671. // node_modules/@e22m4u/js-repository/src/utils/capitalize.js
  31672. function capitalize(string) {
  31673. if (!string || typeof string !== "string") return string;
  31674. return string.charAt(0).toUpperCase() + string.slice(1);
  31675. }
  31676. var init_capitalize = __esm({
  31677. "node_modules/@e22m4u/js-repository/src/utils/capitalize.js"() {
  31678. }
  31679. });
  31680. // node_modules/@e22m4u/js-repository/src/utils/clone-deep.js
  31681. function cloneDeep(value) {
  31682. if (!value) return value;
  31683. const types = [Number, String, Boolean];
  31684. let result;
  31685. types.forEach((type) => {
  31686. if (value instanceof type) result = type(value);
  31687. });
  31688. if (result === void 0) {
  31689. if (Array.isArray(value)) {
  31690. result = [];
  31691. value.forEach((child, index) => {
  31692. result[index] = cloneDeep(child);
  31693. });
  31694. } else if (typeof value === "object") {
  31695. if ("nodeType" in value && value.nodeType && "cloneNode" in value && typeof value.cloneNode === "function") {
  31696. result = value.cloneNode(true);
  31697. } else if (!("prototype" in value) || !value.prototype) {
  31698. if (value instanceof Date) {
  31699. result = new Date(value);
  31700. } else if (value.constructor && value.constructor.name === "Object") {
  31701. result = {};
  31702. for (const key in value) {
  31703. result[key] = cloneDeep(value[key]);
  31704. }
  31705. } else {
  31706. result = value;
  31707. }
  31708. } else {
  31709. result = value;
  31710. }
  31711. } else {
  31712. result = value;
  31713. }
  31714. }
  31715. return result;
  31716. }
  31717. var init_clone_deep = __esm({
  31718. "node_modules/@e22m4u/js-repository/src/utils/clone-deep.js"() {
  31719. }
  31720. });
  31721. // node_modules/@e22m4u/js-repository/src/utils/singularize.js
  31722. function singularize(noun) {
  31723. if (!noun || typeof noun !== "string") return noun;
  31724. const endings = {
  31725. ves: "fe",
  31726. ies: "y",
  31727. i: "us",
  31728. zes: "ze",
  31729. ses: "s",
  31730. es: "e",
  31731. s: ""
  31732. };
  31733. return noun.replace(
  31734. new RegExp(`(${Object.keys(endings).join("|")})$`),
  31735. (r) => endings[r]
  31736. );
  31737. }
  31738. var init_singularize = __esm({
  31739. "node_modules/@e22m4u/js-repository/src/utils/singularize.js"() {
  31740. }
  31741. });
  31742. // node_modules/@e22m4u/js-repository/src/utils/is-deep-equal.js
  31743. function isDeepEqual(firstValue, secondValue) {
  31744. const cached = /* @__PURE__ */ new WeakMap();
  31745. const compare = (a, b) => {
  31746. if (a === null || b === null) return a === b;
  31747. if (typeof a !== "object" || typeof b !== "object") return a === b;
  31748. const dataTypeA = Array.isArray(a) ? "array" : "object";
  31749. const dataTypeB = Array.isArray(b) ? "array" : "object";
  31750. if (dataTypeA !== dataTypeB) return false;
  31751. const keysA = Object.keys(a);
  31752. const keysB = Object.keys(b);
  31753. if (keysA.length !== keysB.length) return false;
  31754. const symbolsA = Object.getOwnPropertySymbols(a);
  31755. const symbolsB = Object.getOwnPropertySymbols(b);
  31756. if (symbolsA.length !== symbolsB.length) return false;
  31757. let setForA = cached.get(a);
  31758. if (setForA == null) {
  31759. setForA = /* @__PURE__ */ new Set();
  31760. cached.set(a, setForA);
  31761. } else if (setForA.has(b)) {
  31762. return true;
  31763. }
  31764. setForA.add(b);
  31765. let setForB = cached.get(b);
  31766. if (setForB == null) {
  31767. setForB = /* @__PURE__ */ new Set();
  31768. cached.set(b, setForB);
  31769. } else if (setForB.has(a)) {
  31770. return true;
  31771. }
  31772. setForB.add(a);
  31773. const propertyNamesA = [...keysA, ...symbolsA];
  31774. for (const propertyNameA of propertyNamesA) {
  31775. if (!Object.prototype.hasOwnProperty.call(b, propertyNameA)) return false;
  31776. const propertyValueA = a[propertyNameA];
  31777. const propertyValueB = b[propertyNameA];
  31778. if (!compare(propertyValueA, propertyValueB)) return false;
  31779. }
  31780. return true;
  31781. };
  31782. return compare(firstValue, secondValue);
  31783. }
  31784. var init_is_deep_equal = __esm({
  31785. "node_modules/@e22m4u/js-repository/src/utils/is-deep-equal.js"() {
  31786. }
  31787. });
  31788. // node_modules/@e22m4u/js-repository/src/utils/get-ctor-name.js
  31789. function getCtorName(value) {
  31790. if (value === null) return "Null";
  31791. if (value === void 0) return "Undefined";
  31792. return value.constructor && value.constructor.name || void 0;
  31793. }
  31794. var init_get_ctor_name = __esm({
  31795. "node_modules/@e22m4u/js-repository/src/utils/get-ctor-name.js"() {
  31796. }
  31797. });
  31798. // node_modules/@e22m4u/js-repository/src/utils/is-pure-object.js
  31799. function isPureObject(value) {
  31800. return Boolean(
  31801. typeof value === "object" && value && !Array.isArray(value) && (!value.constructor || value.constructor && value.constructor.name === "Object")
  31802. );
  31803. }
  31804. var init_is_pure_object = __esm({
  31805. "node_modules/@e22m4u/js-repository/src/utils/is-pure-object.js"() {
  31806. }
  31807. });
  31808. // node_modules/@e22m4u/js-repository/src/utils/string-to-regexp.js
  31809. function stringToRegexp(pattern, flags = void 0) {
  31810. if (pattern instanceof RegExp) {
  31811. return new RegExp(pattern, flags);
  31812. }
  31813. let regex = "";
  31814. for (let i = 0, n = pattern.length; i < n; i++) {
  31815. const char = pattern.charAt(i);
  31816. if (char === "%") {
  31817. regex += ".*";
  31818. } else {
  31819. regex += char;
  31820. }
  31821. }
  31822. return new RegExp(regex, flags);
  31823. }
  31824. var init_string_to_regexp = __esm({
  31825. "node_modules/@e22m4u/js-repository/src/utils/string-to-regexp.js"() {
  31826. }
  31827. });
  31828. // node_modules/@e22m4u/js-repository/src/utils/get-value-by-path.js
  31829. function getValueByPath(obj, path, orElse = void 0) {
  31830. if (!obj || typeof obj !== "object") return orElse;
  31831. if (!path || typeof path !== "string") return orElse;
  31832. const keys = path.split(".");
  31833. let value = obj;
  31834. for (const key of keys) {
  31835. if (typeof value === "object" && value !== null && key in value) {
  31836. value = value[key];
  31837. } else {
  31838. value = orElse;
  31839. break;
  31840. }
  31841. }
  31842. return value;
  31843. }
  31844. var init_get_value_by_path = __esm({
  31845. "node_modules/@e22m4u/js-repository/src/utils/get-value-by-path.js"() {
  31846. }
  31847. });
  31848. // node_modules/@e22m4u/js-repository/src/utils/transform-promise.js
  31849. function transformPromise(valueOrPromise, transformer) {
  31850. return isPromise(valueOrPromise) ? valueOrPromise.then(transformer) : transformer(valueOrPromise);
  31851. }
  31852. var init_transform_promise = __esm({
  31853. "node_modules/@e22m4u/js-repository/src/utils/transform-promise.js"() {
  31854. init_is_promise();
  31855. }
  31856. });
  31857. // node_modules/@e22m4u/js-repository/src/utils/select-object-keys.js
  31858. function selectObjectKeys(obj, keys) {
  31859. if (!obj || typeof obj !== "object" || Array.isArray(obj))
  31860. throw new InvalidArgumentError2(
  31861. "The first argument of selectObjectKeys should be an Object, but %v given.",
  31862. obj
  31863. );
  31864. if (!Array.isArray(keys))
  31865. throw new InvalidArgumentError2(
  31866. "The second argument of selectObjectKeys should be an Array of String, but %v given.",
  31867. keys
  31868. );
  31869. keys.forEach((key) => {
  31870. if (typeof key !== "string")
  31871. throw new InvalidArgumentError2(
  31872. "The second argument of selectObjectKeys should be an Array of String, but %v given.",
  31873. key
  31874. );
  31875. });
  31876. const result = {};
  31877. const allKeys = Object.keys(obj);
  31878. allKeys.forEach((key) => {
  31879. if (keys.includes(key)) result[key] = obj[key];
  31880. });
  31881. return result;
  31882. }
  31883. var init_select_object_keys = __esm({
  31884. "node_modules/@e22m4u/js-repository/src/utils/select-object-keys.js"() {
  31885. init_errors2();
  31886. }
  31887. });
  31888. // node_modules/@e22m4u/js-repository/src/utils/exclude-object-keys.js
  31889. function excludeObjectKeys(obj, keys) {
  31890. if (typeof obj !== "object" || !obj || Array.isArray(obj))
  31891. throw new InvalidArgumentError2(
  31892. "Cannot exclude keys from a non-Object value, %v given.",
  31893. obj
  31894. );
  31895. const result = { ...obj };
  31896. keys = Array.isArray(keys) ? keys : [keys];
  31897. keys.forEach((key) => delete result[key]);
  31898. return result;
  31899. }
  31900. var init_exclude_object_keys = __esm({
  31901. "node_modules/@e22m4u/js-repository/src/utils/exclude-object-keys.js"() {
  31902. init_errors2();
  31903. }
  31904. });
  31905. // node_modules/@e22m4u/js-repository/src/utils/get-decorator-target-type.js
  31906. var init_get_decorator_target_type = __esm({
  31907. "node_modules/@e22m4u/js-repository/src/utils/get-decorator-target-type.js"() {
  31908. }
  31909. });
  31910. // node_modules/@e22m4u/js-repository/src/utils/index.js
  31911. var init_utils2 = __esm({
  31912. "node_modules/@e22m4u/js-repository/src/utils/index.js"() {
  31913. init_is_ctor();
  31914. init_is_promise();
  31915. init_capitalize();
  31916. init_clone_deep();
  31917. init_singularize();
  31918. init_is_deep_equal();
  31919. init_get_ctor_name();
  31920. init_is_pure_object();
  31921. init_string_to_regexp();
  31922. init_get_value_by_path();
  31923. init_transform_promise();
  31924. init_select_object_keys();
  31925. init_exclude_object_keys();
  31926. init_get_decorator_target_type();
  31927. }
  31928. });
  31929. // node_modules/@e22m4u/js-repository/src/filter/order-clause-tool.js
  31930. function compareFn(a, b) {
  31931. let undefinedA, undefinedB;
  31932. for (let i = 0, l = this.length; i < l; i++) {
  31933. const aVal = getValueByPath(a, this[i].key);
  31934. const bVal = getValueByPath(b, this[i].key);
  31935. undefinedB = bVal === void 0 && aVal !== void 0;
  31936. undefinedA = aVal === void 0 && bVal !== void 0;
  31937. if (undefinedB || aVal > bVal) {
  31938. return this[i].reverse;
  31939. } else if (undefinedA || aVal < bVal) {
  31940. return -1 * this[i].reverse;
  31941. }
  31942. }
  31943. return 0;
  31944. }
  31945. var OrderClauseTool;
  31946. var init_order_clause_tool = __esm({
  31947. "node_modules/@e22m4u/js-repository/src/filter/order-clause-tool.js"() {
  31948. init_src2();
  31949. init_utils2();
  31950. init_errors2();
  31951. OrderClauseTool = class extends Service {
  31952. /**
  31953. * Sort.
  31954. *
  31955. * @param {object[]} entities
  31956. * @param {string|string[]|undefined} clause
  31957. */
  31958. sort(entities, clause) {
  31959. if (clause == null) return;
  31960. if (Array.isArray(clause) === false) clause = [clause];
  31961. if (!clause.length) return;
  31962. const mapping = [];
  31963. clause.forEach((key, index) => {
  31964. if (!key || typeof key !== "string")
  31965. throw new InvalidArgumentError2(
  31966. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  31967. key
  31968. );
  31969. let reverse = 1;
  31970. const matches = key.match(/\s+(A|DE)SC$/i);
  31971. if (matches) {
  31972. key = key.replace(/\s+(A|DE)SC/i, "");
  31973. if (matches[1].toLowerCase() === "de") reverse = -1;
  31974. }
  31975. mapping[index] = { key, reverse };
  31976. });
  31977. entities.sort(compareFn.bind(mapping));
  31978. }
  31979. /**
  31980. * Validate order clause.
  31981. *
  31982. * @param {string|string[]|undefined} clause
  31983. */
  31984. static validateOrderClause(clause) {
  31985. if (clause == null) return;
  31986. if (Array.isArray(clause) === false) clause = [clause];
  31987. if (!clause.length) return;
  31988. clause.forEach((field) => {
  31989. if (!field || typeof field !== "string")
  31990. throw new InvalidArgumentError2(
  31991. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  31992. field
  31993. );
  31994. });
  31995. }
  31996. /**
  31997. * Normalize order clause.
  31998. *
  31999. * @param {string|string[]|undefined} clause
  32000. * @returns {string[]|undefined}
  32001. */
  32002. static normalizeOrderClause(clause) {
  32003. if (clause == null) return;
  32004. if (Array.isArray(clause) === false) clause = [clause];
  32005. if (!clause.length) return;
  32006. clause.forEach((field) => {
  32007. if (!field || typeof field !== "string")
  32008. throw new InvalidArgumentError2(
  32009. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  32010. field
  32011. );
  32012. });
  32013. return clause;
  32014. }
  32015. };
  32016. }
  32017. });
  32018. // node_modules/@e22m4u/js-repository/src/filter/operator-clause-tool.js
  32019. var OperatorClauseTool;
  32020. var init_operator_clause_tool = __esm({
  32021. "node_modules/@e22m4u/js-repository/src/filter/operator-clause-tool.js"() {
  32022. init_src2();
  32023. init_utils2();
  32024. init_errors2();
  32025. init_errors2();
  32026. OperatorClauseTool = class extends Service {
  32027. /**
  32028. * Compare.
  32029. *
  32030. * @param {*} val1 The 1st value
  32031. * @param {*} val2 The 2nd value
  32032. * @returns {number} 0: =, positive: >, negative <
  32033. */
  32034. compare(val1, val2) {
  32035. if (val1 == null || val2 == null) {
  32036. return val1 == val2 ? 0 : NaN;
  32037. }
  32038. if (typeof val1 === "number") {
  32039. if (typeof val2 === "number" || typeof val2 === "string" || typeof val2 === "boolean") {
  32040. if (val1 === val2) return 0;
  32041. return val1 - Number(val2);
  32042. }
  32043. return NaN;
  32044. }
  32045. if (typeof val1 === "string") {
  32046. const isDigits = /^\d+$/.test(val1);
  32047. if (isDigits) return this.compare(Number(val1), val2);
  32048. try {
  32049. if (val1 > val2) return 1;
  32050. if (val1 < val2) return -1;
  32051. if (val1 == val2) return 0;
  32052. } catch (e) {
  32053. }
  32054. return NaN;
  32055. }
  32056. if (typeof val1 === "boolean") {
  32057. return Number(val1) - Number(val2);
  32058. }
  32059. return val1 === val2 ? 0 : NaN;
  32060. }
  32061. /**
  32062. * Test all operators.
  32063. *
  32064. * @param {object} clause
  32065. * @param {*} value
  32066. * @returns {boolean|undefined}
  32067. */
  32068. testAll(clause, value) {
  32069. if (!clause || typeof clause !== "object" || Array.isArray(clause))
  32070. throw new InvalidArgumentError2(
  32071. "The first argument of OperatorUtils.testAll should be an Object, but %v given.",
  32072. clause
  32073. );
  32074. const eqNeqTest = this.testEqNeq(clause, value);
  32075. if (eqNeqTest !== void 0) return eqNeqTest;
  32076. const gtLtTest = this.testGtLt(clause, value);
  32077. if (gtLtTest !== void 0) return gtLtTest;
  32078. const incTest = this.testInq(clause, value);
  32079. if (incTest !== void 0) return incTest;
  32080. const ninTest = this.testNin(clause, value);
  32081. if (ninTest !== void 0) return ninTest;
  32082. const betweenTest = this.testBetween(clause, value);
  32083. if (betweenTest !== void 0) return betweenTest;
  32084. const existsTest = this.testExists(clause, value);
  32085. if (existsTest !== void 0) return existsTest;
  32086. const likeTest = this.testLike(clause, value);
  32087. if (likeTest !== void 0) return likeTest;
  32088. const nlikeTest = this.testNlike(clause, value);
  32089. if (nlikeTest !== void 0) return nlikeTest;
  32090. const ilikeTest = this.testIlike(clause, value);
  32091. if (ilikeTest !== void 0) return ilikeTest;
  32092. const nilikeTest = this.testNilike(clause, value);
  32093. if (nilikeTest !== void 0) return nilikeTest;
  32094. const regExpTest = this.testRegexp(clause, value);
  32095. if (regExpTest !== void 0) return regExpTest;
  32096. }
  32097. /**
  32098. * Test eq/neq operator.
  32099. *
  32100. * @example
  32101. * ```ts
  32102. * {
  32103. * eq: 'foo',
  32104. * }
  32105. * ```
  32106. *
  32107. * @example
  32108. * ```ts
  32109. * {
  32110. * neq: 'foo',
  32111. * }
  32112. * ```
  32113. *
  32114. * @param {object} clause
  32115. * @param {*} value
  32116. * @returns {boolean|undefined}
  32117. */
  32118. testEqNeq(clause, value) {
  32119. if (!clause || typeof clause !== "object")
  32120. throw new InvalidArgumentError2(
  32121. "The first argument of OperatorUtils.testEqNeq should be an Object, but %v given.",
  32122. clause
  32123. );
  32124. if ("eq" in clause) return this.compare(clause.eq, value) === 0;
  32125. if ("neq" in clause) return this.compare(clause.neq, value) !== 0;
  32126. }
  32127. /**
  32128. * Test lt/gt/lte/gte operator.
  32129. *
  32130. * @example
  32131. * ```ts
  32132. * {
  32133. * lt: 10,
  32134. * }
  32135. * ```
  32136. *
  32137. * @example
  32138. * ```ts
  32139. * {
  32140. * lte: 10,
  32141. * }
  32142. * ```
  32143. *
  32144. * @example
  32145. * ```ts
  32146. * {
  32147. * gt: 10,
  32148. * }
  32149. * ```
  32150. *
  32151. * @example
  32152. * ```ts
  32153. * {
  32154. * gte: 10,
  32155. * }
  32156. * ```
  32157. *
  32158. * @param {object} clause
  32159. * @param {*} value
  32160. * @returns {boolean|undefined}
  32161. */
  32162. testGtLt(clause, value) {
  32163. if (!clause || typeof clause !== "object")
  32164. throw new InvalidArgumentError2(
  32165. "The first argument of OperatorUtils.testGtLt should be an Object, but %v given.",
  32166. clause
  32167. );
  32168. if ("gt" in clause) return this.compare(value, clause.gt) > 0;
  32169. if ("gte" in clause) return this.compare(value, clause.gte) >= 0;
  32170. if ("lt" in clause) return this.compare(value, clause.lt) < 0;
  32171. if ("lte" in clause) return this.compare(value, clause.lte) <= 0;
  32172. }
  32173. /**
  32174. * Test inc operator.
  32175. *
  32176. * @example
  32177. * ```ts
  32178. * {
  32179. * inc: ['foo', 'bar'],
  32180. * }
  32181. * ```
  32182. *
  32183. * @param {object} clause
  32184. * @param {*} value
  32185. * @returns {boolean|undefined}
  32186. */
  32187. testInq(clause, value) {
  32188. if (!clause || typeof clause !== "object")
  32189. throw new InvalidArgumentError2(
  32190. "The first argument of OperatorUtils.testInq should be an Object, but %v given.",
  32191. clause
  32192. );
  32193. if ("inq" in clause && clause.inq !== void 0) {
  32194. if (!clause.inq || !Array.isArray(clause.inq)) {
  32195. throw new InvalidOperatorValueError(
  32196. "inq",
  32197. "an Array of possible values",
  32198. clause.inq
  32199. );
  32200. }
  32201. for (let i = 0; i < clause.inq.length; i++) {
  32202. if (clause.inq[i] == value) return true;
  32203. }
  32204. return false;
  32205. }
  32206. }
  32207. /**
  32208. * Test nin operator.
  32209. *
  32210. * @example
  32211. * ```ts
  32212. * {
  32213. * nin: ['foo', 'bar'],
  32214. * }
  32215. * ```
  32216. *
  32217. * @param {object} clause
  32218. * @param {*} value
  32219. * @returns {boolean|undefined}
  32220. */
  32221. testNin(clause, value) {
  32222. if (!clause || typeof clause !== "object")
  32223. throw new InvalidArgumentError2(
  32224. "The first argument of OperatorUtils.testNin should be an Object, but %v given.",
  32225. clause
  32226. );
  32227. if ("nin" in clause && clause.nin !== void 0) {
  32228. if (!clause.nin || !Array.isArray(clause.nin)) {
  32229. throw new InvalidOperatorValueError(
  32230. "nin",
  32231. "an Array of possible values",
  32232. clause.nin
  32233. );
  32234. }
  32235. for (let i = 0; i < clause.nin.length; i++) {
  32236. if (clause.nin[i] == value) return false;
  32237. }
  32238. return true;
  32239. }
  32240. }
  32241. /**
  32242. * Test between operator.
  32243. *
  32244. * @example
  32245. * ```ts
  32246. * {
  32247. * between: [10, 20],
  32248. * }
  32249. * ```
  32250. *
  32251. * @param {object} clause
  32252. * @param {*} value
  32253. * @returns {boolean|undefined}
  32254. */
  32255. testBetween(clause, value) {
  32256. if (!clause || typeof clause !== "object")
  32257. throw new InvalidArgumentError2(
  32258. "The first argument of OperatorUtils.testBetween should be an Object, but %v given.",
  32259. clause
  32260. );
  32261. if ("between" in clause && clause.between !== void 0) {
  32262. if (!Array.isArray(clause.between) || clause.between.length !== 2) {
  32263. throw new InvalidOperatorValueError(
  32264. "between",
  32265. "an Array of 2 elements",
  32266. clause.between
  32267. );
  32268. }
  32269. return this.testGtLt({ gte: clause.between[0] }, value) && this.testGtLt({ lte: clause.between[1] }, value);
  32270. }
  32271. }
  32272. /**
  32273. * Test exists operator.
  32274. *
  32275. * @example
  32276. * ```ts
  32277. * {
  32278. * exists: true,
  32279. * }
  32280. * ```
  32281. *
  32282. * @param {object} clause
  32283. * @param {*} value
  32284. * @returns {boolean|undefined}
  32285. */
  32286. testExists(clause, value) {
  32287. if (!clause || typeof clause !== "object")
  32288. throw new InvalidArgumentError2(
  32289. "The first argument of OperatorUtils.testExists should be an Object, but %v given.",
  32290. clause
  32291. );
  32292. if ("exists" in clause && clause.exists !== void 0) {
  32293. if (typeof clause.exists !== "boolean") {
  32294. throw new InvalidOperatorValueError(
  32295. "exists",
  32296. "a Boolean",
  32297. clause.exists
  32298. );
  32299. }
  32300. return clause.exists ? value !== void 0 : value === void 0;
  32301. }
  32302. }
  32303. /**
  32304. * Test like operator.
  32305. *
  32306. * @example
  32307. * ```ts
  32308. * {
  32309. * like: 'foo',
  32310. * }
  32311. * ```
  32312. *
  32313. * @param {object} clause
  32314. * @param {*} value
  32315. * @returns {boolean|undefined}
  32316. */
  32317. testLike(clause, value) {
  32318. if (!clause || typeof clause !== "object")
  32319. throw new InvalidArgumentError2(
  32320. "The first argument of OperatorUtils.testLike should be an Object, but %v given.",
  32321. clause
  32322. );
  32323. if ("like" in clause && clause.like !== void 0) {
  32324. if (typeof clause.like !== "string" && !(clause.like instanceof RegExp))
  32325. throw new InvalidOperatorValueError("like", "a String", clause.like);
  32326. return stringToRegexp(clause.like).test(value);
  32327. }
  32328. }
  32329. /**
  32330. * Test nlike operator.
  32331. *
  32332. * @example
  32333. * ```ts
  32334. * {
  32335. * nlike: 'foo',
  32336. * }
  32337. * ```
  32338. *
  32339. * @param {object} clause
  32340. * @param {*} value
  32341. * @returns {boolean|undefined}
  32342. */
  32343. testNlike(clause, value) {
  32344. if (!clause || typeof clause !== "object")
  32345. throw new InvalidArgumentError2(
  32346. "The first argument of OperatorUtils.testNlike should be an Object, but %v given.",
  32347. clause
  32348. );
  32349. if ("nlike" in clause && clause.nlike !== void 0) {
  32350. if (typeof clause.nlike !== "string" && !(clause.nlike instanceof RegExp)) {
  32351. throw new InvalidOperatorValueError("nlike", "a String", clause.nlike);
  32352. }
  32353. return !stringToRegexp(clause.nlike).test(value);
  32354. }
  32355. }
  32356. /**
  32357. * Test ilike operator.
  32358. *
  32359. * @example
  32360. * ```ts
  32361. * {
  32362. * ilike: 'foo',
  32363. * }
  32364. * ```
  32365. *
  32366. * @param {object} clause
  32367. * @param {*} value
  32368. * @returns {boolean|undefined}
  32369. */
  32370. testIlike(clause, value) {
  32371. if (!clause || typeof clause !== "object")
  32372. throw new InvalidArgumentError2(
  32373. "The first argument of OperatorUtils.testIlike should be an Object, but %v given.",
  32374. clause
  32375. );
  32376. if ("ilike" in clause && clause.ilike !== void 0) {
  32377. if (typeof clause.ilike !== "string" && !(clause.ilike instanceof RegExp)) {
  32378. throw new InvalidOperatorValueError("ilike", "a String", clause.ilike);
  32379. }
  32380. return stringToRegexp(clause.ilike, "i").test(value);
  32381. }
  32382. }
  32383. /**
  32384. * Test nilike operator.
  32385. *
  32386. * @example
  32387. * ```ts
  32388. * {
  32389. * nilike: 'foo',
  32390. * }
  32391. * ```
  32392. *
  32393. * @param {object} clause
  32394. * @param {*} value
  32395. * @returns {boolean|undefined}
  32396. */
  32397. testNilike(clause, value) {
  32398. if (!clause || typeof clause !== "object")
  32399. throw new InvalidArgumentError2(
  32400. "The first argument of OperatorUtils.testNilike should be an Object, but %v given.",
  32401. clause
  32402. );
  32403. if ("nilike" in clause && clause.nilike !== void 0) {
  32404. if (typeof clause.nilike !== "string" && !(clause.nilike instanceof RegExp)) {
  32405. throw new InvalidOperatorValueError(
  32406. "nilike",
  32407. "a String",
  32408. clause.nilike
  32409. );
  32410. }
  32411. return !stringToRegexp(clause.nilike, "i").test(value);
  32412. }
  32413. }
  32414. /**
  32415. * Test regexp.
  32416. *
  32417. * @example
  32418. * ```ts
  32419. * {
  32420. * regexp: 'foo.*',
  32421. * }
  32422. * ```
  32423. *
  32424. * @example
  32425. * ```ts
  32426. * {
  32427. * regexp: 'foo.*',
  32428. * flags: 'i',
  32429. * }
  32430. * ```
  32431. *
  32432. * @param {object} clause
  32433. * @param {*} value
  32434. * @returns {boolean|undefined}
  32435. */
  32436. testRegexp(clause, value) {
  32437. if (!clause || typeof clause !== "object")
  32438. throw new InvalidArgumentError2(
  32439. "The first argument of OperatorUtils.testRegexp should be an Object, but %v given.",
  32440. clause
  32441. );
  32442. if ("regexp" in clause && clause.regexp !== void 0) {
  32443. if (typeof clause.regexp !== "string" && !(clause.regexp instanceof RegExp)) {
  32444. throw new InvalidOperatorValueError(
  32445. "regexp",
  32446. "a String",
  32447. clause.regexp
  32448. );
  32449. }
  32450. const flags = clause.flags || void 0;
  32451. if (flags && typeof flags !== "string")
  32452. throw new InvalidArgumentError2(
  32453. "RegExp flags should be a String, but %v given.",
  32454. clause.flags
  32455. );
  32456. if (!value || typeof value !== "string") return false;
  32457. const regExp = stringToRegexp(clause.regexp, flags);
  32458. return !!value.match(regExp);
  32459. }
  32460. }
  32461. };
  32462. }
  32463. });
  32464. // node_modules/@e22m4u/js-repository/src/filter/where-clause-tool.js
  32465. var WhereClauseTool;
  32466. var init_where_clause_tool = __esm({
  32467. "node_modules/@e22m4u/js-repository/src/filter/where-clause-tool.js"() {
  32468. init_src2();
  32469. init_utils2();
  32470. init_errors2();
  32471. init_operator_clause_tool();
  32472. WhereClauseTool = class extends Service {
  32473. /**
  32474. * Filter by where clause.
  32475. *
  32476. * @example
  32477. * ```
  32478. * const entities = [
  32479. * {foo: 1, bar: 'a'},
  32480. * {foo: 2, bar: 'b'},
  32481. * {foo: 3, bar: 'b'},
  32482. * {foo: 4, bar: 'b'},
  32483. * ];
  32484. *
  32485. * const result = filterByWhereClause(entities, {
  32486. * foo: {gt: 2},
  32487. * bar: 'b',
  32488. * });
  32489. *
  32490. * console.log(result);
  32491. * // [
  32492. * // {foo: 3, bar: 'b'},
  32493. * // {foo: 4, bar: 'b'},
  32494. * // ];
  32495. *
  32496. * ```
  32497. *
  32498. * @param {object[]} entities
  32499. * @param {WhereClause|undefined} where
  32500. * @returns {object[]}
  32501. */
  32502. filter(entities, where = void 0) {
  32503. if (!Array.isArray(entities))
  32504. throw new InvalidArgumentError2(
  32505. "The first argument of WhereClauseTool.filter should be an Array of Object, but %v given.",
  32506. entities
  32507. );
  32508. if (where == null) return entities;
  32509. return entities.filter(this._createFilter(where));
  32510. }
  32511. /**
  32512. * Create where filter.
  32513. *
  32514. * @param {WhereClause} whereClause
  32515. * @returns {Function}
  32516. */
  32517. _createFilter(whereClause) {
  32518. if (typeof whereClause !== "object" || Array.isArray(whereClause))
  32519. throw new InvalidArgumentError2(
  32520. 'The provided option "where" should be an Object, but %v given.',
  32521. whereClause
  32522. );
  32523. const keys = Object.keys(whereClause);
  32524. return (data) => {
  32525. if (typeof data !== "object")
  32526. throw new InvalidArgumentError2(
  32527. "The first argument of WhereClauseTool.filter should be an Array of Object, but %v given.",
  32528. data
  32529. );
  32530. return keys.every((key) => {
  32531. if (key === "and" && key in whereClause) {
  32532. const andClause = whereClause[key];
  32533. if (Array.isArray(andClause))
  32534. return andClause.every((clause) => this._createFilter(clause)(data));
  32535. } else if (key === "or" && key in whereClause) {
  32536. const orClause = whereClause[key];
  32537. if (Array.isArray(orClause))
  32538. return orClause.some((clause) => this._createFilter(clause)(data));
  32539. }
  32540. const value = getValueByPath(data, key);
  32541. const matcher = whereClause[key];
  32542. if (Array.isArray(value)) {
  32543. if (typeof matcher === "object" && matcher !== null && "neq" in matcher && matcher.neq !== void 0) {
  32544. if (value.length === 0) return true;
  32545. return value.every((el, index) => {
  32546. const where = {};
  32547. where[index] = matcher;
  32548. return this._createFilter(where)({ ...value });
  32549. });
  32550. }
  32551. return value.some((el, index) => {
  32552. const where = {};
  32553. where[index] = matcher;
  32554. return this._createFilter(where)({ ...value });
  32555. });
  32556. }
  32557. if (this._test(matcher, value)) return true;
  32558. });
  32559. };
  32560. }
  32561. /**
  32562. * Value testing.
  32563. *
  32564. * @param {*} example
  32565. * @param {*} value
  32566. * @returns {boolean}
  32567. */
  32568. _test(example, value) {
  32569. if (example === null) {
  32570. return value === null;
  32571. }
  32572. if (example === void 0) {
  32573. return value === void 0;
  32574. }
  32575. if (example instanceof RegExp) {
  32576. if (typeof value === "string") return !!value.match(example);
  32577. return false;
  32578. }
  32579. if (typeof example === "object") {
  32580. const operatorsTest = this.getService(OperatorClauseTool).testAll(
  32581. example,
  32582. value
  32583. );
  32584. if (operatorsTest !== void 0) return operatorsTest;
  32585. }
  32586. return example == value;
  32587. }
  32588. /**
  32589. * Validate where clause.
  32590. *
  32591. * @param {WhereClause|undefined} clause
  32592. */
  32593. static validateWhereClause(clause) {
  32594. if (clause == null || typeof clause === "function") return;
  32595. if (typeof clause !== "object" || Array.isArray(clause))
  32596. throw new InvalidArgumentError2(
  32597. 'The provided option "where" should be an Object, but %v given.',
  32598. clause
  32599. );
  32600. }
  32601. };
  32602. }
  32603. });
  32604. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-type.js
  32605. var RelationType;
  32606. var init_relation_type = __esm({
  32607. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-type.js"() {
  32608. RelationType = {
  32609. BELONGS_TO: "belongsTo",
  32610. HAS_ONE: "hasOne",
  32611. HAS_MANY: "hasMany",
  32612. REFERENCES_MANY: "referencesMany"
  32613. };
  32614. }
  32615. });
  32616. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-definition.js
  32617. var init_relation_definition = __esm({
  32618. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relation-definition.js"() {
  32619. }
  32620. });
  32621. // node_modules/@e22m4u/js-repository/src/definition/model/relations/relations-definition-validator.js
  32622. var RelationsDefinitionValidator;
  32623. var init_relations_definition_validator = __esm({
  32624. "node_modules/@e22m4u/js-repository/src/definition/model/relations/relations-definition-validator.js"() {
  32625. init_src2();
  32626. init_relation_type();
  32627. init_relation_type();
  32628. init_errors2();
  32629. RelationsDefinitionValidator = class extends Service {
  32630. /**
  32631. * Validate.
  32632. *
  32633. * @param {string} modelName
  32634. * @param {object} relDefs
  32635. */
  32636. validate(modelName, relDefs) {
  32637. if (!modelName || typeof modelName !== "string")
  32638. throw new InvalidArgumentError2(
  32639. "The first argument of RelationsDefinitionValidator.validate should be a non-empty String, but %v given.",
  32640. modelName
  32641. );
  32642. if (!relDefs || typeof relDefs !== "object" || Array.isArray(relDefs))
  32643. throw new InvalidArgumentError2(
  32644. 'The provided option "relations" of the model %v should be an Object, but %v given.',
  32645. modelName,
  32646. relDefs
  32647. );
  32648. const relNames = Object.keys(relDefs);
  32649. relNames.forEach((relName) => {
  32650. const relDef = relDefs[relName];
  32651. this._validateRelation(modelName, relName, relDef);
  32652. });
  32653. }
  32654. /**
  32655. * Validate relation.
  32656. *
  32657. * @param {string} modelName
  32658. * @param {string} relName
  32659. * @param {object} relDef
  32660. */
  32661. _validateRelation(modelName, relName, relDef) {
  32662. if (!modelName || typeof modelName !== "string")
  32663. throw new InvalidArgumentError2(
  32664. "The first argument of RelationsDefinitionValidator._validateRelation should be a non-empty String, but %v given.",
  32665. modelName
  32666. );
  32667. if (!relName || typeof relName !== "string")
  32668. throw new InvalidArgumentError2(
  32669. "The relation name of the model %v should be a non-empty String, but %v given.",
  32670. modelName,
  32671. relName
  32672. );
  32673. if (!relDef || typeof relDef !== "object" || Array.isArray(relDef))
  32674. throw new InvalidArgumentError2(
  32675. "The relation %v of the model %v should be an Object, but %v given.",
  32676. relName,
  32677. modelName,
  32678. relDef
  32679. );
  32680. if (!relDef.type || !Object.values(RelationType).includes(relDef.type))
  32681. throw new InvalidArgumentError2(
  32682. 'The relation %v of the model %v requires the option "type" to have one of relation types: %l, but %v given.',
  32683. relName,
  32684. modelName,
  32685. Object.values(RelationType),
  32686. relDef.type
  32687. );
  32688. this._validateBelongsTo(modelName, relName, relDef);
  32689. this._validateHasOne(modelName, relName, relDef);
  32690. this._validateHasMany(modelName, relName, relDef);
  32691. this._validateReferencesMany(modelName, relName, relDef);
  32692. }
  32693. /**
  32694. * Validate "belongsTo".
  32695. *
  32696. * @example The regular "belongsTo" relation.
  32697. * ```
  32698. * {
  32699. * type: RelationType.BELONGS_TO,
  32700. * model: 'model',
  32701. * foreignKey: 'modelId', // optional
  32702. * }
  32703. * ```
  32704. *
  32705. * @example The polymorphic "belongsTo" relation.
  32706. * ```
  32707. * {
  32708. * type: RelationType.BELONGS_TO,
  32709. * polymorphic: true,
  32710. * foreignKey: 'referenceId', // optional
  32711. * discriminator: 'referenceType', // optional
  32712. * }
  32713. * ```
  32714. *
  32715. * @param {string} modelName
  32716. * @param {string} relName
  32717. * @param {object} relDef
  32718. * @private
  32719. */
  32720. _validateBelongsTo(modelName, relName, relDef) {
  32721. if (relDef.type !== RelationType.BELONGS_TO) return;
  32722. if (relDef.polymorphic) {
  32723. if (typeof relDef.polymorphic !== "boolean")
  32724. throw new InvalidArgumentError2(
  32725. 'The relation %v of the model %v has the type "belongsTo", so it expects the option "polymorphic" to be a Boolean, but %v given.',
  32726. relName,
  32727. modelName,
  32728. relDef.polymorphic
  32729. );
  32730. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32731. throw new InvalidArgumentError2(
  32732. '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.',
  32733. relName,
  32734. modelName,
  32735. relDef.foreignKey
  32736. );
  32737. if (relDef.discriminator && typeof relDef.discriminator !== "string")
  32738. throw new InvalidArgumentError2(
  32739. '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.',
  32740. relName,
  32741. modelName,
  32742. relDef.discriminator
  32743. );
  32744. } else {
  32745. if (!relDef.model || typeof relDef.model !== "string")
  32746. throw new InvalidArgumentError2(
  32747. '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.',
  32748. relName,
  32749. modelName,
  32750. relDef.model
  32751. );
  32752. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32753. throw new InvalidArgumentError2(
  32754. '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.',
  32755. relName,
  32756. modelName,
  32757. relDef.foreignKey
  32758. );
  32759. if (relDef.discriminator)
  32760. throw new InvalidArgumentError2(
  32761. 'The relation %v of the model %v is a non-polymorphic "belongsTo" relation, so it should not have the option "discriminator" to be provided.',
  32762. relName,
  32763. modelName
  32764. );
  32765. }
  32766. }
  32767. /**
  32768. * Validate "hasOne".
  32769. *
  32770. * @example The regular "hasOne" relation.
  32771. * ```
  32772. * {
  32773. * type: RelationType.HAS_ONE,
  32774. * model: 'model',
  32775. * foreignKey: 'modelId',
  32776. * }
  32777. * ```
  32778. *
  32779. * @example The polymorphic "hasOne" relation with a target relation name.
  32780. * ```
  32781. * {
  32782. * type: RelationType.HAS_ONE,
  32783. * model: 'model',
  32784. * polymorphic: 'reference',
  32785. * }
  32786. * ```
  32787. *
  32788. * @example The polymorphic "hasOne" relation with target relation keys.
  32789. * ```
  32790. * {
  32791. * type: RelationType.HAS_ONE,
  32792. * model: 'model',
  32793. * polymorphic: true,
  32794. * foreignKey: 'referenceId',
  32795. * discriminator: 'referenceType',
  32796. * }
  32797. * ```
  32798. *
  32799. * @param {string} modelName
  32800. * @param {string} relName
  32801. * @param {object} relDef
  32802. * @private
  32803. */
  32804. _validateHasOne(modelName, relName, relDef) {
  32805. if (relDef.type !== RelationType.HAS_ONE) return;
  32806. if (!relDef.model || typeof relDef.model !== "string")
  32807. throw new InvalidArgumentError2(
  32808. '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.',
  32809. relName,
  32810. modelName,
  32811. relDef.model
  32812. );
  32813. if (relDef.polymorphic) {
  32814. if (typeof relDef.polymorphic === "string") {
  32815. if (relDef.foreignKey)
  32816. throw new InvalidArgumentError2(
  32817. '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.',
  32818. relName,
  32819. modelName
  32820. );
  32821. if (relDef.discriminator)
  32822. throw new InvalidArgumentError2(
  32823. '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.',
  32824. relName,
  32825. modelName
  32826. );
  32827. } else if (typeof relDef.polymorphic === "boolean") {
  32828. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32829. throw new InvalidArgumentError2(
  32830. '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.',
  32831. relName,
  32832. modelName,
  32833. relDef.foreignKey
  32834. );
  32835. if (!relDef.discriminator || typeof relDef.discriminator !== "string")
  32836. throw new InvalidArgumentError2(
  32837. '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.',
  32838. relName,
  32839. modelName,
  32840. relDef.discriminator
  32841. );
  32842. } else {
  32843. throw new InvalidArgumentError2(
  32844. '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.',
  32845. relName,
  32846. modelName,
  32847. relDef.polymorphic
  32848. );
  32849. }
  32850. } else {
  32851. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32852. throw new InvalidArgumentError2(
  32853. '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.',
  32854. relName,
  32855. modelName,
  32856. relDef.foreignKey
  32857. );
  32858. if (relDef.discriminator)
  32859. throw new InvalidArgumentError2(
  32860. 'The relation %v of the model %v is a non-polymorphic "hasOne" relation, so it should not have the option "discriminator" to be provided.',
  32861. relName,
  32862. modelName
  32863. );
  32864. }
  32865. }
  32866. /**
  32867. * Validate "hasMany".
  32868. *
  32869. * @example The regular "hasMany" relation.
  32870. * ```
  32871. * {
  32872. * type: RelationType.HAS_MANY,
  32873. * model: 'model',
  32874. * foreignKey: 'modelId',
  32875. * }
  32876. * ```
  32877. *
  32878. * @example The polymorphic "hasMany" relation with a target relation name.
  32879. * ```
  32880. * {
  32881. * type: RelationType.HAS_MANY,
  32882. * model: 'model',
  32883. * polymorphic: 'reference',
  32884. * }
  32885. * ```
  32886. *
  32887. * @example The polymorphic "hasMany" relation with target relation keys.
  32888. * ```
  32889. * {
  32890. * type: RelationType.HAS_MANY,
  32891. * model: 'model',
  32892. * polymorphic: true,
  32893. * foreignKey: 'referenceId',
  32894. * discriminator: 'referenceType',
  32895. * }
  32896. * ```
  32897. *
  32898. * @param {string} modelName
  32899. * @param {string} relName
  32900. * @param {object} relDef
  32901. * @private
  32902. */
  32903. _validateHasMany(modelName, relName, relDef) {
  32904. if (relDef.type !== RelationType.HAS_MANY) return;
  32905. if (!relDef.model || typeof relDef.model !== "string")
  32906. throw new InvalidArgumentError2(
  32907. '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.',
  32908. relName,
  32909. modelName,
  32910. relDef.model
  32911. );
  32912. if (relDef.polymorphic) {
  32913. if (typeof relDef.polymorphic === "string") {
  32914. if (relDef.foreignKey)
  32915. throw new InvalidArgumentError2(
  32916. '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.',
  32917. relName,
  32918. modelName
  32919. );
  32920. if (relDef.discriminator)
  32921. throw new InvalidArgumentError2(
  32922. '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.',
  32923. relName,
  32924. modelName
  32925. );
  32926. } else if (typeof relDef.polymorphic === "boolean") {
  32927. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32928. throw new InvalidArgumentError2(
  32929. '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.',
  32930. relName,
  32931. modelName,
  32932. relDef.foreignKey
  32933. );
  32934. if (!relDef.discriminator || typeof relDef.discriminator !== "string")
  32935. throw new InvalidArgumentError2(
  32936. '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.',
  32937. relName,
  32938. modelName,
  32939. relDef.discriminator
  32940. );
  32941. } else {
  32942. throw new InvalidArgumentError2(
  32943. '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.',
  32944. relName,
  32945. modelName,
  32946. relDef.polymorphic
  32947. );
  32948. }
  32949. } else {
  32950. if (!relDef.foreignKey || typeof relDef.foreignKey !== "string")
  32951. throw new InvalidArgumentError2(
  32952. '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.',
  32953. relName,
  32954. modelName,
  32955. relDef.foreignKey
  32956. );
  32957. if (relDef.discriminator)
  32958. throw new InvalidArgumentError2(
  32959. 'The relation %v of the model %v is a non-polymorphic "hasMany" relation, so it should not have the option "discriminator" to be provided.',
  32960. relName,
  32961. modelName
  32962. );
  32963. }
  32964. }
  32965. /**
  32966. * Validate "referencesMany".
  32967. *
  32968. * @example
  32969. * ```
  32970. * {
  32971. * type: RelationType.REFERENCES_MANY,
  32972. * model: 'model',
  32973. * foreignKey: 'modelIds', // optional
  32974. * }
  32975. * ```
  32976. *
  32977. * @param {string} modelName
  32978. * @param {string} relName
  32979. * @param {object} relDef
  32980. * @private
  32981. */
  32982. _validateReferencesMany(modelName, relName, relDef) {
  32983. if (relDef.type !== RelationType.REFERENCES_MANY) return;
  32984. if (!relDef.model || typeof relDef.model !== "string")
  32985. throw new InvalidArgumentError2(
  32986. '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.',
  32987. relName,
  32988. modelName,
  32989. relDef.model
  32990. );
  32991. if (relDef.foreignKey && typeof relDef.foreignKey !== "string")
  32992. throw new InvalidArgumentError2(
  32993. '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.',
  32994. relName,
  32995. modelName,
  32996. relDef.foreignKey
  32997. );
  32998. if (relDef.discriminator)
  32999. throw new InvalidArgumentError2(
  33000. 'The relation %v of the model %v has the type "referencesMany", so it should not have the option "discriminator" to be provided.',
  33001. relName,
  33002. modelName
  33003. );
  33004. }
  33005. };
  33006. }
  33007. });
  33008. // node_modules/@e22m4u/js-repository/src/definition/model/relations/index.js
  33009. var init_relations = __esm({
  33010. "node_modules/@e22m4u/js-repository/src/definition/model/relations/index.js"() {
  33011. init_relation_type();
  33012. init_relation_definition();
  33013. init_relations_definition_validator();
  33014. }
  33015. });
  33016. // node_modules/@e22m4u/js-repository/src/definition/model/properties/data-type.js
  33017. var DataType;
  33018. var init_data_type = __esm({
  33019. "node_modules/@e22m4u/js-repository/src/definition/model/properties/data-type.js"() {
  33020. DataType = {
  33021. ANY: "any",
  33022. STRING: "string",
  33023. NUMBER: "number",
  33024. BOOLEAN: "boolean",
  33025. ARRAY: "array",
  33026. OBJECT: "object"
  33027. };
  33028. }
  33029. });
  33030. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-definition.js
  33031. var init_property_definition = __esm({
  33032. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-definition.js"() {
  33033. }
  33034. });
  33035. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness.js
  33036. var PropertyUniqueness;
  33037. var init_property_uniqueness = __esm({
  33038. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness.js"() {
  33039. PropertyUniqueness = {
  33040. STRICT: "strict",
  33041. SPARSE: "sparse",
  33042. NON_UNIQUE: "nonUnique"
  33043. };
  33044. }
  33045. });
  33046. // node_modules/@e22m4u/js-repository/src/definition/model/properties/empty-values-definer.js
  33047. var EmptyValuesDefiner;
  33048. var init_empty_values_definer = __esm({
  33049. "node_modules/@e22m4u/js-repository/src/definition/model/properties/empty-values-definer.js"() {
  33050. init_data_type();
  33051. init_src2();
  33052. init_utils2();
  33053. init_errors2();
  33054. EmptyValuesDefiner = class extends Service {
  33055. /**
  33056. * Empty values map.
  33057. *
  33058. * @type {Map<string, *[]>}
  33059. */
  33060. _emptyValuesMap = /* @__PURE__ */ new Map([
  33061. [DataType.ANY, [void 0, null]],
  33062. [DataType.STRING, [void 0, null, ""]],
  33063. [DataType.NUMBER, [void 0, null, 0]],
  33064. [DataType.BOOLEAN, [void 0, null]],
  33065. [DataType.ARRAY, [void 0, null, []]],
  33066. [DataType.OBJECT, [void 0, null, {}]]
  33067. ]);
  33068. /**
  33069. * Set empty values of data type.
  33070. *
  33071. * @param {string} dataType
  33072. * @param {*[]} emptyValues
  33073. * @returns {EmptyValuesDefiner}
  33074. */
  33075. setEmptyValuesOf(dataType, emptyValues) {
  33076. if (!Object.values(DataType).includes(dataType))
  33077. throw new InvalidArgumentError2(
  33078. 'The argument "dataType" of the EmptyValuesDefiner.setEmptyValuesOf must be one of data types: %l, but %v given.',
  33079. Object.values(DataType),
  33080. dataType
  33081. );
  33082. if (!Array.isArray(emptyValues))
  33083. throw new InvalidArgumentError2(
  33084. 'The argument "emptyValues" of the EmptyValuesDefiner.setEmptyValuesOf must be an Array, but %v given.',
  33085. emptyValues
  33086. );
  33087. this._emptyValuesMap.set(dataType, emptyValues);
  33088. return this;
  33089. }
  33090. /**
  33091. * Is empty.
  33092. *
  33093. * @param {string} dataType
  33094. * @param {*} value
  33095. * @returns {boolean}
  33096. */
  33097. isEmpty(dataType, value) {
  33098. if (!Object.values(DataType).includes(dataType))
  33099. throw new InvalidArgumentError2(
  33100. 'The argument "dataType" of the EmptyValuesDefiner.isEmpty must be one of data types: %l, but %v given.',
  33101. Object.values(DataType),
  33102. dataType
  33103. );
  33104. return this._emptyValuesMap.get(dataType).some((v) => isDeepEqual(v, value));
  33105. }
  33106. };
  33107. }
  33108. });
  33109. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator.js
  33110. var init_property_validator = __esm({
  33111. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator.js"() {
  33112. }
  33113. });
  33114. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/regexp-validator.js
  33115. function regexpValidator(value, options, context) {
  33116. if (value == null || options === false) return true;
  33117. if (typeof options !== "string" && !(options instanceof RegExp))
  33118. throw new InvalidArgumentError2(
  33119. 'The validator %v requires the "options" argument as a String or RegExp, but %v given.',
  33120. context.validatorName,
  33121. options
  33122. );
  33123. if (typeof value === "string") {
  33124. const regexp = stringToRegexp(options);
  33125. return regexp.test(value);
  33126. }
  33127. throw new InvalidArgumentError2(
  33128. "The property validator %v requires a String value, but %v given.",
  33129. context.validatorName,
  33130. value
  33131. );
  33132. }
  33133. var init_regexp_validator = __esm({
  33134. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/regexp-validator.js"() {
  33135. init_utils2();
  33136. init_errors2();
  33137. }
  33138. });
  33139. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/max-length-validator.js
  33140. function maxLengthValidator(value, options, context) {
  33141. if (value == null || options === false) return true;
  33142. if (typeof options !== "number")
  33143. throw new InvalidArgumentError2(
  33144. 'The validator %v requires the "options" argument as a Number, but %v given.',
  33145. context.validatorName,
  33146. options
  33147. );
  33148. if (typeof value === "string" || Array.isArray(value))
  33149. return value.length <= options;
  33150. throw new InvalidArgumentError2(
  33151. "The property validator %v requires a String or an Array value, but %v given.",
  33152. context.validatorName,
  33153. value
  33154. );
  33155. }
  33156. var init_max_length_validator = __esm({
  33157. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/max-length-validator.js"() {
  33158. init_errors2();
  33159. }
  33160. });
  33161. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/min-length-validator.js
  33162. function minLengthValidator(value, options, context) {
  33163. if (value == null || options === false) return true;
  33164. if (typeof options !== "number")
  33165. throw new InvalidArgumentError2(
  33166. 'The validator %v requires the "options" argument as a Number, but %v given.',
  33167. context.validatorName,
  33168. options
  33169. );
  33170. if (typeof value === "string" || Array.isArray(value))
  33171. return value.length >= options;
  33172. throw new InvalidArgumentError2(
  33173. "The property validator %v requires a String or an Array value, but %v given.",
  33174. context.validatorName,
  33175. value
  33176. );
  33177. }
  33178. var init_min_length_validator = __esm({
  33179. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/min-length-validator.js"() {
  33180. init_errors2();
  33181. }
  33182. });
  33183. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/index.js
  33184. var init_builtin = __esm({
  33185. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/builtin/index.js"() {
  33186. init_regexp_validator();
  33187. init_max_length_validator();
  33188. init_min_length_validator();
  33189. }
  33190. });
  33191. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator-registry.js
  33192. var PropertyValidatorRegistry;
  33193. var init_property_validator_registry = __esm({
  33194. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/property-validator-registry.js"() {
  33195. init_src2();
  33196. init_builtin();
  33197. init_builtin();
  33198. init_builtin();
  33199. init_errors2();
  33200. PropertyValidatorRegistry = class extends Service {
  33201. /**
  33202. * Validators.
  33203. *
  33204. * @type {object}
  33205. */
  33206. _validators = {
  33207. maxLength: maxLengthValidator,
  33208. minLength: minLengthValidator,
  33209. regexp: regexpValidator
  33210. };
  33211. /**
  33212. * Add validator.
  33213. *
  33214. * @param {string} name
  33215. * @param {Function} validator
  33216. * @returns {PropertyValidatorRegistry}
  33217. */
  33218. addValidator(name, validator) {
  33219. if (!name || typeof name !== "string")
  33220. throw new InvalidArgumentError2(
  33221. "A name of the property validator must be a non-empty String, but %v given.",
  33222. name
  33223. );
  33224. if (name in this._validators)
  33225. throw new InvalidArgumentError2(
  33226. "The property validator %v is already defined.",
  33227. name
  33228. );
  33229. if (typeof validator !== "function")
  33230. throw new InvalidArgumentError2(
  33231. "The property validator %v must be a Function, but %v given.",
  33232. name,
  33233. validator
  33234. );
  33235. this._validators[name] = validator;
  33236. return this;
  33237. }
  33238. /**
  33239. * Has validator.
  33240. *
  33241. * @param {string} name
  33242. * @returns {boolean}
  33243. */
  33244. hasValidator(name) {
  33245. return Boolean(this._validators[name]);
  33246. }
  33247. /**
  33248. * Get validator.
  33249. *
  33250. * @param {string} name
  33251. * @returns {Function}
  33252. */
  33253. getValidator(name) {
  33254. const validator = this._validators[name];
  33255. if (!validator)
  33256. throw new InvalidArgumentError2(
  33257. "The property validator %v is not defined.",
  33258. name
  33259. );
  33260. return validator;
  33261. }
  33262. };
  33263. }
  33264. });
  33265. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/index.js
  33266. var init_property_validator2 = __esm({
  33267. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-validator/index.js"() {
  33268. init_property_validator();
  33269. init_property_validator_registry();
  33270. }
  33271. });
  33272. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer.js
  33273. var init_property_transformer = __esm({
  33274. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer.js"() {
  33275. }
  33276. });
  33277. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/trim-transformer.js
  33278. function trimTransformer(value, options, context) {
  33279. if (value == null) return value;
  33280. if (typeof value === "string") return value.trim();
  33281. throw new InvalidArgumentError2(
  33282. "The property transformer %v requires a String value, but %v given.",
  33283. context.transformerName,
  33284. value
  33285. );
  33286. }
  33287. var init_trim_transformer = __esm({
  33288. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/trim-transformer.js"() {
  33289. init_errors2();
  33290. }
  33291. });
  33292. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js
  33293. function toLowerCaseTransformer(value, options, context) {
  33294. if (value == null) return value;
  33295. if (typeof value === "string") return value.toLowerCase();
  33296. throw new InvalidArgumentError2(
  33297. "The property transformer %v requires a String value, but %v given.",
  33298. context.transformerName,
  33299. value
  33300. );
  33301. }
  33302. var init_to_lower_case_transformer = __esm({
  33303. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-lower-case-transformer.js"() {
  33304. init_errors2();
  33305. }
  33306. });
  33307. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js
  33308. function toUpperCaseTransformer(value, options, context) {
  33309. if (value == null) return value;
  33310. if (typeof value === "string") return value.toUpperCase();
  33311. throw new InvalidArgumentError2(
  33312. "The property transformer %v requires a String value, but %v given.",
  33313. context.transformerName,
  33314. value
  33315. );
  33316. }
  33317. var init_to_upper_case_transformer = __esm({
  33318. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-upper-case-transformer.js"() {
  33319. init_errors2();
  33320. }
  33321. });
  33322. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.js
  33323. function toTitleCaseTransformer(value, options, context) {
  33324. if (value == null) return value;
  33325. if (typeof value === "string")
  33326. return value.replace(new RegExp("\\p{L}\\S*", "gu"), (text) => {
  33327. return text.charAt(0).toUpperCase() + text.substring(1).toLowerCase();
  33328. });
  33329. throw new InvalidArgumentError2(
  33330. "The property transformer %v requires a String value, but %v given.",
  33331. context.transformerName,
  33332. value
  33333. );
  33334. }
  33335. var init_to_title_case_transformer = __esm({
  33336. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/to-title-case-transformer.js"() {
  33337. init_errors2();
  33338. }
  33339. });
  33340. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/index.js
  33341. var init_builtin2 = __esm({
  33342. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/builtin/index.js"() {
  33343. init_trim_transformer();
  33344. init_to_lower_case_transformer();
  33345. init_to_upper_case_transformer();
  33346. init_to_title_case_transformer();
  33347. }
  33348. });
  33349. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer-registry.js
  33350. var PropertyTransformerRegistry;
  33351. var init_property_transformer_registry = __esm({
  33352. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/property-transformer-registry.js"() {
  33353. init_src2();
  33354. init_builtin2();
  33355. init_builtin2();
  33356. init_builtin2();
  33357. init_builtin2();
  33358. init_errors2();
  33359. PropertyTransformerRegistry = class extends Service {
  33360. /**
  33361. * Transformers.
  33362. *
  33363. * @type {object}
  33364. */
  33365. _transformers = {
  33366. trim: trimTransformer,
  33367. toUpperCase: toUpperCaseTransformer,
  33368. toLowerCase: toLowerCaseTransformer,
  33369. toTitleCase: toTitleCaseTransformer
  33370. };
  33371. /**
  33372. * Add transformer.
  33373. *
  33374. * @param {string} name
  33375. * @param {Function} transformer
  33376. * @returns {PropertyTransformerRegistry}
  33377. */
  33378. addTransformer(name, transformer) {
  33379. if (!name || typeof name !== "string")
  33380. throw new InvalidArgumentError2(
  33381. "A name of the property transformer must be a non-empty String, but %v given.",
  33382. name
  33383. );
  33384. if (name in this._transformers)
  33385. throw new InvalidArgumentError2(
  33386. "The property transformer %v is already defined.",
  33387. name
  33388. );
  33389. if (typeof transformer !== "function")
  33390. throw new InvalidArgumentError2(
  33391. "The property transformer %v must be a Function, but %v given.",
  33392. name,
  33393. transformer
  33394. );
  33395. this._transformers[name] = transformer;
  33396. return this;
  33397. }
  33398. /**
  33399. * Has transformer.
  33400. *
  33401. * @param {string} name
  33402. * @returns {boolean}
  33403. */
  33404. hasTransformer(name) {
  33405. return Boolean(this._transformers[name]);
  33406. }
  33407. /**
  33408. * Get transformer.
  33409. *
  33410. * @param {string} name
  33411. * @returns {Function}
  33412. */
  33413. getTransformer(name) {
  33414. const transformer = this._transformers[name];
  33415. if (!transformer)
  33416. throw new InvalidArgumentError2(
  33417. "The property transformer %v is not defined.",
  33418. name
  33419. );
  33420. return transformer;
  33421. }
  33422. };
  33423. }
  33424. });
  33425. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/index.js
  33426. var init_property_transformer2 = __esm({
  33427. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-transformer/index.js"() {
  33428. init_property_transformer();
  33429. init_property_transformer_registry();
  33430. }
  33431. });
  33432. // node_modules/@e22m4u/js-repository/src/definition/definition-registry.js
  33433. var DefinitionRegistry;
  33434. var init_definition_registry = __esm({
  33435. "node_modules/@e22m4u/js-repository/src/definition/definition-registry.js"() {
  33436. init_src2();
  33437. init_errors2();
  33438. init_model();
  33439. init_definition();
  33440. DefinitionRegistry = class extends Service {
  33441. /**
  33442. * Datasources.
  33443. *
  33444. * @type {object}
  33445. */
  33446. _datasources = {};
  33447. /**
  33448. * Models.
  33449. *
  33450. * @type {object}
  33451. */
  33452. _models = {};
  33453. /**
  33454. * Add datasource.
  33455. *
  33456. * @param {object} datasourceDef
  33457. */
  33458. addDatasource(datasourceDef) {
  33459. this.getService(DatasourceDefinitionValidator).validate(datasourceDef);
  33460. const name = datasourceDef.name;
  33461. if (name in this._datasources)
  33462. throw new InvalidArgumentError2(
  33463. "The datasource %v is already defined.",
  33464. name
  33465. );
  33466. this._datasources[name] = datasourceDef;
  33467. }
  33468. /**
  33469. * Has datasource.
  33470. *
  33471. * @param {string} name
  33472. * @returns {boolean}
  33473. */
  33474. hasDatasource(name) {
  33475. return Boolean(this._datasources[name]);
  33476. }
  33477. /**
  33478. * Get datasource.
  33479. *
  33480. * @param {string} name
  33481. * @returns {object}
  33482. */
  33483. getDatasource(name) {
  33484. const datasourceDef = this._datasources[name];
  33485. if (!datasourceDef)
  33486. throw new InvalidArgumentError2("The datasource %v is not defined.", name);
  33487. return datasourceDef;
  33488. }
  33489. /**
  33490. * Add model.
  33491. *
  33492. * @param {object} modelDef
  33493. */
  33494. addModel(modelDef) {
  33495. this.getService(ModelDefinitionValidator).validate(modelDef);
  33496. const name = modelDef.name;
  33497. if (name in this._models)
  33498. throw new InvalidArgumentError2("The model %v is already defined.", name);
  33499. this._models[name] = modelDef;
  33500. }
  33501. /**
  33502. * Has model.
  33503. *
  33504. * @param {string} name
  33505. * @returns {boolean}
  33506. */
  33507. hasModel(name) {
  33508. return Boolean(this._models[name]);
  33509. }
  33510. /**
  33511. * Get model.
  33512. *
  33513. * @param {string} name
  33514. * @returns {object}
  33515. */
  33516. getModel(name) {
  33517. const modelDef = this._models[name];
  33518. if (!modelDef)
  33519. throw new InvalidArgumentError2("The model %v is not defined.", name);
  33520. return modelDef;
  33521. }
  33522. };
  33523. }
  33524. });
  33525. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition-utils.js
  33526. var DEFAULT_PRIMARY_KEY_PROPERTY_NAME, ModelDefinitionUtils;
  33527. var init_model_definition_utils = __esm({
  33528. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition-utils.js"() {
  33529. init_src2();
  33530. init_properties();
  33531. init_utils2();
  33532. init_utils2();
  33533. init_properties();
  33534. init_errors2();
  33535. init_definition_registry();
  33536. DEFAULT_PRIMARY_KEY_PROPERTY_NAME = "id";
  33537. ModelDefinitionUtils = class extends Service {
  33538. /**
  33539. * Get primary key as property name.
  33540. *
  33541. * @param {string} modelName
  33542. * @returns {string}
  33543. */
  33544. getPrimaryKeyAsPropertyName(modelName) {
  33545. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33546. const propNames = Object.keys(propDefs).filter((propName) => {
  33547. const propDef = propDefs[propName];
  33548. return propDef && typeof propDef === "object" && propDef.primaryKey;
  33549. });
  33550. if (propNames.length < 1) {
  33551. const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(
  33552. DEFAULT_PRIMARY_KEY_PROPERTY_NAME
  33553. );
  33554. if (isDefaultPrimaryKeyAlreadyInUse)
  33555. throw new InvalidArgumentError2(
  33556. '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.',
  33557. DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
  33558. modelName
  33559. );
  33560. return DEFAULT_PRIMARY_KEY_PROPERTY_NAME;
  33561. }
  33562. return propNames[0];
  33563. }
  33564. /**
  33565. * Get primary key as column name.
  33566. *
  33567. * @param {string} modelName
  33568. * @returns {string}
  33569. */
  33570. getPrimaryKeyAsColumnName(modelName) {
  33571. const pkPropName = this.getPrimaryKeyAsPropertyName(modelName);
  33572. let pkColName;
  33573. try {
  33574. pkColName = this.getColumnNameByPropertyName(modelName, pkPropName);
  33575. } catch (error) {
  33576. if (!(error instanceof InvalidArgumentError2)) throw error;
  33577. }
  33578. if (pkColName === void 0) return pkPropName;
  33579. return pkColName;
  33580. }
  33581. /**
  33582. * Get table name by model name.
  33583. *
  33584. * @param {string} modelName
  33585. * @returns {string}
  33586. */
  33587. getTableNameByModelName(modelName) {
  33588. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33589. return modelDef.tableName ?? modelName;
  33590. }
  33591. /**
  33592. * Get column name by property name.
  33593. *
  33594. * @param {string} modelName
  33595. * @param {string} propertyName
  33596. * @returns {string}
  33597. */
  33598. getColumnNameByPropertyName(modelName, propertyName) {
  33599. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33600. const propDef = propDefs[propertyName];
  33601. if (!propDef)
  33602. throw new InvalidArgumentError2(
  33603. "The model %v does not have the property %v.",
  33604. modelName,
  33605. propertyName
  33606. );
  33607. if (propDef && typeof propDef === "object")
  33608. return propDef.columnName ?? propertyName;
  33609. return propertyName;
  33610. }
  33611. /**
  33612. * Get default property value.
  33613. *
  33614. * @param {string} modelName
  33615. * @param {string} propertyName
  33616. * @returns {*}
  33617. */
  33618. getDefaultPropertyValue(modelName, propertyName) {
  33619. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33620. const propDef = propDefs[propertyName];
  33621. if (!propDef)
  33622. throw new InvalidArgumentError2(
  33623. "The model %v does not have the property %v.",
  33624. modelName,
  33625. propertyName
  33626. );
  33627. if (propDef && typeof propDef === "object")
  33628. return propDef.default instanceof Function ? propDef.default() : propDef.default;
  33629. }
  33630. /**
  33631. * Set default values for empty properties.
  33632. *
  33633. * @param {string} modelName
  33634. * @param {object} modelData
  33635. * @param {boolean|undefined} onlyProvidedProperties
  33636. * @returns {object}
  33637. */
  33638. setDefaultValuesToEmptyProperties(modelName, modelData, onlyProvidedProperties = false) {
  33639. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33640. const propNames = onlyProvidedProperties ? Object.keys(modelData) : Object.keys(propDefs);
  33641. const extendedData = cloneDeep(modelData);
  33642. const emptyValueDefiner = this.getService(EmptyValuesDefiner);
  33643. propNames.forEach((propName) => {
  33644. const propDef = propDefs[propName];
  33645. const propValue = extendedData[propName];
  33646. const propType = propDef != null ? this.getDataTypeFromPropertyDefinition(propDef) : DataType.ANY;
  33647. const isEmpty = emptyValueDefiner.isEmpty(propType, propValue);
  33648. if (!isEmpty) return;
  33649. if (propDef && typeof propDef === "object" && propDef.default !== void 0) {
  33650. extendedData[propName] = this.getDefaultPropertyValue(
  33651. modelName,
  33652. propName
  33653. );
  33654. }
  33655. });
  33656. return extendedData;
  33657. }
  33658. /**
  33659. * Convert property names to column names.
  33660. *
  33661. * @param {string} modelName
  33662. * @param {object} modelData
  33663. * @returns {object}
  33664. */
  33665. convertPropertyNamesToColumnNames(modelName, modelData) {
  33666. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33667. const propNames = Object.keys(propDefs);
  33668. const convertedData = cloneDeep(modelData);
  33669. propNames.forEach((propName) => {
  33670. if (!(propName in convertedData)) return;
  33671. const colName = this.getColumnNameByPropertyName(modelName, propName);
  33672. if (propName === colName) return;
  33673. const propValue = convertedData[propName];
  33674. delete convertedData[propName];
  33675. convertedData[colName] = propValue;
  33676. });
  33677. return convertedData;
  33678. }
  33679. /**
  33680. * Convert column names to property names.
  33681. *
  33682. * @param {string} modelName
  33683. * @param {object} tableData
  33684. * @returns {object}
  33685. */
  33686. convertColumnNamesToPropertyNames(modelName, tableData) {
  33687. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33688. const propNames = Object.keys(propDefs);
  33689. const convertedData = cloneDeep(tableData);
  33690. propNames.forEach((propName) => {
  33691. const colName = this.getColumnNameByPropertyName(modelName, propName);
  33692. if (!(colName in convertedData) || colName === propName) return;
  33693. const colValue = convertedData[colName];
  33694. delete convertedData[colName];
  33695. convertedData[propName] = colValue;
  33696. });
  33697. return convertedData;
  33698. }
  33699. /**
  33700. * Get data type by property name.
  33701. *
  33702. * @param {string} modelName
  33703. * @param {string} propertyName
  33704. * @returns {string}
  33705. */
  33706. getDataTypeByPropertyName(modelName, propertyName) {
  33707. const propDefs = this.getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33708. const propDef = propDefs[propertyName];
  33709. if (!propDef) {
  33710. const pkPropName = this.getPrimaryKeyAsPropertyName(modelName);
  33711. if (pkPropName === propertyName) return DataType.ANY;
  33712. throw new InvalidArgumentError2(
  33713. "The model %v does not have the property %v.",
  33714. modelName,
  33715. propertyName
  33716. );
  33717. }
  33718. if (typeof propDef === "string") return propDef;
  33719. return propDef.type;
  33720. }
  33721. /**
  33722. * Get data type from property definition.
  33723. *
  33724. * @param {object} propDef
  33725. * @returns {string}
  33726. */
  33727. getDataTypeFromPropertyDefinition(propDef) {
  33728. if ((!propDef || typeof propDef !== "object") && !Object.values(DataType).includes(propDef)) {
  33729. throw new InvalidArgumentError2(
  33730. 'The argument "propDef" of the ModelDefinitionUtils.getDataTypeFromPropertyDefinition should be an Object or the DataType enum, but %v given.',
  33731. propDef
  33732. );
  33733. }
  33734. if (typeof propDef === "string") return propDef;
  33735. const dataType = propDef.type;
  33736. if (!Object.values(DataType).includes(dataType))
  33737. throw new InvalidArgumentError2(
  33738. 'The given Object to the ModelDefinitionUtils.getDataTypeFromPropertyDefinition should have the "type" property with one of values: %l, but %v given.',
  33739. Object.values(DataType),
  33740. propDef.type
  33741. );
  33742. return dataType;
  33743. }
  33744. /**
  33745. * Get own properties definition of primary keys.
  33746. *
  33747. * @param {string} modelName
  33748. * @returns {object}
  33749. */
  33750. getOwnPropertiesDefinitionOfPrimaryKeys(modelName) {
  33751. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33752. const propDefs = modelDef.properties ?? {};
  33753. const pkPropNames = Object.keys(propDefs).filter((propName) => {
  33754. const propDef = propDefs[propName];
  33755. return typeof propDef === "object" && propDef.primaryKey;
  33756. });
  33757. return pkPropNames.reduce((a, k) => ({ ...a, [k]: propDefs[k] }), {});
  33758. }
  33759. /**
  33760. * Get own properties definition without primary keys.
  33761. *
  33762. * @param {string} modelName
  33763. * @returns {object}
  33764. */
  33765. getOwnPropertiesDefinitionWithoutPrimaryKeys(modelName) {
  33766. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33767. const propDefs = modelDef.properties ?? {};
  33768. return Object.keys(propDefs).reduce((result, propName) => {
  33769. const propDef = propDefs[propName];
  33770. if (typeof propDef === "object" && propDef.primaryKey) return result;
  33771. return { ...result, [propName]: propDef };
  33772. }, {});
  33773. }
  33774. /**
  33775. * Get properties definition in base model hierarchy.
  33776. *
  33777. * @param {string} modelName
  33778. * @returns {object}
  33779. */
  33780. getPropertiesDefinitionInBaseModelHierarchy(modelName) {
  33781. let result = {};
  33782. let pkPropDefs = {};
  33783. const recursion = (currModelName, prevModelName = void 0) => {
  33784. if (currModelName === prevModelName)
  33785. throw new InvalidArgumentError2(
  33786. "The model %v has a circular inheritance.",
  33787. currModelName
  33788. );
  33789. if (Object.keys(pkPropDefs).length === 0) {
  33790. pkPropDefs = this.getOwnPropertiesDefinitionOfPrimaryKeys(currModelName);
  33791. result = { ...result, ...pkPropDefs };
  33792. }
  33793. const regularPropDefs = this.getOwnPropertiesDefinitionWithoutPrimaryKeys(currModelName);
  33794. result = { ...regularPropDefs, ...result };
  33795. const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
  33796. if (modelDef.base) recursion(modelDef.base, currModelName);
  33797. };
  33798. recursion(modelName);
  33799. return result;
  33800. }
  33801. /**
  33802. * Get own relations definition.
  33803. *
  33804. * @param {string} modelName
  33805. * @returns {object}
  33806. */
  33807. getOwnRelationsDefinition(modelName) {
  33808. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  33809. return modelDef.relations ?? {};
  33810. }
  33811. /**
  33812. * Get relations definition in base model hierarchy.
  33813. *
  33814. * @param {string} modelName
  33815. * @returns {object}
  33816. */
  33817. getRelationsDefinitionInBaseModelHierarchy(modelName) {
  33818. let result = {};
  33819. const recursion = (currModelName, prevModelName = void 0) => {
  33820. if (currModelName === prevModelName)
  33821. throw new InvalidArgumentError2(
  33822. "The model %v has a circular inheritance.",
  33823. currModelName
  33824. );
  33825. const modelDef = this.getService(DefinitionRegistry).getModel(currModelName);
  33826. const ownRelDefs = modelDef.relations ?? {};
  33827. result = { ...ownRelDefs, ...result };
  33828. if (modelDef.base) recursion(modelDef.base, currModelName);
  33829. };
  33830. recursion(modelName);
  33831. return result;
  33832. }
  33833. /**
  33834. * Get relation definition by name.
  33835. *
  33836. * @param {string} modelName
  33837. * @param {string} relationName
  33838. * @returns {object}
  33839. */
  33840. getRelationDefinitionByName(modelName, relationName) {
  33841. const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
  33842. const relNames = Object.keys(relDefs);
  33843. let foundDef;
  33844. for (const relName of relNames) {
  33845. if (relName === relationName) {
  33846. foundDef = relDefs[relName];
  33847. break;
  33848. }
  33849. }
  33850. if (!foundDef)
  33851. throw new InvalidArgumentError2(
  33852. "The model %v does not have relation name %v.",
  33853. modelName,
  33854. relationName
  33855. );
  33856. return foundDef;
  33857. }
  33858. /**
  33859. * Exclude object keys by relation names.
  33860. *
  33861. * @param {string} modelName
  33862. * @param {object} modelData
  33863. * @returns {object}
  33864. */
  33865. excludeObjectKeysByRelationNames(modelName, modelData) {
  33866. if (!modelData || typeof modelData !== "object" || Array.isArray(modelData))
  33867. throw new InvalidArgumentError2(
  33868. "The second argument of ModelDefinitionUtils.excludeObjectKeysByRelationNames should be an Object, but %v given.",
  33869. modelData
  33870. );
  33871. const relDefs = this.getRelationsDefinitionInBaseModelHierarchy(modelName);
  33872. const relNames = Object.keys(relDefs);
  33873. return excludeObjectKeys(modelData, relNames);
  33874. }
  33875. };
  33876. }
  33877. });
  33878. // node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness-validator.js
  33879. var PropertyUniquenessValidator;
  33880. var init_property_uniqueness_validator = __esm({
  33881. "node_modules/@e22m4u/js-repository/src/definition/model/properties/property-uniqueness-validator.js"() {
  33882. init_data_type();
  33883. init_src2();
  33884. init_utils2();
  33885. init_property_uniqueness();
  33886. init_empty_values_definer();
  33887. init_errors2();
  33888. init_model_definition_utils();
  33889. PropertyUniquenessValidator = class extends Service {
  33890. /**
  33891. * Validate.
  33892. *
  33893. * @param {Function} countMethod
  33894. * @param {string} methodName
  33895. * @param {string} modelName
  33896. * @param {object} modelData
  33897. * @param {*} modelId
  33898. * @returns {Promise<undefined>}
  33899. */
  33900. async validate(countMethod, methodName, modelName, modelData, modelId = void 0) {
  33901. if (typeof countMethod !== "function")
  33902. throw new InvalidArgumentError2(
  33903. 'The parameter "countMethod" of the PropertyUniquenessValidator must be a Function, but %v given.',
  33904. countMethod
  33905. );
  33906. if (!methodName || typeof methodName !== "string")
  33907. throw new InvalidArgumentError2(
  33908. 'The parameter "methodName" of the PropertyUniquenessValidator must be a non-empty String, but %v given.',
  33909. methodName
  33910. );
  33911. if (!modelName || typeof modelName !== "string")
  33912. throw new InvalidArgumentError2(
  33913. 'The parameter "modelName" of the PropertyUniquenessValidator must be a non-empty String, but %v given.',
  33914. modelName
  33915. );
  33916. if (!isPureObject(modelData))
  33917. throw new InvalidArgumentError2(
  33918. "The data of the model %v should be an Object, but %v given.",
  33919. modelName,
  33920. modelData
  33921. );
  33922. const propDefs = this.getService(
  33923. ModelDefinitionUtils
  33924. ).getPropertiesDefinitionInBaseModelHierarchy(modelName);
  33925. const isPartial = methodName === "patch" || methodName === "patchById";
  33926. const propNames = Object.keys(isPartial ? modelData : propDefs);
  33927. const idProp = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  33928. modelName
  33929. );
  33930. const createError = (propName, propValue) => new InvalidArgumentError2(
  33931. "An existing document of the model %v already has the property %v with the value %v and should be unique.",
  33932. modelName,
  33933. propName,
  33934. propValue
  33935. );
  33936. let willBeReplaced = void 0;
  33937. const emptyValuesDefiner = this.getService(EmptyValuesDefiner);
  33938. for (const propName of propNames) {
  33939. const propDef = propDefs[propName];
  33940. if (!propDef || typeof propDef === "string" || !propDef.unique || propDef.unique === PropertyUniqueness.NON_UNIQUE) {
  33941. continue;
  33942. }
  33943. const propValue = modelData[propName];
  33944. if (propDef.unique === PropertyUniqueness.SPARSE) {
  33945. const propType = propDef.type || DataType.ANY;
  33946. const isEmpty = emptyValuesDefiner.isEmpty(propType, propValue);
  33947. if (isEmpty) continue;
  33948. }
  33949. if (methodName === "create") {
  33950. const count = await countMethod({ [propName]: propValue });
  33951. if (count > 0) throw createError(propName, propValue);
  33952. } else if (methodName === "replaceById") {
  33953. const count = await countMethod({
  33954. [idProp]: { neq: modelId },
  33955. [propName]: propValue
  33956. });
  33957. if (count > 0) throw createError(propName, propValue);
  33958. } else if (methodName === "replaceOrCreate") {
  33959. const idFromData = modelData[idProp];
  33960. if (willBeReplaced == null && idFromData != null) {
  33961. const count = await countMethod({ [idProp]: idFromData });
  33962. willBeReplaced = count > 0;
  33963. }
  33964. if (willBeReplaced) {
  33965. const count = await countMethod({
  33966. [idProp]: { neq: idFromData },
  33967. [propName]: propValue
  33968. });
  33969. if (count > 0) throw createError(propName, propValue);
  33970. } else {
  33971. const count = await countMethod({ [propName]: propValue });
  33972. if (count > 0) throw createError(propName, propValue);
  33973. }
  33974. } else if (methodName === "patch") {
  33975. const count = await countMethod({ [propName]: propValue });
  33976. if (count > 0) throw createError(propName, propValue);
  33977. } else if (methodName === "patchById") {
  33978. const count = await countMethod({
  33979. [idProp]: { neq: modelId },
  33980. [propName]: propValue
  33981. });
  33982. if (count > 0) throw createError(propName, propValue);
  33983. } else {
  33984. throw new InvalidArgumentError2(
  33985. "The PropertyUniquenessValidator does not support the adapter method %v.",
  33986. methodName
  33987. );
  33988. }
  33989. }
  33990. }
  33991. };
  33992. }
  33993. });
  33994. // node_modules/@e22m4u/js-repository/src/definition/model/properties/primary-keys-definition-validator.js
  33995. var PrimaryKeysDefinitionValidator;
  33996. var init_primary_keys_definition_validator = __esm({
  33997. "node_modules/@e22m4u/js-repository/src/definition/model/properties/primary-keys-definition-validator.js"() {
  33998. init_src2();
  33999. init_errors2();
  34000. init_model_definition_utils();
  34001. PrimaryKeysDefinitionValidator = class extends Service {
  34002. /**
  34003. * Validate.
  34004. *
  34005. * @param {string} modelName
  34006. * @param {object} propDefs
  34007. */
  34008. validate(modelName, propDefs) {
  34009. const propNames = Object.keys(propDefs).filter((propName) => {
  34010. const propDef = propDefs[propName];
  34011. return propDef && typeof propDef === "object" && propDef.primaryKey;
  34012. });
  34013. if (propNames.length < 1) {
  34014. const isDefaultPrimaryKeyAlreadyInUse = Object.keys(propDefs).includes(DEFAULT_PRIMARY_KEY_PROPERTY_NAME);
  34015. if (isDefaultPrimaryKeyAlreadyInUse)
  34016. throw new InvalidArgumentError2(
  34017. '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.',
  34018. DEFAULT_PRIMARY_KEY_PROPERTY_NAME,
  34019. modelName
  34020. );
  34021. return;
  34022. }
  34023. if (propNames.length > 1)
  34024. throw new InvalidArgumentError2(
  34025. "The model definition %v should not have multiple primary keys, but %v keys given.",
  34026. modelName,
  34027. propNames.length
  34028. );
  34029. const pkPropName = propNames[0];
  34030. const pkPropDef = propDefs[pkPropName];
  34031. if (pkPropDef && typeof pkPropDef === "object" && pkPropDef.default !== void 0) {
  34032. throw new InvalidArgumentError2(
  34033. "Do not specify a default value for the primary key %v of the model %v.",
  34034. pkPropName,
  34035. modelName
  34036. );
  34037. }
  34038. }
  34039. };
  34040. }
  34041. });
  34042. // node_modules/@e22m4u/js-repository/src/definition/model/properties/properties-definition-validator.js
  34043. var PropertiesDefinitionValidator;
  34044. var init_properties_definition_validator = __esm({
  34045. "node_modules/@e22m4u/js-repository/src/definition/model/properties/properties-definition-validator.js"() {
  34046. init_src2();
  34047. init_data_type();
  34048. init_utils2();
  34049. init_property_uniqueness();
  34050. init_errors2();
  34051. init_property_validator2();
  34052. init_property_transformer2();
  34053. init_primary_keys_definition_validator();
  34054. PropertiesDefinitionValidator = class extends Service {
  34055. /**
  34056. * Validate.
  34057. *
  34058. * @param {string} modelName
  34059. * @param {object} propDefs
  34060. */
  34061. validate(modelName, propDefs) {
  34062. if (!modelName || typeof modelName !== "string")
  34063. throw new InvalidArgumentError2(
  34064. "The first argument of PropertiesDefinitionValidator.validate should be a non-empty String, but %v given.",
  34065. modelName
  34066. );
  34067. if (!propDefs || typeof propDefs !== "object" || Array.isArray(propDefs)) {
  34068. throw new InvalidArgumentError2(
  34069. 'The provided option "properties" of the model %v should be an Object, but %v given.',
  34070. modelName,
  34071. propDefs
  34072. );
  34073. }
  34074. const propNames = Object.keys(propDefs);
  34075. propNames.forEach((propName) => {
  34076. const propDef = propDefs[propName];
  34077. this._validateProperty(modelName, propName, propDef);
  34078. });
  34079. this.getService(PrimaryKeysDefinitionValidator).validate(
  34080. modelName,
  34081. propDefs
  34082. );
  34083. }
  34084. /**
  34085. * Validate property.
  34086. *
  34087. * @param {string} modelName
  34088. * @param {string} propName
  34089. * @param {object} propDef
  34090. */
  34091. _validateProperty(modelName, propName, propDef) {
  34092. if (!modelName || typeof modelName !== "string")
  34093. throw new InvalidArgumentError2(
  34094. "The first argument of PropertiesDefinitionValidator._validateProperty should be a non-empty String, but %v given.",
  34095. modelName
  34096. );
  34097. if (!propName || typeof propName !== "string")
  34098. throw new InvalidArgumentError2(
  34099. "The property name of the model %v should be a non-empty String, but %v given.",
  34100. modelName,
  34101. propName
  34102. );
  34103. if (!propDef)
  34104. throw new InvalidArgumentError2(
  34105. "The property %v of the model %v should have a property definition, but %v given.",
  34106. propName,
  34107. modelName,
  34108. propDef
  34109. );
  34110. if (typeof propDef === "string") {
  34111. if (!Object.values(DataType).includes(propDef))
  34112. throw new InvalidArgumentError2(
  34113. "In case of a short property definition, the property %v of the model %v should have one of data types: %l, but %v given.",
  34114. propName,
  34115. modelName,
  34116. Object.values(DataType),
  34117. propDef
  34118. );
  34119. return;
  34120. }
  34121. if (!propDef || typeof propDef !== "object" || Array.isArray(propDef)) {
  34122. throw new InvalidArgumentError2(
  34123. "In case of a full property definition, the property %v of the model %v should be an Object, but %v given.",
  34124. propName,
  34125. modelName,
  34126. propDef
  34127. );
  34128. }
  34129. if (!propDef.type || !Object.values(DataType).includes(propDef.type))
  34130. throw new InvalidArgumentError2(
  34131. 'The property %v of the model %v requires the option "type" to have one of data types: %l, but %v given.',
  34132. propName,
  34133. modelName,
  34134. Object.values(DataType),
  34135. propDef.type
  34136. );
  34137. if (propDef.itemType && !Object.values(DataType).includes(propDef.itemType)) {
  34138. throw new InvalidArgumentError2(
  34139. 'The provided option "itemType" of the property %v in the model %v should have one of data types: %l, but %v given.',
  34140. propName,
  34141. modelName,
  34142. Object.values(DataType),
  34143. propDef.itemType
  34144. );
  34145. }
  34146. if (propDef.model && typeof propDef.model !== "string")
  34147. throw new InvalidArgumentError2(
  34148. 'The provided option "model" of the property %v in the model %v should be a String, but %v given.',
  34149. propName,
  34150. modelName,
  34151. propDef.model
  34152. );
  34153. if (propDef.primaryKey && typeof propDef.primaryKey !== "boolean")
  34154. throw new InvalidArgumentError2(
  34155. 'The provided option "primaryKey" of the property %v in the model %v should be a Boolean, but %v given.',
  34156. propName,
  34157. modelName,
  34158. propDef.primaryKey
  34159. );
  34160. if (propDef.columnName && typeof propDef.columnName !== "string")
  34161. throw new InvalidArgumentError2(
  34162. 'The provided option "columnName" of the property %v in the model %v should be a String, but %v given.',
  34163. propName,
  34164. modelName,
  34165. propDef.columnName
  34166. );
  34167. if (propDef.columnType && typeof propDef.columnType !== "string")
  34168. throw new InvalidArgumentError2(
  34169. 'The provided option "columnType" of the property %v in the model %v should be a String, but %v given.',
  34170. propName,
  34171. modelName,
  34172. propDef.columnType
  34173. );
  34174. if (propDef.required && typeof propDef.required !== "boolean")
  34175. throw new InvalidArgumentError2(
  34176. 'The provided option "required" of the property %v in the model %v should be a Boolean, but %v given.',
  34177. propName,
  34178. modelName,
  34179. propDef.required
  34180. );
  34181. if (propDef.required && propDef.default !== void 0)
  34182. throw new InvalidArgumentError2(
  34183. 'The property %v of the model %v is a required property, so it should not have the option "default" to be provided.',
  34184. propName,
  34185. modelName
  34186. );
  34187. if (propDef.primaryKey && propDef.required)
  34188. throw new InvalidArgumentError2(
  34189. 'The property %v of the model %v is a primary key, so it should not have the option "required" to be provided.',
  34190. propName,
  34191. modelName
  34192. );
  34193. if (propDef.primaryKey && propDef.default !== void 0)
  34194. throw new InvalidArgumentError2(
  34195. 'The property %v of the model %v is a primary key, so it should not have the option "default" to be provided.',
  34196. propName,
  34197. modelName
  34198. );
  34199. if (propDef.itemType && propDef.type !== DataType.ARRAY)
  34200. throw new InvalidArgumentError2(
  34201. 'The property %v of the model %v has the non-array type, so it should not have the option "itemType" to be provided.',
  34202. propName,
  34203. modelName,
  34204. propDef.type
  34205. );
  34206. if (propDef.model && propDef.type !== DataType.OBJECT && propDef.itemType !== DataType.OBJECT) {
  34207. if (propDef.type !== DataType.ARRAY) {
  34208. throw new InvalidArgumentError2(
  34209. '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.',
  34210. capitalize(propDef.type),
  34211. propName,
  34212. modelName
  34213. );
  34214. } else {
  34215. throw new InvalidArgumentError2(
  34216. '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.',
  34217. capitalize(propDef.itemType),
  34218. propName,
  34219. modelName
  34220. );
  34221. }
  34222. }
  34223. if (propDef.validate != null) {
  34224. const propertyValidatorRegistry = this.getService(
  34225. PropertyValidatorRegistry
  34226. );
  34227. if (propDef.validate && typeof propDef.validate === "string") {
  34228. if (!propertyValidatorRegistry.hasValidator(propDef.validate))
  34229. throw new InvalidArgumentError2(
  34230. "The property validator %v is not found.",
  34231. propDef.validate
  34232. );
  34233. } else if (Array.isArray(propDef.validate)) {
  34234. for (const validatorName of propDef.validate) {
  34235. if (typeof validatorName !== "string")
  34236. throw new InvalidArgumentError2(
  34237. '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.',
  34238. propName,
  34239. modelName,
  34240. validatorName
  34241. );
  34242. if (!propertyValidatorRegistry.hasValidator(validatorName))
  34243. throw new InvalidArgumentError2(
  34244. "The property validator %v is not found.",
  34245. validatorName
  34246. );
  34247. }
  34248. } else if (typeof propDef.validate === "object") {
  34249. for (const validatorName in propDef.validate) {
  34250. if (!propertyValidatorRegistry.hasValidator(validatorName))
  34251. throw new InvalidArgumentError2(
  34252. "The property validator %v is not found.",
  34253. validatorName
  34254. );
  34255. }
  34256. } else {
  34257. throw new InvalidArgumentError2(
  34258. '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.',
  34259. propName,
  34260. modelName,
  34261. propDef.validate
  34262. );
  34263. }
  34264. }
  34265. if (propDef.transform != null) {
  34266. const propertyTransformerRegistry = this.getService(
  34267. PropertyTransformerRegistry
  34268. );
  34269. if (propDef.transform && typeof propDef.transform === "string") {
  34270. if (!propertyTransformerRegistry.hasTransformer(propDef.transform))
  34271. throw new InvalidArgumentError2(
  34272. "The property transformer %v is not found.",
  34273. propDef.transform
  34274. );
  34275. } else if (Array.isArray(propDef.transform)) {
  34276. for (const transformerName of propDef.transform) {
  34277. if (typeof transformerName !== "string")
  34278. throw new InvalidArgumentError2(
  34279. '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.',
  34280. propName,
  34281. modelName,
  34282. transformerName
  34283. );
  34284. if (!propertyTransformerRegistry.hasTransformer(transformerName))
  34285. throw new InvalidArgumentError2(
  34286. "The property transformer %v is not found.",
  34287. transformerName
  34288. );
  34289. }
  34290. } else if (typeof propDef.transform === "object") {
  34291. for (const transformerName in propDef.transform) {
  34292. if (!propertyTransformerRegistry.hasTransformer(transformerName))
  34293. throw new InvalidArgumentError2(
  34294. "The property transformer %v is not found.",
  34295. transformerName
  34296. );
  34297. }
  34298. } else {
  34299. throw new InvalidArgumentError2(
  34300. '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.',
  34301. propName,
  34302. modelName,
  34303. propDef.transform
  34304. );
  34305. }
  34306. }
  34307. if (propDef.unique) {
  34308. if (typeof propDef.unique !== "boolean" && !Object.values(PropertyUniqueness).includes(propDef.unique)) {
  34309. throw new InvalidArgumentError2(
  34310. 'The provided option "unique" of the property %v in the model %v should be a Boolean or one of values: %l, but %v given.',
  34311. propName,
  34312. modelName,
  34313. Object.values(PropertyUniqueness),
  34314. propDef.unique
  34315. );
  34316. }
  34317. }
  34318. if (propDef.unique && propDef.primaryKey)
  34319. throw new InvalidArgumentError2(
  34320. 'The property %v of the model %v is a primary key, so it should not have the option "unique" to be provided.',
  34321. propName,
  34322. modelName
  34323. );
  34324. }
  34325. };
  34326. }
  34327. });
  34328. // node_modules/@e22m4u/js-repository/src/definition/model/properties/index.js
  34329. var init_properties = __esm({
  34330. "node_modules/@e22m4u/js-repository/src/definition/model/properties/index.js"() {
  34331. init_data_type();
  34332. init_property_definition();
  34333. init_property_uniqueness();
  34334. init_empty_values_definer();
  34335. init_property_validator2();
  34336. init_property_transformer2();
  34337. init_property_uniqueness_validator();
  34338. init_properties_definition_validator();
  34339. init_primary_keys_definition_validator();
  34340. }
  34341. });
  34342. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition.js
  34343. var init_model_definition = __esm({
  34344. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition.js"() {
  34345. }
  34346. });
  34347. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-validator.js
  34348. var ModelDataValidator;
  34349. var init_model_data_validator = __esm({
  34350. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-validator.js"() {
  34351. init_src2();
  34352. init_properties();
  34353. init_utils2();
  34354. init_utils2();
  34355. init_properties();
  34356. init_errors2();
  34357. init_properties();
  34358. init_model_definition_utils();
  34359. ModelDataValidator = class extends Service {
  34360. /**
  34361. * Validate.
  34362. *
  34363. * @param {string} modelName
  34364. * @param {object} modelData
  34365. * @param {boolean} isPartial
  34366. * @returns {undefined}
  34367. */
  34368. validate(modelName, modelData, isPartial = false) {
  34369. if (!isPureObject(modelData))
  34370. throw new InvalidArgumentError2(
  34371. "The data of the model %v should be an Object, but %v given.",
  34372. modelName,
  34373. modelData
  34374. );
  34375. const propDefs = this.getService(
  34376. ModelDefinitionUtils
  34377. ).getPropertiesDefinitionInBaseModelHierarchy(modelName);
  34378. const propNames = Object.keys(isPartial ? modelData : propDefs);
  34379. propNames.forEach((propName) => {
  34380. const propDef = propDefs[propName];
  34381. if (!propDef) return;
  34382. this._validatePropertyValue(
  34383. modelName,
  34384. propName,
  34385. propDef,
  34386. modelData[propName]
  34387. );
  34388. });
  34389. }
  34390. /**
  34391. * Validate property value.
  34392. *
  34393. * @param {string} modelName
  34394. * @param {string} propName
  34395. * @param {string|object} propDef
  34396. * @param {*} propValue
  34397. * @returns {undefined}
  34398. */
  34399. _validatePropertyValue(modelName, propName, propDef, propValue) {
  34400. const propType = this.getService(ModelDefinitionUtils).getDataTypeFromPropertyDefinition(
  34401. propDef
  34402. );
  34403. const isEmpty = this.getService(EmptyValuesDefiner).isEmpty(
  34404. propType,
  34405. propValue
  34406. );
  34407. if (isEmpty) {
  34408. const isRequired = typeof propDef === "string" ? false : Boolean(propDef.required);
  34409. if (!isRequired) return;
  34410. throw new InvalidArgumentError2(
  34411. "The property %v of the model %v is required, but %v given.",
  34412. propName,
  34413. modelName,
  34414. propValue
  34415. );
  34416. }
  34417. this._validateValueByPropertyValidators(
  34418. modelName,
  34419. propName,
  34420. propDef,
  34421. propValue
  34422. );
  34423. this._validateValueByPropertyType(modelName, propName, propDef, propValue);
  34424. }
  34425. /**
  34426. * Validate value by property type.
  34427. *
  34428. * @param {string} modelName
  34429. * @param {string} propName
  34430. * @param {string|object} propDef
  34431. * @param {*} propValue
  34432. * @param {boolean} isArrayValue
  34433. * @returns {undefined}
  34434. */
  34435. _validateValueByPropertyType(modelName, propName, propDef, propValue, isArrayValue = false) {
  34436. let expectingType;
  34437. if (isArrayValue) {
  34438. if (typeof propDef === "object") {
  34439. expectingType = propDef.itemType ?? DataType.ANY;
  34440. } else {
  34441. expectingType = DataType.ANY;
  34442. }
  34443. } else {
  34444. expectingType = typeof propDef !== "string" ? propDef.type : propDef;
  34445. }
  34446. const createError = (expected) => {
  34447. 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.";
  34448. const ctorName = getCtorName(propValue);
  34449. const givenStr = ctorName ?? typeof propValue;
  34450. return new InvalidArgumentError2(
  34451. pattern,
  34452. propName,
  34453. modelName,
  34454. expected,
  34455. givenStr
  34456. );
  34457. };
  34458. switch (expectingType) {
  34459. // STRING
  34460. case DataType.STRING:
  34461. if (typeof propValue !== "string") throw createError("a String");
  34462. break;
  34463. // NUMBER
  34464. case DataType.NUMBER:
  34465. if (typeof propValue !== "number") throw createError("a Number");
  34466. break;
  34467. // BOOLEAN
  34468. case DataType.BOOLEAN:
  34469. if (typeof propValue !== "boolean") throw createError("a Boolean");
  34470. break;
  34471. // ARRAY
  34472. case DataType.ARRAY:
  34473. if (!Array.isArray(propValue)) throw createError("an Array");
  34474. propValue.forEach(
  34475. (value) => this._validateValueByPropertyType(
  34476. modelName,
  34477. propName,
  34478. propDef,
  34479. value,
  34480. true
  34481. )
  34482. );
  34483. break;
  34484. // OBJECT
  34485. case DataType.OBJECT:
  34486. if (!isPureObject(propValue)) throw createError("an Object");
  34487. if (typeof propDef === "object" && propDef.model)
  34488. this.validate(propDef.model, propValue);
  34489. break;
  34490. }
  34491. }
  34492. /**
  34493. * Validate value by property validators.
  34494. *
  34495. * @param {string} modelName
  34496. * @param {string} propName
  34497. * @param {string|object} propDef
  34498. * @param {*} propValue
  34499. * @returns {undefined}
  34500. */
  34501. _validateValueByPropertyValidators(modelName, propName, propDef, propValue) {
  34502. if (typeof propDef === "string" || propDef.validate == null) return;
  34503. const validateDef = propDef.validate;
  34504. const validatorRegistry = this.getService(PropertyValidatorRegistry);
  34505. const createError = (validatorName) => new InvalidArgumentError2(
  34506. "The property %v of the model %v has an invalid value %v that caught by the validator %v.",
  34507. propName,
  34508. modelName,
  34509. propValue,
  34510. validatorName
  34511. );
  34512. const validateBy = (validatorName, validatorOptions = void 0) => {
  34513. const validator = validatorRegistry.getValidator(validatorName);
  34514. const context = { validatorName, modelName, propName };
  34515. const valid = validator(propValue, validatorOptions, context);
  34516. if (valid instanceof Promise) {
  34517. throw new InvalidArgumentError2(
  34518. "Asynchronous property validators are not supported, but the property validator %v returns a Promise.",
  34519. validatorName
  34520. );
  34521. } else if (valid !== true) {
  34522. throw createError(validatorName);
  34523. }
  34524. };
  34525. if (validateDef && typeof validateDef === "string") {
  34526. validateBy(validateDef);
  34527. } else if (Array.isArray(validateDef)) {
  34528. validateDef.forEach((validatorName) => validateBy(validatorName));
  34529. } else if (validateDef !== null && typeof validateDef === "object") {
  34530. Object.keys(validateDef).forEach((validatorName) => {
  34531. if (Object.prototype.hasOwnProperty.call(validateDef, validatorName)) {
  34532. const validatorOptions = validateDef[validatorName];
  34533. validateBy(validatorName, validatorOptions);
  34534. }
  34535. });
  34536. } else {
  34537. throw new InvalidArgumentError2(
  34538. '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.',
  34539. propName,
  34540. modelName,
  34541. validateDef
  34542. );
  34543. }
  34544. }
  34545. };
  34546. }
  34547. });
  34548. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-sanitizer.js
  34549. var ModelDataSanitizer;
  34550. var init_model_data_sanitizer = __esm({
  34551. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-sanitizer.js"() {
  34552. init_src2();
  34553. init_errors2();
  34554. init_model_definition_utils();
  34555. ModelDataSanitizer = class extends Service {
  34556. /**
  34557. * Validate.
  34558. *
  34559. * @param {string} modelName
  34560. * @param {object} modelData
  34561. * @returns {object}
  34562. */
  34563. sanitize(modelName, modelData) {
  34564. if (!modelName || typeof modelName !== "string")
  34565. throw new InvalidArgumentError2(
  34566. "The first argument of ModelDataSanitizer.sanitize should be a string, but %v given.",
  34567. modelName
  34568. );
  34569. if (!modelData || typeof modelData !== "object")
  34570. throw new InvalidArgumentError2(
  34571. "The second argument of ModelDataSanitizer.sanitize should be an Object, but %v given.",
  34572. modelData
  34573. );
  34574. return this.getService(
  34575. ModelDefinitionUtils
  34576. ).excludeObjectKeysByRelationNames(modelName, modelData);
  34577. }
  34578. };
  34579. }
  34580. });
  34581. // node_modules/@e22m4u/js-repository/src/definition/model/model-data-transformer.js
  34582. var ModelDataTransformer;
  34583. var init_model_data_transformer = __esm({
  34584. "node_modules/@e22m4u/js-repository/src/definition/model/model-data-transformer.js"() {
  34585. init_src2();
  34586. init_utils2();
  34587. init_utils2();
  34588. init_utils2();
  34589. init_properties();
  34590. init_errors2();
  34591. init_model_definition_utils();
  34592. init_properties();
  34593. ModelDataTransformer = class extends Service {
  34594. /**
  34595. * Transform.
  34596. *
  34597. * @param {string} modelName
  34598. * @param {object} modelData
  34599. * @param {boolean} isPartial
  34600. * @returns {object|Promise<object>}
  34601. */
  34602. transform(modelName, modelData, isPartial = false) {
  34603. if (!isPureObject(modelData))
  34604. throw new InvalidArgumentError2(
  34605. "The data of the model %v should be an Object, but %v given.",
  34606. modelName,
  34607. modelData
  34608. );
  34609. const emptyValuesDefiner = this.getService(EmptyValuesDefiner);
  34610. const modelDefinitionUtils = this.getService(ModelDefinitionUtils);
  34611. const propDefs = modelDefinitionUtils.getPropertiesDefinitionInBaseModelHierarchy(
  34612. modelName
  34613. );
  34614. const propNames = Object.keys(isPartial ? modelData : propDefs);
  34615. const transformedData = cloneDeep(modelData);
  34616. return propNames.reduce((transformedDataOrPromise, propName) => {
  34617. const propDef = propDefs[propName];
  34618. if (!propDef) return transformedDataOrPromise;
  34619. const propType = modelDefinitionUtils.getDataTypeFromPropertyDefinition(propDef);
  34620. const propValue = modelData[propName];
  34621. const isEmpty = emptyValuesDefiner.isEmpty(propType, propValue);
  34622. if (isEmpty) return transformedDataOrPromise;
  34623. const newPropValueOrPromise = this._transformPropertyValue(
  34624. modelName,
  34625. propName,
  34626. propDef,
  34627. propValue
  34628. );
  34629. return transformPromise(newPropValueOrPromise, (newPropValue) => {
  34630. return transformPromise(transformedDataOrPromise, (resolvedData) => {
  34631. if (newPropValue !== propValue) resolvedData[propName] = newPropValue;
  34632. return resolvedData;
  34633. });
  34634. });
  34635. }, transformedData);
  34636. }
  34637. /**
  34638. * Transform property value.
  34639. *
  34640. * @param {string} modelName
  34641. * @param {string} propName
  34642. * @param {string|object} propDef
  34643. * @param {*} propValue
  34644. * @returns {*}
  34645. */
  34646. _transformPropertyValue(modelName, propName, propDef, propValue) {
  34647. if (typeof propDef === "string" || propDef.transform == null)
  34648. return propValue;
  34649. const transformDef = propDef.transform;
  34650. const transformerRegistry = this.getService(PropertyTransformerRegistry);
  34651. const transformFn = (value, transformerName, transformerOptions = void 0) => {
  34652. const transformer = transformerRegistry.getTransformer(transformerName);
  34653. const context = { transformerName, modelName, propName };
  34654. return transformer(value, transformerOptions, context);
  34655. };
  34656. if (transformDef && typeof transformDef === "string") {
  34657. return transformFn(propValue, transformDef);
  34658. } else if (Array.isArray(transformDef)) {
  34659. return transformDef.reduce((valueOrPromise, transformerName) => {
  34660. return transformPromise(valueOrPromise, (value) => {
  34661. return transformFn(value, transformerName);
  34662. });
  34663. }, propValue);
  34664. } else if (transformDef !== null && typeof transformDef === "object") {
  34665. return Object.keys(transformDef).reduce(
  34666. (valueOrPromise, transformerName) => {
  34667. const transformerOptions = transformDef[transformerName];
  34668. return transformPromise(valueOrPromise, (value) => {
  34669. return transformFn(value, transformerName, transformerOptions);
  34670. });
  34671. },
  34672. propValue
  34673. );
  34674. } else {
  34675. throw new InvalidArgumentError2(
  34676. '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.',
  34677. propName,
  34678. modelName,
  34679. transformDef
  34680. );
  34681. }
  34682. }
  34683. };
  34684. }
  34685. });
  34686. // node_modules/@e22m4u/js-repository/src/definition/model/model-definition-validator.js
  34687. var ModelDefinitionValidator;
  34688. var init_model_definition_validator = __esm({
  34689. "node_modules/@e22m4u/js-repository/src/definition/model/model-definition-validator.js"() {
  34690. init_src2();
  34691. init_errors2();
  34692. init_relations();
  34693. init_properties();
  34694. ModelDefinitionValidator = class extends Service {
  34695. /**
  34696. * Validate.
  34697. *
  34698. * @param {object} modelDef
  34699. */
  34700. validate(modelDef) {
  34701. if (!modelDef || typeof modelDef !== "object" || Array.isArray(modelDef))
  34702. throw new InvalidArgumentError2(
  34703. "The model definition should be an Object, but %v given.",
  34704. modelDef
  34705. );
  34706. if (!modelDef.name || typeof modelDef.name !== "string")
  34707. throw new InvalidArgumentError2(
  34708. 'The model definition requires the option "name" as a non-empty String, but %v given.',
  34709. modelDef.name
  34710. );
  34711. if (modelDef.datasource && typeof modelDef.datasource !== "string")
  34712. throw new InvalidArgumentError2(
  34713. 'The provided option "datasource" of the model %v should be a String, but %v given.',
  34714. modelDef.name,
  34715. modelDef.datasource
  34716. );
  34717. if (modelDef.base && typeof modelDef.base !== "string")
  34718. throw new InvalidArgumentError2(
  34719. 'The provided option "base" of the model %v should be a String, but %v given.',
  34720. modelDef.name,
  34721. modelDef.base
  34722. );
  34723. if (modelDef.tableName && typeof modelDef.tableName !== "string")
  34724. throw new InvalidArgumentError2(
  34725. 'The provided option "tableName" of the model %v should be a String, but %v given.',
  34726. modelDef.name,
  34727. modelDef.tableName
  34728. );
  34729. if (modelDef.properties) {
  34730. if (typeof modelDef.properties !== "object" || Array.isArray(modelDef.properties)) {
  34731. throw new InvalidArgumentError2(
  34732. 'The provided option "properties" of the model %v should be an Object, but %v given.',
  34733. modelDef.name,
  34734. modelDef.properties
  34735. );
  34736. }
  34737. this.getService(PropertiesDefinitionValidator).validate(
  34738. modelDef.name,
  34739. modelDef.properties
  34740. );
  34741. }
  34742. if (modelDef.relations) {
  34743. if (typeof modelDef.relations !== "object" || Array.isArray(modelDef.relations)) {
  34744. throw new InvalidArgumentError2(
  34745. 'The provided option "relations" of the model %v should be an Object, but %v given.',
  34746. modelDef.name,
  34747. modelDef.relations
  34748. );
  34749. }
  34750. this.getService(RelationsDefinitionValidator).validate(
  34751. modelDef.name,
  34752. modelDef.relations
  34753. );
  34754. }
  34755. }
  34756. };
  34757. }
  34758. });
  34759. // node_modules/@e22m4u/js-repository/src/definition/model/index.js
  34760. var init_model = __esm({
  34761. "node_modules/@e22m4u/js-repository/src/definition/model/index.js"() {
  34762. init_relations();
  34763. init_properties();
  34764. init_model_definition();
  34765. init_model_data_validator();
  34766. init_model_data_sanitizer();
  34767. init_model_data_transformer();
  34768. init_model_definition_utils();
  34769. init_model_definition_validator();
  34770. }
  34771. });
  34772. // node_modules/@e22m4u/js-repository/src/definition/datasource/datasource-definition-validator.js
  34773. var DatasourceDefinitionValidator;
  34774. var init_datasource_definition_validator = __esm({
  34775. "node_modules/@e22m4u/js-repository/src/definition/datasource/datasource-definition-validator.js"() {
  34776. init_src2();
  34777. init_errors2();
  34778. DatasourceDefinitionValidator = class extends Service {
  34779. /**
  34780. * Validate.
  34781. *
  34782. * @param {object} datasourceDef
  34783. */
  34784. validate(datasourceDef) {
  34785. if (!datasourceDef || typeof datasourceDef !== "object")
  34786. throw new InvalidArgumentError2(
  34787. "The datasource definition should be an Object, but %v given.",
  34788. datasourceDef
  34789. );
  34790. if (!datasourceDef.name || typeof datasourceDef.name !== "string")
  34791. throw new InvalidArgumentError2(
  34792. 'The datasource definition requires the option "name" as a non-empty String, but %v given.',
  34793. datasourceDef.name
  34794. );
  34795. if (!datasourceDef.adapter || typeof datasourceDef.adapter !== "string")
  34796. throw new InvalidArgumentError2(
  34797. 'The datasource %v requires the option "adapter" as a non-empty String, but %v given.',
  34798. datasourceDef.name,
  34799. datasourceDef.adapter
  34800. );
  34801. }
  34802. };
  34803. }
  34804. });
  34805. // node_modules/@e22m4u/js-repository/src/definition/datasource/index.js
  34806. var init_datasource = __esm({
  34807. "node_modules/@e22m4u/js-repository/src/definition/datasource/index.js"() {
  34808. init_datasource_definition_validator();
  34809. }
  34810. });
  34811. // node_modules/@e22m4u/js-repository/src/definition/index.js
  34812. var init_definition = __esm({
  34813. "node_modules/@e22m4u/js-repository/src/definition/index.js"() {
  34814. init_model();
  34815. init_datasource();
  34816. init_definition_registry();
  34817. }
  34818. });
  34819. // node_modules/@e22m4u/js-repository/src/filter/fields-clause-tool.js
  34820. var FieldsClauseTool;
  34821. var init_fields_clause_tool = __esm({
  34822. "node_modules/@e22m4u/js-repository/src/filter/fields-clause-tool.js"() {
  34823. init_src2();
  34824. init_utils2();
  34825. init_errors2();
  34826. init_definition();
  34827. FieldsClauseTool = class extends Service {
  34828. /**
  34829. * Filter.
  34830. *
  34831. * @param {object|object[]} input
  34832. * @param {string} modelName
  34833. * @param {string|string[]|undefined} clause
  34834. * @returns {object|object[]}
  34835. */
  34836. filter(input, modelName, clause) {
  34837. const isArray = Array.isArray(input);
  34838. let entities = isArray ? input : [input];
  34839. entities.forEach((entity) => {
  34840. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  34841. throw new InvalidArgumentError2(
  34842. "The first argument of FieldsClauseTool.filter should be an Object or an Array of Object, but %v given.",
  34843. entity
  34844. );
  34845. });
  34846. if (!modelName || typeof modelName !== "string")
  34847. throw new InvalidArgumentError2(
  34848. "The second argument of FieldsClauseTool.filter should be a non-empty String, but %v given.",
  34849. modelName
  34850. );
  34851. if (clause == null) return input;
  34852. const fields = Array.isArray(clause) ? clause.slice() : [clause];
  34853. if (!fields.length) return input;
  34854. fields.forEach((field) => {
  34855. if (!field || typeof field !== "string")
  34856. throw new InvalidArgumentError2(
  34857. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34858. field
  34859. );
  34860. });
  34861. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  34862. modelName
  34863. );
  34864. if (fields.indexOf(pkPropName) === -1) fields.push(pkPropName);
  34865. entities = entities.map((entity) => selectObjectKeys(entity, fields));
  34866. return isArray ? entities : entities[0];
  34867. }
  34868. /**
  34869. * Validate fields clause.
  34870. *
  34871. * @param {string|string[]|undefined} clause
  34872. */
  34873. static validateFieldsClause(clause) {
  34874. if (clause == null) return;
  34875. const fields = Array.isArray(clause) ? clause : [clause];
  34876. if (!fields.length) return;
  34877. fields.forEach((field) => {
  34878. if (!field || typeof field !== "string")
  34879. throw new InvalidArgumentError2(
  34880. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34881. field
  34882. );
  34883. });
  34884. }
  34885. /**
  34886. * Normalize fields clause.
  34887. *
  34888. * @param {string|string[]|undefined} clause
  34889. * @returns {string[]|undefined}
  34890. */
  34891. static normalizeFieldsClause(clause) {
  34892. if (clause == null) return;
  34893. const fields = Array.isArray(clause) ? clause : [clause];
  34894. if (!fields.length) return;
  34895. fields.forEach((field) => {
  34896. if (!field || typeof field !== "string")
  34897. throw new InvalidArgumentError2(
  34898. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  34899. field
  34900. );
  34901. });
  34902. return fields;
  34903. }
  34904. };
  34905. }
  34906. });
  34907. // node_modules/@e22m4u/js-repository/src/relations/has-one-resolver.js
  34908. var HasOneResolver;
  34909. var init_has_one_resolver = __esm({
  34910. "node_modules/@e22m4u/js-repository/src/relations/has-one-resolver.js"() {
  34911. init_src2();
  34912. init_utils2();
  34913. init_definition();
  34914. init_errors2();
  34915. init_repository2();
  34916. init_definition();
  34917. HasOneResolver = class extends Service {
  34918. /**
  34919. * Include to.
  34920. *
  34921. * @param {object[]} entities
  34922. * @param {string} sourceName
  34923. * @param {string} targetName
  34924. * @param {string} relationName
  34925. * @param {string} foreignKey
  34926. * @param {object|undefined} scope
  34927. * @returns {Promise<void>}
  34928. */
  34929. async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
  34930. if (!entities || !Array.isArray(entities))
  34931. throw new InvalidArgumentError2(
  34932. 'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v given.',
  34933. entities
  34934. );
  34935. if (!sourceName || typeof sourceName !== "string")
  34936. throw new InvalidArgumentError2(
  34937. 'The parameter "sourceName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34938. sourceName
  34939. );
  34940. if (!targetName || typeof targetName !== "string")
  34941. throw new InvalidArgumentError2(
  34942. 'The parameter "targetName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34943. targetName
  34944. );
  34945. if (!relationName || typeof relationName !== "string")
  34946. throw new InvalidArgumentError2(
  34947. 'The parameter "relationName" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34948. relationName
  34949. );
  34950. if (!foreignKey || typeof foreignKey !== "string")
  34951. throw new InvalidArgumentError2(
  34952. 'The parameter "foreignKey" of HasOneResolver.includeTo requires a non-empty String, but %v given.',
  34953. foreignKey
  34954. );
  34955. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  34956. throw new InvalidArgumentError2(
  34957. 'The provided parameter "scope" of HasOneResolver.includeTo should be an Object, but %v given.',
  34958. scope
  34959. );
  34960. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  34961. sourceName
  34962. );
  34963. const sourceIds = [];
  34964. entities.forEach((entity) => {
  34965. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  34966. throw new InvalidArgumentError2(
  34967. 'The parameter "entities" of HasOneResolver.includeTo requires an Array of Object, but %v given.',
  34968. entity
  34969. );
  34970. const sourceId = entity[sourcePkPropName];
  34971. if (sourceIds.includes(sourceId)) return;
  34972. sourceIds.push(sourceId);
  34973. });
  34974. const promises = [];
  34975. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  34976. scope = scope ? cloneDeep(scope) : {};
  34977. const targetBySourceId = /* @__PURE__ */ new Map();
  34978. sourceIds.forEach((sourceId) => {
  34979. const filter = cloneDeep(scope);
  34980. filter.where = {
  34981. and: [{ [foreignKey]: sourceId }, ...scope.where ? [scope.where] : []]
  34982. };
  34983. filter.limit = 1;
  34984. promises.push(
  34985. targetRepository.find(filter).then((result) => {
  34986. if (result.length) targetBySourceId.set(sourceId, result[0]);
  34987. })
  34988. );
  34989. });
  34990. await Promise.all(promises);
  34991. Array.from(targetBySourceId.keys()).forEach((sourceId) => {
  34992. const sources = entities.filter((v) => v[sourcePkPropName] === sourceId);
  34993. sources.forEach((v) => v[relationName] = targetBySourceId.get(sourceId));
  34994. });
  34995. }
  34996. /**
  34997. * Include polymorphic to.
  34998. *
  34999. * @param {object[]} entities
  35000. * @param {string} sourceName
  35001. * @param {string} targetName
  35002. * @param {string} relationName
  35003. * @param {string} foreignKey
  35004. * @param {string} discriminator
  35005. * @param {object|undefined} scope
  35006. * @returns {Promise<void>}
  35007. */
  35008. async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
  35009. if (!entities || !Array.isArray(entities))
  35010. throw new InvalidArgumentError2(
  35011. 'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35012. entities
  35013. );
  35014. if (!sourceName || typeof sourceName !== "string")
  35015. throw new InvalidArgumentError2(
  35016. 'The parameter "sourceName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35017. sourceName
  35018. );
  35019. if (!targetName || typeof targetName !== "string")
  35020. throw new InvalidArgumentError2(
  35021. 'The parameter "targetName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35022. targetName
  35023. );
  35024. if (!relationName || typeof relationName !== "string")
  35025. throw new InvalidArgumentError2(
  35026. 'The parameter "relationName" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35027. relationName
  35028. );
  35029. if (!foreignKey || typeof foreignKey !== "string")
  35030. throw new InvalidArgumentError2(
  35031. 'The parameter "foreignKey" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35032. foreignKey
  35033. );
  35034. if (!discriminator || typeof discriminator !== "string")
  35035. throw new InvalidArgumentError2(
  35036. 'The parameter "discriminator" of HasOneResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35037. discriminator
  35038. );
  35039. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35040. throw new InvalidArgumentError2(
  35041. 'The provided parameter "scope" of HasOneResolver.includePolymorphicTo should be an Object, but %v given.',
  35042. scope
  35043. );
  35044. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35045. sourceName
  35046. );
  35047. const sourceIds = [];
  35048. entities.forEach((entity) => {
  35049. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35050. throw new InvalidArgumentError2(
  35051. 'The parameter "entities" of HasOneResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35052. entity
  35053. );
  35054. const sourceId = entity[sourcePkPropName];
  35055. if (sourceIds.includes(sourceId)) return;
  35056. sourceIds.push(sourceId);
  35057. });
  35058. const promises = [];
  35059. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35060. scope = scope ? cloneDeep(scope) : {};
  35061. const targetBySourceId = /* @__PURE__ */ new Map();
  35062. sourceIds.forEach((sourceId) => {
  35063. const filter = cloneDeep(scope);
  35064. filter.where = {
  35065. and: [
  35066. { [foreignKey]: sourceId, [discriminator]: sourceName },
  35067. ...scope.where ? [scope.where] : []
  35068. ]
  35069. };
  35070. filter.limit = 1;
  35071. promises.push(
  35072. targetRepository.find(filter).then((result) => {
  35073. if (result.length) targetBySourceId.set(sourceId, result[0]);
  35074. })
  35075. );
  35076. });
  35077. await Promise.all(promises);
  35078. Array.from(targetBySourceId.keys()).forEach((sourceId) => {
  35079. const sources = entities.filter((v) => v[sourcePkPropName] === sourceId);
  35080. sources.forEach((v) => v[relationName] = targetBySourceId.get(sourceId));
  35081. });
  35082. }
  35083. /**
  35084. * Include polymorphic by relation name.
  35085. *
  35086. * @param {object[]} entities
  35087. * @param {string} sourceName
  35088. * @param {string} targetName
  35089. * @param {string} relationName
  35090. * @param {string} targetRelationName
  35091. * @param {object|undefined} scope
  35092. * @returns {Promise<void>}
  35093. */
  35094. async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
  35095. if (!entities || !Array.isArray(entities))
  35096. throw new InvalidArgumentError2(
  35097. 'The parameter "entities" of HasOneResolver.includePolymorphicByRelationName requires an Array of Object, but %v given.',
  35098. entities
  35099. );
  35100. if (!sourceName || typeof sourceName !== "string")
  35101. throw new InvalidArgumentError2(
  35102. 'The parameter "sourceName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35103. sourceName
  35104. );
  35105. if (!targetName || typeof targetName !== "string")
  35106. throw new InvalidArgumentError2(
  35107. 'The parameter "targetName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35108. targetName
  35109. );
  35110. if (!relationName || typeof relationName !== "string")
  35111. throw new InvalidArgumentError2(
  35112. 'The parameter "relationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35113. relationName
  35114. );
  35115. if (!targetRelationName || typeof targetRelationName !== "string")
  35116. throw new InvalidArgumentError2(
  35117. 'The parameter "targetRelationName" of HasOneResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35118. targetRelationName
  35119. );
  35120. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35121. throw new InvalidArgumentError2(
  35122. 'The provided parameter "scope" of HasOneResolver.includePolymorphicByRelationName should be an Object, but %v given.',
  35123. scope
  35124. );
  35125. const targetRelationDef = this.getService(
  35126. ModelDefinitionUtils
  35127. ).getRelationDefinitionByName(targetName, targetRelationName);
  35128. if (targetRelationDef.type !== RelationType.BELONGS_TO)
  35129. throw new InvalidArgumentError2(
  35130. '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.',
  35131. relationName,
  35132. sourceName,
  35133. targetRelationName,
  35134. targetRelationDef.type
  35135. );
  35136. if (!targetRelationDef.polymorphic)
  35137. throw new InvalidArgumentError2(
  35138. 'The relation %v of the model %v is a polymorphic "hasOne" relation, so it requires the target relation %v to be a polymorphic too.',
  35139. relationName,
  35140. sourceName,
  35141. targetRelationName
  35142. );
  35143. const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
  35144. const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
  35145. return this.includePolymorphicTo(
  35146. entities,
  35147. sourceName,
  35148. targetName,
  35149. relationName,
  35150. foreignKey,
  35151. discriminator,
  35152. scope
  35153. );
  35154. }
  35155. };
  35156. }
  35157. });
  35158. // node_modules/@e22m4u/js-repository/src/relations/has-many-resolver.js
  35159. var HasManyResolver;
  35160. var init_has_many_resolver = __esm({
  35161. "node_modules/@e22m4u/js-repository/src/relations/has-many-resolver.js"() {
  35162. init_src2();
  35163. init_utils2();
  35164. init_definition();
  35165. init_errors2();
  35166. init_repository2();
  35167. init_definition();
  35168. HasManyResolver = class extends Service {
  35169. /**
  35170. * Include to.
  35171. *
  35172. * @param {object[]} entities
  35173. * @param {string} sourceName
  35174. * @param {string} targetName
  35175. * @param {string} relationName
  35176. * @param {string} foreignKey
  35177. * @param {object|undefined} scope
  35178. * @returns {Promise<void>}
  35179. */
  35180. async includeTo(entities, sourceName, targetName, relationName, foreignKey, scope = void 0) {
  35181. if (!entities || !Array.isArray(entities))
  35182. throw new InvalidArgumentError2(
  35183. 'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v given.',
  35184. entities
  35185. );
  35186. if (!sourceName || typeof sourceName !== "string")
  35187. throw new InvalidArgumentError2(
  35188. 'The parameter "sourceName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35189. sourceName
  35190. );
  35191. if (!targetName || typeof targetName !== "string")
  35192. throw new InvalidArgumentError2(
  35193. 'The parameter "targetName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35194. targetName
  35195. );
  35196. if (!relationName || typeof relationName !== "string")
  35197. throw new InvalidArgumentError2(
  35198. 'The parameter "relationName" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35199. relationName
  35200. );
  35201. if (!foreignKey || typeof foreignKey !== "string")
  35202. throw new InvalidArgumentError2(
  35203. 'The parameter "foreignKey" of HasManyResolver.includeTo requires a non-empty String, but %v given.',
  35204. foreignKey
  35205. );
  35206. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35207. throw new InvalidArgumentError2(
  35208. 'The provided parameter "scope" of HasManyResolver.includeTo should be an Object, but %v given.',
  35209. scope
  35210. );
  35211. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35212. sourceName
  35213. );
  35214. const sourceIds = [];
  35215. entities.forEach((entity) => {
  35216. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35217. throw new InvalidArgumentError2(
  35218. 'The parameter "entities" of HasManyResolver.includeTo requires an Array of Object, but %v given.',
  35219. entity
  35220. );
  35221. const sourceId = entity[sourcePkPropName];
  35222. if (sourceIds.includes(sourceId)) return;
  35223. sourceIds.push(sourceId);
  35224. });
  35225. const promises = [];
  35226. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35227. scope = scope ? cloneDeep(scope) : {};
  35228. const targetsBySourceId = /* @__PURE__ */ new Map();
  35229. sourceIds.forEach((sourceId) => {
  35230. const filter = cloneDeep(scope);
  35231. filter.where = {
  35232. and: [{ [foreignKey]: sourceId }, ...scope.where ? [scope.where] : []]
  35233. };
  35234. promises.push(
  35235. targetRepository.find(filter).then((result) => {
  35236. if (result.length) {
  35237. let targets = targetsBySourceId.get(sourceId) ?? [];
  35238. targets = [...targets, ...result];
  35239. targetsBySourceId.set(sourceId, targets);
  35240. }
  35241. })
  35242. );
  35243. });
  35244. await Promise.all(promises);
  35245. entities.forEach((entity) => {
  35246. const sourceId = entity[sourcePkPropName];
  35247. entity[relationName] = targetsBySourceId.get(sourceId) ?? [];
  35248. });
  35249. }
  35250. /**
  35251. * Include polymorphic to.
  35252. *
  35253. * @param {object[]} entities
  35254. * @param {string} sourceName
  35255. * @param {string} targetName
  35256. * @param {string} relationName
  35257. * @param {string} foreignKey
  35258. * @param {string} discriminator
  35259. * @param {object|undefined} scope
  35260. * @returns {Promise<void>}
  35261. */
  35262. async includePolymorphicTo(entities, sourceName, targetName, relationName, foreignKey, discriminator, scope = void 0) {
  35263. if (!entities || !Array.isArray(entities))
  35264. throw new InvalidArgumentError2(
  35265. 'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35266. entities
  35267. );
  35268. if (!sourceName || typeof sourceName !== "string")
  35269. throw new InvalidArgumentError2(
  35270. 'The parameter "sourceName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35271. sourceName
  35272. );
  35273. if (!targetName || typeof targetName !== "string")
  35274. throw new InvalidArgumentError2(
  35275. 'The parameter "targetName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35276. targetName
  35277. );
  35278. if (!relationName || typeof relationName !== "string")
  35279. throw new InvalidArgumentError2(
  35280. 'The parameter "relationName" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35281. relationName
  35282. );
  35283. if (!foreignKey || typeof foreignKey !== "string")
  35284. throw new InvalidArgumentError2(
  35285. 'The parameter "foreignKey" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35286. foreignKey
  35287. );
  35288. if (!discriminator || typeof discriminator !== "string")
  35289. throw new InvalidArgumentError2(
  35290. 'The parameter "discriminator" of HasManyResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35291. discriminator
  35292. );
  35293. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35294. throw new InvalidArgumentError2(
  35295. 'The provided parameter "scope" of HasManyResolver.includePolymorphicTo should be an Object, but %v given.',
  35296. scope
  35297. );
  35298. const sourcePkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35299. sourceName
  35300. );
  35301. const sourceIds = [];
  35302. entities.forEach((entity) => {
  35303. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35304. throw new InvalidArgumentError2(
  35305. 'The parameter "entities" of HasManyResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35306. entity
  35307. );
  35308. const sourceId = entity[sourcePkPropName];
  35309. if (sourceIds.includes(sourceId)) return;
  35310. sourceIds.push(sourceId);
  35311. });
  35312. const promises = [];
  35313. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35314. scope = scope ? cloneDeep(scope) : {};
  35315. const targetsBySourceId = /* @__PURE__ */ new Map();
  35316. sourceIds.forEach((sourceId) => {
  35317. const filter = cloneDeep(scope);
  35318. filter.where = {
  35319. and: [
  35320. { [foreignKey]: sourceId, [discriminator]: sourceName },
  35321. ...scope.where ? [scope.where] : []
  35322. ]
  35323. };
  35324. promises.push(
  35325. targetRepository.find(filter).then((result) => {
  35326. if (result.length) {
  35327. let targets = targetsBySourceId.get(sourceId) ?? [];
  35328. targets = [...targets, ...result];
  35329. targetsBySourceId.set(sourceId, targets);
  35330. }
  35331. })
  35332. );
  35333. });
  35334. await Promise.all(promises);
  35335. entities.forEach((entity) => {
  35336. const sourceId = entity[sourcePkPropName];
  35337. entity[relationName] = targetsBySourceId.get(sourceId) ?? [];
  35338. });
  35339. }
  35340. /**
  35341. * Include polymorphic by relation name.
  35342. *
  35343. * @param {object[]} entities
  35344. * @param {string} sourceName
  35345. * @param {string} targetName
  35346. * @param {string} relationName
  35347. * @param {string} targetRelationName
  35348. * @param {object|undefined} scope
  35349. * @returns {Promise<void>}
  35350. */
  35351. async includePolymorphicByRelationName(entities, sourceName, targetName, relationName, targetRelationName, scope = void 0) {
  35352. if (!entities || !Array.isArray(entities))
  35353. throw new InvalidArgumentError2(
  35354. 'The parameter "entities" of HasManyResolver.includePolymorphicByRelationName requires an Array of Object, but %v given.',
  35355. entities
  35356. );
  35357. if (!sourceName || typeof sourceName !== "string")
  35358. throw new InvalidArgumentError2(
  35359. 'The parameter "sourceName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35360. sourceName
  35361. );
  35362. if (!targetName || typeof targetName !== "string")
  35363. throw new InvalidArgumentError2(
  35364. 'The parameter "targetName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35365. targetName
  35366. );
  35367. if (!relationName || typeof relationName !== "string")
  35368. throw new InvalidArgumentError2(
  35369. 'The parameter "relationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35370. relationName
  35371. );
  35372. if (!targetRelationName || typeof targetRelationName !== "string")
  35373. throw new InvalidArgumentError2(
  35374. 'The parameter "targetRelationName" of HasManyResolver.includePolymorphicByRelationName requires a non-empty String, but %v given.',
  35375. targetRelationName
  35376. );
  35377. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35378. throw new InvalidArgumentError2(
  35379. 'The provided parameter "scope" of HasManyResolver.includePolymorphicByRelationName should be an Object, but %v given.',
  35380. scope
  35381. );
  35382. const targetRelationDef = this.getService(
  35383. ModelDefinitionUtils
  35384. ).getRelationDefinitionByName(targetName, targetRelationName);
  35385. if (targetRelationDef.type !== RelationType.BELONGS_TO)
  35386. throw new InvalidArgumentError2(
  35387. '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.',
  35388. relationName,
  35389. sourceName,
  35390. targetRelationName,
  35391. targetRelationDef.type
  35392. );
  35393. if (!targetRelationDef.polymorphic)
  35394. throw new InvalidArgumentError2(
  35395. 'The relation %v of the model %v is a polymorphic "hasMany" relation, so it requires the target relation %v to be a polymorphic too.',
  35396. relationName,
  35397. sourceName,
  35398. targetRelationName
  35399. );
  35400. const foreignKey = targetRelationDef.foreignKey || `${targetRelationName}Id`;
  35401. const discriminator = targetRelationDef.discriminator || `${targetRelationName}Type`;
  35402. return this.includePolymorphicTo(
  35403. entities,
  35404. sourceName,
  35405. targetName,
  35406. relationName,
  35407. foreignKey,
  35408. discriminator,
  35409. scope
  35410. );
  35411. }
  35412. };
  35413. }
  35414. });
  35415. // node_modules/@e22m4u/js-repository/src/relations/belongs-to-resolver.js
  35416. var BelongsToResolver;
  35417. var init_belongs_to_resolver = __esm({
  35418. "node_modules/@e22m4u/js-repository/src/relations/belongs-to-resolver.js"() {
  35419. init_src2();
  35420. init_utils2();
  35421. init_utils2();
  35422. init_errors2();
  35423. init_repository2();
  35424. init_definition();
  35425. BelongsToResolver = class extends Service {
  35426. /**
  35427. * Include to.
  35428. *
  35429. * @param {object[]} entities
  35430. * @param {string} sourceName
  35431. * @param {string} targetName
  35432. * @param {string} relationName
  35433. * @param {string|undefined} foreignKey
  35434. * @param {object|undefined} scope
  35435. * @returns {Promise<void>}
  35436. */
  35437. async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
  35438. if (!entities || !Array.isArray(entities))
  35439. throw new InvalidArgumentError2(
  35440. 'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v given.',
  35441. entities
  35442. );
  35443. if (!sourceName || typeof sourceName !== "string")
  35444. throw new InvalidArgumentError2(
  35445. 'The parameter "sourceName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35446. sourceName
  35447. );
  35448. if (!targetName || typeof targetName !== "string")
  35449. throw new InvalidArgumentError2(
  35450. 'The parameter "targetName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35451. targetName
  35452. );
  35453. if (!relationName || typeof relationName !== "string")
  35454. throw new InvalidArgumentError2(
  35455. 'The parameter "relationName" of BelongsToResolver.includeTo requires a non-empty String, but %v given.',
  35456. relationName
  35457. );
  35458. if (foreignKey && typeof foreignKey !== "string")
  35459. throw new InvalidArgumentError2(
  35460. 'The provided parameter "foreignKey" of BelongsToResolver.includeTo should be a String, but %v given.',
  35461. foreignKey
  35462. );
  35463. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35464. throw new InvalidArgumentError2(
  35465. 'The provided parameter "scope" of BelongsToResolver.includeTo should be an Object, but %v given.',
  35466. scope
  35467. );
  35468. if (foreignKey == null) foreignKey = `${relationName}Id`;
  35469. const targetIds = entities.reduce((acc, entity) => {
  35470. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35471. throw new InvalidArgumentError2(
  35472. 'The parameter "entities" of BelongsToResolver.includeTo requires an Array of Object, but %v given.',
  35473. entity
  35474. );
  35475. const targetId = entity[foreignKey];
  35476. return targetId != null ? [...acc, targetId] : acc;
  35477. }, []);
  35478. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35479. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35480. targetName
  35481. );
  35482. scope = scope ? cloneDeep(scope) : {};
  35483. const filter = cloneDeep(scope);
  35484. filter.where = {
  35485. and: [
  35486. { [targetPkPropName]: { inq: targetIds } },
  35487. ...scope.where ? [scope.where] : []
  35488. ]
  35489. };
  35490. const targets = await targetRepository.find(filter);
  35491. entities.forEach((entity) => {
  35492. const target = targets.find(
  35493. (e) => e[targetPkPropName] === entity[foreignKey]
  35494. );
  35495. if (target) entity[relationName] = target;
  35496. });
  35497. }
  35498. /**
  35499. * Include polymorphic to.
  35500. *
  35501. * @param {object[]} entities
  35502. * @param {string} sourceName
  35503. * @param {string} relationName
  35504. * @param {string|undefined} foreignKey
  35505. * @param {string|undefined} discriminator
  35506. * @param {object|undefined} scope
  35507. * @returns {Promise<void>}
  35508. */
  35509. async includePolymorphicTo(entities, sourceName, relationName, foreignKey = void 0, discriminator = void 0, scope = void 0) {
  35510. if (!entities || !Array.isArray(entities))
  35511. throw new InvalidArgumentError2(
  35512. 'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35513. entities
  35514. );
  35515. if (!sourceName || typeof sourceName !== "string")
  35516. throw new InvalidArgumentError2(
  35517. 'The parameter "sourceName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35518. sourceName
  35519. );
  35520. if (!relationName || typeof relationName !== "string")
  35521. throw new InvalidArgumentError2(
  35522. 'The parameter "relationName" of BelongsToResolver.includePolymorphicTo requires a non-empty String, but %v given.',
  35523. relationName
  35524. );
  35525. if (foreignKey && typeof foreignKey !== "string")
  35526. throw new InvalidArgumentError2(
  35527. 'The provided parameter "foreignKey" of BelongsToResolver.includePolymorphicTo should be a String, but %v given.',
  35528. foreignKey
  35529. );
  35530. if (discriminator && typeof discriminator !== "string")
  35531. throw new InvalidArgumentError2(
  35532. 'The provided parameter "discriminator" of BelongsToResolver.includePolymorphicTo should be a String, but %v given.',
  35533. discriminator
  35534. );
  35535. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35536. throw new InvalidArgumentError2(
  35537. 'The provided parameter "scope" of BelongsToResolver.includePolymorphicTo should be an Object, but %v given.',
  35538. scope
  35539. );
  35540. if (foreignKey == null) {
  35541. const singularRelationName = singularize(relationName);
  35542. foreignKey = `${singularRelationName}Id`;
  35543. }
  35544. if (discriminator == null) {
  35545. const singularRelationName = singularize(relationName);
  35546. discriminator = `${singularRelationName}Type`;
  35547. }
  35548. const targetIdsByTargetName = {};
  35549. entities.forEach((entity) => {
  35550. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35551. throw new InvalidArgumentError2(
  35552. 'The parameter "entities" of BelongsToResolver.includePolymorphicTo requires an Array of Object, but %v given.',
  35553. entity
  35554. );
  35555. const targetId = entity[foreignKey];
  35556. const targetName = entity[discriminator];
  35557. if (targetId == null || targetName == null) return;
  35558. if (targetIdsByTargetName[targetName] == null)
  35559. targetIdsByTargetName[targetName] = [];
  35560. if (!targetIdsByTargetName[targetName].includes(targetId))
  35561. targetIdsByTargetName[targetName].push(targetId);
  35562. });
  35563. const promises = [];
  35564. const targetNames = Object.keys(targetIdsByTargetName);
  35565. scope = scope ? cloneDeep(scope) : {};
  35566. const targetEntitiesByTargetNames = {};
  35567. targetNames.forEach((targetName) => {
  35568. let targetRepository;
  35569. try {
  35570. targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35571. } catch (error) {
  35572. if (error instanceof InvalidArgumentError2) {
  35573. if (error.message === `The model "${targetName}" is not defined.` || error.message === `The model "${targetName}" does not have a specified datasource.`) {
  35574. return;
  35575. }
  35576. } else {
  35577. throw error;
  35578. }
  35579. }
  35580. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35581. targetName
  35582. );
  35583. const targetFilter = cloneDeep(scope);
  35584. const targetIds = targetIdsByTargetName[targetName];
  35585. targetFilter.where = {
  35586. and: [
  35587. { [targetPkPropName]: { inq: targetIds } },
  35588. ...scope.where ? [scope.where] : []
  35589. ]
  35590. };
  35591. const promise = targetRepository.find(targetFilter).then((result) => {
  35592. targetEntitiesByTargetNames[targetName] = [
  35593. ...targetEntitiesByTargetNames[targetName] ?? [],
  35594. ...result
  35595. ];
  35596. });
  35597. promises.push(promise);
  35598. });
  35599. await Promise.all(promises);
  35600. entities.forEach((entity) => {
  35601. const targetId = entity[foreignKey];
  35602. const targetName = entity[discriminator];
  35603. if (targetId == null || targetName == null || targetEntitiesByTargetNames[targetName] == null) {
  35604. return;
  35605. }
  35606. const targetEntities = targetEntitiesByTargetNames[targetName] ?? [];
  35607. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35608. targetName
  35609. );
  35610. const target = targetEntities.find((e) => e[targetPkPropName] === targetId);
  35611. if (target) entity[relationName] = target;
  35612. });
  35613. }
  35614. };
  35615. }
  35616. });
  35617. // node_modules/@e22m4u/js-repository/src/relations/references-many-resolver.js
  35618. var ReferencesManyResolver;
  35619. var init_references_many_resolver = __esm({
  35620. "node_modules/@e22m4u/js-repository/src/relations/references-many-resolver.js"() {
  35621. init_src2();
  35622. init_utils2();
  35623. init_utils2();
  35624. init_errors2();
  35625. init_repository2();
  35626. init_definition();
  35627. ReferencesManyResolver = class extends Service {
  35628. /**
  35629. * Include to.
  35630. *
  35631. * @param {object[]} entities
  35632. * @param {string} sourceName
  35633. * @param {string} targetName
  35634. * @param {string} relationName
  35635. * @param {string|undefined} foreignKey
  35636. * @param {object|undefined} scope
  35637. * @returns {Promise<void>}
  35638. */
  35639. async includeTo(entities, sourceName, targetName, relationName, foreignKey = void 0, scope = void 0) {
  35640. if (!entities || !Array.isArray(entities))
  35641. throw new InvalidArgumentError2(
  35642. 'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v given.',
  35643. entities
  35644. );
  35645. if (!sourceName || typeof sourceName !== "string")
  35646. throw new InvalidArgumentError2(
  35647. 'The parameter "sourceName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35648. sourceName
  35649. );
  35650. if (!targetName || typeof targetName !== "string")
  35651. throw new InvalidArgumentError2(
  35652. 'The parameter "targetName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35653. targetName
  35654. );
  35655. if (!relationName || typeof relationName !== "string")
  35656. throw new InvalidArgumentError2(
  35657. 'The parameter "relationName" of ReferencesManyResolver.includeTo requires a non-empty String, but %v given.',
  35658. relationName
  35659. );
  35660. if (foreignKey && typeof foreignKey !== "string")
  35661. throw new InvalidArgumentError2(
  35662. 'The provided parameter "foreignKey" of ReferencesManyResolver.includeTo should be a String, but %v given.',
  35663. foreignKey
  35664. );
  35665. if (scope && (typeof scope !== "object" || Array.isArray(scope)))
  35666. throw new InvalidArgumentError2(
  35667. 'The provided parameter "scope" of ReferencesManyResolver.includeTo should be an Object, but %v given.',
  35668. scope
  35669. );
  35670. if (foreignKey == null) {
  35671. const singularRelationName = singularize(relationName);
  35672. foreignKey = `${singularRelationName}Ids`;
  35673. }
  35674. const targetIds = entities.reduce((acc, entity) => {
  35675. if (!entity || typeof entity !== "object" || Array.isArray(entity))
  35676. throw new InvalidArgumentError2(
  35677. 'The parameter "entities" of ReferencesManyResolver.includeTo requires an Array of Object, but %v given.',
  35678. entity
  35679. );
  35680. const ids = entity[foreignKey];
  35681. if (Array.isArray(ids))
  35682. ids.forEach((id) => {
  35683. if (id == null || acc.includes(id)) return;
  35684. acc.push(id);
  35685. });
  35686. return acc;
  35687. }, []);
  35688. const targetRepository = this.getService(RepositoryRegistry).getRepository(targetName);
  35689. const targetPkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  35690. targetName
  35691. );
  35692. scope = scope ? cloneDeep(scope) : {};
  35693. const filter = cloneDeep(scope);
  35694. filter.where = {
  35695. and: [
  35696. { [targetPkPropName]: { inq: targetIds } },
  35697. ...scope.where ? [scope.where] : []
  35698. ]
  35699. };
  35700. const targets = await targetRepository.find(filter);
  35701. entities.forEach((entity) => {
  35702. const ids = entity[foreignKey];
  35703. entity[relationName] = [];
  35704. if (Array.isArray(ids))
  35705. targets.forEach((target) => {
  35706. const targetId = target[targetPkPropName];
  35707. if (ids.includes(targetId)) entity[relationName].push(target);
  35708. });
  35709. });
  35710. }
  35711. };
  35712. }
  35713. });
  35714. // node_modules/@e22m4u/js-repository/src/relations/index.js
  35715. var init_relations2 = __esm({
  35716. "node_modules/@e22m4u/js-repository/src/relations/index.js"() {
  35717. init_has_one_resolver();
  35718. init_has_many_resolver();
  35719. init_belongs_to_resolver();
  35720. init_references_many_resolver();
  35721. }
  35722. });
  35723. // node_modules/@e22m4u/js-repository/src/filter/include-clause-tool.js
  35724. var IncludeClauseTool;
  35725. var init_include_clause_tool = __esm({
  35726. "node_modules/@e22m4u/js-repository/src/filter/include-clause-tool.js"() {
  35727. init_src2();
  35728. init_definition();
  35729. init_relations2();
  35730. init_relations2();
  35731. init_where_clause_tool();
  35732. init_order_clause_tool();
  35733. init_slice_clause_tool();
  35734. init_errors2();
  35735. init_relations2();
  35736. init_fields_clause_tool();
  35737. init_definition();
  35738. init_relations2();
  35739. IncludeClauseTool = class _IncludeClauseTool extends Service {
  35740. /**
  35741. * Include to.
  35742. *
  35743. * @param {object[]} entities
  35744. * @param {string} modelName
  35745. * @param {IncludeClause|undefined} clause
  35746. * @returns {Promise<void>}
  35747. */
  35748. async includeTo(entities, modelName, clause) {
  35749. clause = _IncludeClauseTool.normalizeIncludeClause(clause);
  35750. const promises = [];
  35751. clause.forEach((inclusion) => {
  35752. const relDef = this.getService(
  35753. ModelDefinitionUtils
  35754. ).getRelationDefinitionByName(modelName, inclusion.relation);
  35755. switch (relDef.type) {
  35756. // BELONGS_TO
  35757. case RelationType.BELONGS_TO:
  35758. if (relDef.polymorphic) {
  35759. promises.push(
  35760. this.getService(BelongsToResolver).includePolymorphicTo(
  35761. entities,
  35762. modelName,
  35763. inclusion.relation,
  35764. relDef.foreignKey,
  35765. relDef.discriminator,
  35766. inclusion.scope
  35767. )
  35768. );
  35769. } else {
  35770. promises.push(
  35771. this.getService(BelongsToResolver).includeTo(
  35772. entities,
  35773. modelName,
  35774. relDef.model,
  35775. inclusion.relation,
  35776. relDef.foreignKey,
  35777. inclusion.scope
  35778. )
  35779. );
  35780. }
  35781. break;
  35782. // HAS_ONE
  35783. case RelationType.HAS_ONE:
  35784. if (relDef.polymorphic && typeof relDef.polymorphic === "string") {
  35785. promises.push(
  35786. this.getService(HasOneResolver).includePolymorphicByRelationName(
  35787. entities,
  35788. modelName,
  35789. relDef.model,
  35790. inclusion.relation,
  35791. relDef.polymorphic,
  35792. inclusion.scope
  35793. )
  35794. );
  35795. } else if (relDef.polymorphic) {
  35796. promises.push(
  35797. this.getService(HasOneResolver).includePolymorphicTo(
  35798. entities,
  35799. modelName,
  35800. relDef.model,
  35801. inclusion.relation,
  35802. relDef.foreignKey,
  35803. relDef.discriminator,
  35804. inclusion.scope
  35805. )
  35806. );
  35807. } else {
  35808. promises.push(
  35809. this.getService(HasOneResolver).includeTo(
  35810. entities,
  35811. modelName,
  35812. relDef.model,
  35813. inclusion.relation,
  35814. relDef.foreignKey,
  35815. inclusion.scope
  35816. )
  35817. );
  35818. }
  35819. break;
  35820. // HAS_MANY
  35821. case RelationType.HAS_MANY:
  35822. if (relDef.polymorphic && typeof relDef.polymorphic === "string") {
  35823. promises.push(
  35824. this.getService(HasManyResolver).includePolymorphicByRelationName(
  35825. entities,
  35826. modelName,
  35827. relDef.model,
  35828. inclusion.relation,
  35829. relDef.polymorphic,
  35830. inclusion.scope
  35831. )
  35832. );
  35833. } else if (relDef.polymorphic) {
  35834. promises.push(
  35835. this.getService(HasManyResolver).includePolymorphicTo(
  35836. entities,
  35837. modelName,
  35838. relDef.model,
  35839. inclusion.relation,
  35840. relDef.foreignKey,
  35841. relDef.discriminator,
  35842. inclusion.scope
  35843. )
  35844. );
  35845. } else {
  35846. promises.push(
  35847. this.getService(HasManyResolver).includeTo(
  35848. entities,
  35849. modelName,
  35850. relDef.model,
  35851. inclusion.relation,
  35852. relDef.foreignKey,
  35853. inclusion.scope
  35854. )
  35855. );
  35856. }
  35857. break;
  35858. case RelationType.REFERENCES_MANY:
  35859. promises.push(
  35860. this.getService(ReferencesManyResolver).includeTo(
  35861. entities,
  35862. modelName,
  35863. relDef.model,
  35864. inclusion.relation,
  35865. relDef.foreignKey,
  35866. inclusion.scope
  35867. )
  35868. );
  35869. break;
  35870. default:
  35871. throw new InvalidArgumentError2(
  35872. "The relation type %v does not have an inclusion resolver.",
  35873. relDef.type
  35874. );
  35875. }
  35876. });
  35877. await Promise.all(promises);
  35878. }
  35879. /**
  35880. * Validate include clause.
  35881. *
  35882. * @param {IncludeClause|undefined} clause
  35883. */
  35884. static validateIncludeClause(clause) {
  35885. if (clause == null) {
  35886. } else if (clause && typeof clause === "string") {
  35887. } else if (Array.isArray(clause)) {
  35888. const relNames = [];
  35889. clause.flat(Infinity).forEach((el) => {
  35890. this.validateIncludeClause(el);
  35891. if (typeof el === "string") {
  35892. relNames.push(el);
  35893. } else if (typeof el === "object") {
  35894. Object.keys(el).forEach((key) => {
  35895. if (Object.prototype.hasOwnProperty.call(el, key))
  35896. relNames.push(key);
  35897. });
  35898. }
  35899. });
  35900. const duplicateNames = relNames.filter(
  35901. (name, i) => relNames.indexOf(name) !== i
  35902. );
  35903. if (duplicateNames.length)
  35904. throw new InvalidArgumentError2(
  35905. 'The provided option "include" has duplicates of %v.',
  35906. duplicateNames[0]
  35907. );
  35908. } else if (typeof clause === "object") {
  35909. if ("relation" in clause) {
  35910. if (!clause.relation || typeof clause.relation !== "string")
  35911. throw new InvalidArgumentError2(
  35912. 'The provided option "relation" should be a non-empty String, but %v given.',
  35913. clause.relation
  35914. );
  35915. if ("scope" in clause && clause) this.validateScopeClause(clause.scope);
  35916. } else {
  35917. Object.keys(clause).forEach((key) => {
  35918. if (!Object.prototype.hasOwnProperty.call(clause, key)) return;
  35919. this.validateIncludeClause(key);
  35920. this.validateIncludeClause(clause[key]);
  35921. });
  35922. }
  35923. } else {
  35924. throw new InvalidArgumentError2(
  35925. 'The provided option "include" should have a non-empty String, an Object or an Array, but %v given.',
  35926. clause
  35927. );
  35928. }
  35929. }
  35930. /**
  35931. * Validate scope clause.
  35932. *
  35933. * @param {object|undefined} clause
  35934. */
  35935. static validateScopeClause(clause) {
  35936. if (clause == null) return;
  35937. if (typeof clause !== "object" || Array.isArray(clause))
  35938. throw new InvalidArgumentError2(
  35939. 'The provided option "scope" should be an Object, but %v given.',
  35940. clause
  35941. );
  35942. if (clause.where != null) {
  35943. WhereClauseTool.validateWhereClause(clause.where);
  35944. }
  35945. if (clause.order != null) {
  35946. OrderClauseTool.validateOrderClause(clause.order);
  35947. }
  35948. if (clause.skip != null) {
  35949. SliceClauseTool.validateSkipClause(clause.skip);
  35950. }
  35951. if (clause.limit != null) {
  35952. SliceClauseTool.validateLimitClause(clause.limit);
  35953. }
  35954. if (clause.fields != null) {
  35955. FieldsClauseTool.validateFieldsClause(clause.fields);
  35956. }
  35957. if (clause.include != null) {
  35958. _IncludeClauseTool.validateIncludeClause(clause.include);
  35959. }
  35960. }
  35961. /**
  35962. * Normalize include clause.
  35963. *
  35964. * @param {IncludeClause|undefined} clause
  35965. * @returns {object[]}
  35966. */
  35967. static normalizeIncludeClause(clause) {
  35968. let result = [];
  35969. if (clause == null) {
  35970. return result;
  35971. } else if (clause && typeof clause === "string") {
  35972. result.push({ relation: clause });
  35973. } else if (Array.isArray(clause)) {
  35974. clause.flat(Infinity).forEach((el) => {
  35975. el = this.normalizeIncludeClause(el);
  35976. result = [...result, ...el];
  35977. });
  35978. const relNames = result.map((v) => v.relation);
  35979. const duplicateNames = relNames.filter(
  35980. (name, i) => relNames.indexOf(name) !== i
  35981. );
  35982. if (duplicateNames.length)
  35983. throw new InvalidArgumentError2(
  35984. 'The provided option "include" has duplicates of %v.',
  35985. duplicateNames[0]
  35986. );
  35987. } else if (typeof clause === "object") {
  35988. if ("relation" in clause) {
  35989. if (!clause.relation || typeof clause.relation !== "string")
  35990. throw new InvalidArgumentError2(
  35991. 'The provided option "relation" should be a non-empty String, but %v given.',
  35992. clause.relation
  35993. );
  35994. const normalized = { relation: clause.relation };
  35995. const scope = this.normalizeScopeClause(clause.scope);
  35996. if (scope) normalized.scope = scope;
  35997. result.push(normalized);
  35998. } else {
  35999. Object.keys(clause).forEach((key) => {
  36000. if (!Object.prototype.hasOwnProperty.call(clause, key)) return;
  36001. this.validateIncludeClause(key);
  36002. const normalized = { relation: key };
  36003. const include = this.normalizeIncludeClause(clause[key]);
  36004. if (include.length) normalized.scope = { include };
  36005. result.push(normalized);
  36006. });
  36007. }
  36008. } else {
  36009. throw new InvalidArgumentError2(
  36010. 'The provided option "include" should have a non-empty String, an Object or an Array, but %v given.',
  36011. clause
  36012. );
  36013. }
  36014. return result;
  36015. }
  36016. /**
  36017. * Normalize scope clause.
  36018. *
  36019. * @param {object|undefined} clause
  36020. * @returns {object|undefined}
  36021. */
  36022. static normalizeScopeClause(clause) {
  36023. if (clause == null) return;
  36024. if (typeof clause !== "object" || Array.isArray(clause))
  36025. throw new InvalidArgumentError2(
  36026. 'The provided option "scope" should be an Object, but %v given.',
  36027. clause
  36028. );
  36029. const result = {};
  36030. if (clause.where != null) {
  36031. WhereClauseTool.validateWhereClause(clause.where);
  36032. result.where = clause.where;
  36033. }
  36034. if (clause.order != null) {
  36035. OrderClauseTool.validateOrderClause(clause.order);
  36036. result.order = clause.order;
  36037. }
  36038. if (clause.skip != null) {
  36039. SliceClauseTool.validateSkipClause(clause.skip);
  36040. result.skip = clause.skip;
  36041. }
  36042. if (clause.limit != null) {
  36043. SliceClauseTool.validateLimitClause(clause.limit);
  36044. result.limit = clause.limit;
  36045. }
  36046. if (clause.fields != null) {
  36047. FieldsClauseTool.validateFieldsClause(clause.fields);
  36048. result.fields = clause.fields;
  36049. }
  36050. if (clause.include != null) {
  36051. result.include = this.normalizeIncludeClause(clause.include);
  36052. }
  36053. if (Object.keys(result).length) return result;
  36054. return void 0;
  36055. }
  36056. };
  36057. }
  36058. });
  36059. // node_modules/@e22m4u/js-repository/src/filter/index.js
  36060. var init_filter = __esm({
  36061. "node_modules/@e22m4u/js-repository/src/filter/index.js"() {
  36062. init_slice_clause_tool();
  36063. init_order_clause_tool();
  36064. init_where_clause_tool();
  36065. init_fields_clause_tool();
  36066. init_include_clause_tool();
  36067. init_operator_clause_tool();
  36068. }
  36069. });
  36070. // node_modules/@e22m4u/js-repository/src/adapter/decorator/inclusion-decorator.js
  36071. var InclusionDecorator;
  36072. var init_inclusion_decorator = __esm({
  36073. "node_modules/@e22m4u/js-repository/src/adapter/decorator/inclusion-decorator.js"() {
  36074. init_adapter();
  36075. init_src2();
  36076. init_filter();
  36077. init_errors2();
  36078. InclusionDecorator = class extends Service {
  36079. /**
  36080. * Decorate.
  36081. *
  36082. * @param {Adapter} adapter
  36083. */
  36084. decorate(adapter) {
  36085. if (!adapter || !(adapter instanceof Adapter))
  36086. throw new InvalidArgumentError2(
  36087. "The first argument of InclusionDecorator.decorate should be an Adapter instance, but %v given.",
  36088. adapter
  36089. );
  36090. const tool = adapter.getService(IncludeClauseTool);
  36091. const includeTo = (...args) => tool.includeTo(...args);
  36092. const create = adapter.create;
  36093. adapter.create = async function(modelName, modelData, filter) {
  36094. const retvalData = await create.call(this, modelName, modelData, filter);
  36095. if (filter && typeof filter === "object" && filter.include)
  36096. await includeTo([retvalData], modelName, filter.include);
  36097. return retvalData;
  36098. };
  36099. const replaceById = adapter.replaceById;
  36100. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36101. const retvalData = await replaceById.call(
  36102. this,
  36103. modelName,
  36104. id,
  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 replaceOrCreate = adapter.replaceOrCreate;
  36113. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36114. const retvalData = await replaceOrCreate.call(
  36115. this,
  36116. modelName,
  36117. modelData,
  36118. filter
  36119. );
  36120. if (filter && typeof filter === "object" && filter.include)
  36121. await includeTo([retvalData], modelName, filter.include);
  36122. return retvalData;
  36123. };
  36124. const patchById = adapter.patchById;
  36125. adapter.patchById = async function(modelName, id, modelData, filter) {
  36126. const retvalData = await patchById.call(
  36127. this,
  36128. modelName,
  36129. id,
  36130. modelData,
  36131. filter
  36132. );
  36133. if (filter && typeof filter === "object" && filter.include)
  36134. await includeTo([retvalData], modelName, filter.include);
  36135. return retvalData;
  36136. };
  36137. const find = adapter.find;
  36138. adapter.find = async function(modelName, filter) {
  36139. const modelItems = await find.call(this, modelName, filter);
  36140. if (filter && typeof filter === "object" && filter.include)
  36141. await includeTo(modelItems, modelName, filter.include);
  36142. return modelItems;
  36143. };
  36144. const findById = adapter.findById;
  36145. adapter.findById = async function(modelName, id, filter) {
  36146. const retvalData = await findById.call(this, modelName, id, filter);
  36147. if (filter && typeof filter === "object" && filter.include)
  36148. await includeTo([retvalData], modelName, filter.include);
  36149. return retvalData;
  36150. };
  36151. }
  36152. };
  36153. }
  36154. });
  36155. // node_modules/@e22m4u/js-repository/src/adapter/decorator/default-values-decorator.js
  36156. var DefaultValuesDecorator;
  36157. var init_default_values_decorator = __esm({
  36158. "node_modules/@e22m4u/js-repository/src/adapter/decorator/default-values-decorator.js"() {
  36159. init_adapter();
  36160. init_src2();
  36161. init_errors2();
  36162. init_definition();
  36163. DefaultValuesDecorator = class extends Service {
  36164. /**
  36165. * Decorate.
  36166. *
  36167. * @param {Adapter} adapter
  36168. */
  36169. decorate(adapter) {
  36170. if (!adapter || !(adapter instanceof Adapter))
  36171. throw new InvalidArgumentError2(
  36172. "The first argument of DefaultValuesDecorator.decorate should be an Adapter instance, but %v given.",
  36173. adapter
  36174. );
  36175. const utils = adapter.getService(ModelDefinitionUtils);
  36176. const setDefaults = (...args) => utils.setDefaultValuesToEmptyProperties(...args);
  36177. const create = adapter.create;
  36178. adapter.create = function(modelName, modelData, filter) {
  36179. modelData = setDefaults(modelName, modelData);
  36180. return create.call(this, modelName, modelData, filter);
  36181. };
  36182. const replaceById = adapter.replaceById;
  36183. adapter.replaceById = function(modelName, id, modelData, filter) {
  36184. modelData = setDefaults(modelName, modelData);
  36185. return replaceById.call(this, modelName, id, modelData, filter);
  36186. };
  36187. const replaceOrCreate = adapter.replaceOrCreate;
  36188. adapter.replaceOrCreate = function(modelName, modelData, filter) {
  36189. modelData = setDefaults(modelName, modelData);
  36190. return replaceOrCreate.call(this, modelName, modelData, filter);
  36191. };
  36192. const patch = adapter.patch;
  36193. adapter.patch = function(modelName, modelData, where) {
  36194. modelData = setDefaults(modelName, modelData, true);
  36195. return patch.call(this, modelName, modelData, where);
  36196. };
  36197. const patchById = adapter.patchById;
  36198. adapter.patchById = function(modelName, id, modelData, filter) {
  36199. modelData = setDefaults(modelName, modelData, true);
  36200. return patchById.call(this, modelName, id, modelData, filter);
  36201. };
  36202. const find = adapter.find;
  36203. adapter.find = async function(modelName, filter) {
  36204. const modelItems = await find.call(this, modelName, filter);
  36205. return modelItems.map((modelItem) => setDefaults(modelName, modelItem));
  36206. };
  36207. const findById = adapter.findById;
  36208. adapter.findById = async function(modelName, id, filter) {
  36209. const retvalData = await findById.call(this, modelName, id, filter);
  36210. return setDefaults(modelName, retvalData);
  36211. };
  36212. }
  36213. };
  36214. }
  36215. });
  36216. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-sanitizing-decorator.js
  36217. var DataSanitizingDecorator;
  36218. var init_data_sanitizing_decorator = __esm({
  36219. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-sanitizing-decorator.js"() {
  36220. init_adapter();
  36221. init_src2();
  36222. init_errors2();
  36223. init_definition();
  36224. DataSanitizingDecorator = class extends Service {
  36225. /**
  36226. * Decorate.
  36227. *
  36228. * @param {Adapter} adapter
  36229. */
  36230. decorate(adapter) {
  36231. if (!adapter || !(adapter instanceof Adapter))
  36232. throw new InvalidArgumentError2(
  36233. "The first argument of DataSanitizingDecorator.decorate should be an Adapter instance, but %v given.",
  36234. adapter
  36235. );
  36236. const sanitizer = adapter.getService(ModelDataSanitizer);
  36237. const sanitize = (...args) => sanitizer.sanitize(...args);
  36238. const create = adapter.create;
  36239. adapter.create = async function(modelName, modelData, filter) {
  36240. modelData = sanitize(modelName, modelData);
  36241. return create.call(this, modelName, modelData, filter);
  36242. };
  36243. const replaceById = adapter.replaceById;
  36244. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36245. modelData = sanitize(modelName, modelData);
  36246. return replaceById.call(this, modelName, id, modelData, filter);
  36247. };
  36248. const replaceOrCreate = adapter.replaceOrCreate;
  36249. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36250. modelData = sanitize(modelName, modelData);
  36251. return replaceOrCreate.call(this, modelName, modelData, filter);
  36252. };
  36253. const patch = adapter.patch;
  36254. adapter.patch = async function(modelName, modelData, where) {
  36255. modelData = sanitize(modelName, modelData);
  36256. return patch.call(this, modelName, modelData, where);
  36257. };
  36258. const patchById = adapter.patchById;
  36259. adapter.patchById = async function(modelName, id, modelData, filter) {
  36260. modelData = sanitize(modelName, modelData);
  36261. return patchById.call(this, modelName, id, modelData, filter);
  36262. };
  36263. }
  36264. };
  36265. }
  36266. });
  36267. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-validation-decorator.js
  36268. var DataValidationDecorator;
  36269. var init_data_validation_decorator = __esm({
  36270. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-validation-decorator.js"() {
  36271. init_adapter();
  36272. init_src2();
  36273. init_errors2();
  36274. init_definition();
  36275. DataValidationDecorator = class extends Service {
  36276. /**
  36277. * Decorate.
  36278. *
  36279. * @param {Adapter} adapter
  36280. */
  36281. decorate(adapter) {
  36282. if (!adapter || !(adapter instanceof Adapter))
  36283. throw new InvalidArgumentError2(
  36284. "The first argument of DataValidationDecorator.decorate should be an Adapter instance, but %v given.",
  36285. adapter
  36286. );
  36287. const validator = this.getService(ModelDataValidator);
  36288. const create = adapter.create;
  36289. adapter.create = function(modelName, modelData, filter) {
  36290. validator.validate(modelName, modelData);
  36291. return create.call(this, modelName, modelData, filter);
  36292. };
  36293. const replaceById = adapter.replaceById;
  36294. adapter.replaceById = function(modelName, id, modelData, filter) {
  36295. validator.validate(modelName, modelData);
  36296. return replaceById.call(this, modelName, id, modelData, filter);
  36297. };
  36298. const replaceOrCreate = adapter.replaceOrCreate;
  36299. adapter.replaceOrCreate = function(modelName, modelData, filter) {
  36300. validator.validate(modelName, modelData);
  36301. return replaceOrCreate.call(this, modelName, modelData, filter);
  36302. };
  36303. const patch = adapter.patch;
  36304. adapter.patch = function(modelName, modelData, where) {
  36305. validator.validate(modelName, modelData, true);
  36306. return patch.call(this, modelName, modelData, where);
  36307. };
  36308. const patchById = adapter.patchById;
  36309. adapter.patchById = function(modelName, id, modelData, filter) {
  36310. validator.validate(modelName, modelData, true);
  36311. return patchById.call(this, modelName, id, modelData, filter);
  36312. };
  36313. }
  36314. };
  36315. }
  36316. });
  36317. // node_modules/@e22m4u/js-repository/src/adapter/decorator/fields-filtering-decorator.js
  36318. var FieldsFilteringDecorator;
  36319. var init_fields_filtering_decorator = __esm({
  36320. "node_modules/@e22m4u/js-repository/src/adapter/decorator/fields-filtering-decorator.js"() {
  36321. init_adapter();
  36322. init_src2();
  36323. init_filter();
  36324. init_errors2();
  36325. FieldsFilteringDecorator = class extends Service {
  36326. /**
  36327. * Decorate.
  36328. *
  36329. * @param {Adapter} adapter
  36330. */
  36331. decorate(adapter) {
  36332. if (!adapter || !(adapter instanceof Adapter))
  36333. throw new InvalidArgumentError2(
  36334. "The first argument of FieldsFilteringDecorator.decorate should be an Adapter instance, but %v given.",
  36335. adapter
  36336. );
  36337. const tool = adapter.getService(FieldsClauseTool);
  36338. const selectFields = (...args) => tool.filter(...args);
  36339. const create = adapter.create;
  36340. adapter.create = async function(modelName, modelData, filter) {
  36341. let result = await create.call(this, modelName, modelData, filter);
  36342. if (filter && typeof filter === "object" && filter.fields)
  36343. result = selectFields(result, modelName, filter.fields);
  36344. return result;
  36345. };
  36346. const replaceById = adapter.replaceById;
  36347. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36348. let result = await replaceById.call(
  36349. this,
  36350. modelName,
  36351. id,
  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 replaceOrCreate = adapter.replaceOrCreate;
  36360. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36361. let result = await replaceOrCreate.call(
  36362. this,
  36363. modelName,
  36364. modelData,
  36365. filter
  36366. );
  36367. if (filter && typeof filter === "object" && filter.fields)
  36368. result = selectFields(result, modelName, filter.fields);
  36369. return result;
  36370. };
  36371. const patchById = adapter.patchById;
  36372. adapter.patchById = async function(modelName, id, modelData, filter) {
  36373. let result = await patchById.call(this, modelName, id, modelData, filter);
  36374. if (filter && typeof filter === "object" && filter.fields)
  36375. result = selectFields(result, modelName, filter.fields);
  36376. return result;
  36377. };
  36378. const find = adapter.find;
  36379. adapter.find = async function(modelName, filter) {
  36380. let result = await find.call(this, modelName, filter);
  36381. if (filter && typeof filter === "object" && filter.fields)
  36382. result = selectFields(result, modelName, filter.fields);
  36383. return result;
  36384. };
  36385. const findById = adapter.findById;
  36386. adapter.findById = async function(modelName, id, filter) {
  36387. let result = await findById.call(this, modelName, id, filter);
  36388. if (filter && typeof filter === "object" && filter.fields)
  36389. result = selectFields(result, modelName, filter.fields);
  36390. return result;
  36391. };
  36392. }
  36393. };
  36394. }
  36395. });
  36396. // node_modules/@e22m4u/js-repository/src/adapter/decorator/data-transformation-decorator.js
  36397. var DataTransformationDecorator;
  36398. var init_data_transformation_decorator = __esm({
  36399. "node_modules/@e22m4u/js-repository/src/adapter/decorator/data-transformation-decorator.js"() {
  36400. init_adapter();
  36401. init_src2();
  36402. init_errors2();
  36403. init_definition();
  36404. DataTransformationDecorator = class extends Service {
  36405. /**
  36406. * Decorate.
  36407. *
  36408. * @param {Adapter} adapter
  36409. */
  36410. decorate(adapter) {
  36411. if (!adapter || !(adapter instanceof Adapter))
  36412. throw new InvalidArgumentError2(
  36413. "The first argument of DataTransformerDecorator.decorate should be an Adapter instance, but %v given.",
  36414. adapter
  36415. );
  36416. const transformer = this.getService(ModelDataTransformer);
  36417. const create = adapter.create;
  36418. adapter.create = async function(modelName, modelData, filter) {
  36419. modelData = await transformer.transform(modelName, modelData);
  36420. return create.call(this, modelName, modelData, filter);
  36421. };
  36422. const replaceById = adapter.replaceById;
  36423. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36424. modelData = await transformer.transform(modelName, modelData);
  36425. return replaceById.call(this, modelName, id, modelData, filter);
  36426. };
  36427. const replaceOrCreate = adapter.replaceOrCreate;
  36428. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36429. modelData = await transformer.transform(modelName, modelData);
  36430. return replaceOrCreate.call(this, modelName, modelData, filter);
  36431. };
  36432. const patch = adapter.patch;
  36433. adapter.patch = async function(modelName, modelData, where) {
  36434. modelData = await transformer.transform(modelName, modelData, true);
  36435. return patch.call(this, modelName, modelData, where);
  36436. };
  36437. const patchById = adapter.patchById;
  36438. adapter.patchById = async function(modelName, id, modelData, filter) {
  36439. modelData = await transformer.transform(modelName, modelData, true);
  36440. return patchById.call(this, modelName, id, modelData, filter);
  36441. };
  36442. }
  36443. };
  36444. }
  36445. });
  36446. // node_modules/@e22m4u/js-repository/src/adapter/decorator/property-uniqueness-decorator.js
  36447. var PropertyUniquenessDecorator;
  36448. var init_property_uniqueness_decorator = __esm({
  36449. "node_modules/@e22m4u/js-repository/src/adapter/decorator/property-uniqueness-decorator.js"() {
  36450. init_adapter();
  36451. init_src2();
  36452. init_errors2();
  36453. init_definition();
  36454. PropertyUniquenessDecorator = class extends Service {
  36455. /**
  36456. * Decorate.
  36457. *
  36458. * @param {Adapter} adapter
  36459. */
  36460. decorate(adapter) {
  36461. if (!adapter || !(adapter instanceof Adapter))
  36462. throw new InvalidArgumentError2(
  36463. "The first argument of PropertyUniquenessDecorator.decorate should be an Adapter instance, but %v given.",
  36464. adapter
  36465. );
  36466. const validator = this.getService(PropertyUniquenessValidator);
  36467. const create = adapter.create;
  36468. adapter.create = async function(modelName, modelData, filter) {
  36469. const countMethod = adapter.count.bind(adapter, modelName);
  36470. await validator.validate(countMethod, "create", modelName, modelData);
  36471. return create.call(this, modelName, modelData, filter);
  36472. };
  36473. const replaceById = adapter.replaceById;
  36474. adapter.replaceById = async function(modelName, id, modelData, filter) {
  36475. const countMethod = adapter.count.bind(adapter, modelName);
  36476. await validator.validate(
  36477. countMethod,
  36478. "replaceById",
  36479. modelName,
  36480. modelData,
  36481. id
  36482. );
  36483. return replaceById.call(this, modelName, id, modelData, filter);
  36484. };
  36485. const replaceOrCreate = adapter.replaceOrCreate;
  36486. adapter.replaceOrCreate = async function(modelName, modelData, filter) {
  36487. const countMethod = adapter.count.bind(adapter, modelName);
  36488. await validator.validate(
  36489. countMethod,
  36490. "replaceOrCreate",
  36491. modelName,
  36492. modelData
  36493. );
  36494. return replaceOrCreate.call(this, modelName, modelData, filter);
  36495. };
  36496. const patch = adapter.patch;
  36497. adapter.patch = async function(modelName, modelData, where) {
  36498. const countMethod = adapter.count.bind(adapter, modelName);
  36499. await validator.validate(countMethod, "patch", modelName, modelData);
  36500. return patch.call(this, modelName, modelData, where);
  36501. };
  36502. const patchById = adapter.patchById;
  36503. adapter.patchById = async function(modelName, id, modelData, filter) {
  36504. const countMethod = adapter.count.bind(adapter, modelName);
  36505. await validator.validate(
  36506. countMethod,
  36507. "patchById",
  36508. modelName,
  36509. modelData,
  36510. id
  36511. );
  36512. return patchById.call(this, modelName, id, modelData, filter);
  36513. };
  36514. }
  36515. };
  36516. }
  36517. });
  36518. // node_modules/@e22m4u/js-repository/src/adapter/decorator/index.js
  36519. var init_decorator = __esm({
  36520. "node_modules/@e22m4u/js-repository/src/adapter/decorator/index.js"() {
  36521. init_inclusion_decorator();
  36522. init_default_values_decorator();
  36523. init_data_sanitizing_decorator();
  36524. init_data_validation_decorator();
  36525. init_fields_filtering_decorator();
  36526. init_data_transformation_decorator();
  36527. init_property_uniqueness_decorator();
  36528. }
  36529. });
  36530. // node_modules/@e22m4u/js-repository/src/adapter/adapter.js
  36531. var Adapter;
  36532. var init_adapter = __esm({
  36533. "node_modules/@e22m4u/js-repository/src/adapter/adapter.js"() {
  36534. init_src2();
  36535. init_errors2();
  36536. init_decorator();
  36537. init_decorator();
  36538. init_decorator();
  36539. init_decorator();
  36540. init_decorator();
  36541. init_decorator();
  36542. init_decorator();
  36543. Adapter = class _Adapter extends Service {
  36544. /**
  36545. * Settings.
  36546. *
  36547. * @type {object|undefined}
  36548. */
  36549. _settings;
  36550. /**
  36551. * Settings.
  36552. *
  36553. * @returns {object|undefined}
  36554. */
  36555. get settings() {
  36556. return this._settings;
  36557. }
  36558. /**
  36559. * Constructor.
  36560. *
  36561. * @param {object|undefined} container
  36562. * @param {object|undefined} settings
  36563. */
  36564. constructor(container = void 0, settings = void 0) {
  36565. super(container);
  36566. this._settings = settings;
  36567. if (this.constructor !== _Adapter) {
  36568. this.getService(DataSanitizingDecorator).decorate(this);
  36569. this.getService(DefaultValuesDecorator).decorate(this);
  36570. this.getService(DataTransformationDecorator).decorate(this);
  36571. this.getService(DataValidationDecorator).decorate(this);
  36572. this.getService(PropertyUniquenessDecorator).decorate(this);
  36573. this.getService(FieldsFilteringDecorator).decorate(this);
  36574. this.getService(InclusionDecorator).decorate(this);
  36575. }
  36576. }
  36577. /**
  36578. * Create.
  36579. *
  36580. * @param {string} modelName
  36581. * @param {object} modelData
  36582. * @param {object|undefined} filter
  36583. * @returns {Promise<object>}
  36584. */
  36585. create(modelName, modelData, filter = void 0) {
  36586. throw new NotImplementedError(
  36587. "%s.create is not implemented.",
  36588. this.constructor.name
  36589. );
  36590. }
  36591. /**
  36592. * Replace by id.
  36593. *
  36594. * @param {string} modelName
  36595. * @param {number|string} id
  36596. * @param {object} modelData
  36597. * @param {object|undefined} filter
  36598. * @returns {Promise<object>}
  36599. */
  36600. replaceById(modelName, id, modelData, filter = void 0) {
  36601. throw new NotImplementedError(
  36602. "%s.replaceById is not implemented.",
  36603. this.constructor.name
  36604. );
  36605. }
  36606. /**
  36607. * Replace or create.
  36608. *
  36609. * @param {string} modelName
  36610. * @param {object} modelData
  36611. * @param {object|undefined} filter
  36612. * @returns {Promise<object>}
  36613. */
  36614. replaceOrCreate(modelName, modelData, filter = void 0) {
  36615. throw new NotImplementedError(
  36616. "%s.replaceOrCreate is not implemented.",
  36617. this.constructor.name
  36618. );
  36619. }
  36620. /**
  36621. * Patch.
  36622. *
  36623. * @param {string} modelName
  36624. * @param {object} modelData
  36625. * @param {object|undefined} where
  36626. * @returns {Promise<number>}
  36627. */
  36628. patch(modelName, modelData, where = void 0) {
  36629. throw new NotImplementedError(
  36630. "%s.patch is not implemented.",
  36631. this.constructor.name
  36632. );
  36633. }
  36634. /**
  36635. * Patch by id.
  36636. *
  36637. * @param {string} modelName
  36638. * @param {number|string} id
  36639. * @param {object} modelData
  36640. * @param {object|undefined} filter
  36641. * @returns {Promise<object>}
  36642. */
  36643. patchById(modelName, id, modelData, filter = void 0) {
  36644. throw new NotImplementedError(
  36645. "%s.patchById is not implemented.",
  36646. this.constructor.name
  36647. );
  36648. }
  36649. /**
  36650. * Find.
  36651. *
  36652. * @param {string} modelName
  36653. * @param {object|undefined} filter
  36654. * @returns {Promise<object[]>}
  36655. */
  36656. find(modelName, filter = void 0) {
  36657. throw new NotImplementedError(
  36658. "%s.find is not implemented.",
  36659. this.constructor.name
  36660. );
  36661. }
  36662. /**
  36663. * Find by id.
  36664. *
  36665. * @param {string} modelName
  36666. * @param {number|string} id
  36667. * @param {object|undefined} filter
  36668. * @returns {Promise<object>}
  36669. */
  36670. findById(modelName, id, filter = void 0) {
  36671. throw new NotImplementedError(
  36672. "%s.findById is not implemented.",
  36673. this.constructor.name
  36674. );
  36675. }
  36676. /**
  36677. * Delete.
  36678. *
  36679. * @param {string} modelName
  36680. * @param {object|undefined} where
  36681. * @returns {Promise<number>}
  36682. */
  36683. delete(modelName, where = void 0) {
  36684. throw new NotImplementedError(
  36685. "%s.delete is not implemented.",
  36686. this.constructor.name
  36687. );
  36688. }
  36689. /**
  36690. * Delete by id.
  36691. *
  36692. * @param {string} modelName
  36693. * @param {number|string} id
  36694. * @returns {Promise<boolean>}
  36695. */
  36696. deleteById(modelName, id) {
  36697. throw new NotImplementedError(
  36698. "%s.deleteById is not implemented.",
  36699. this.constructor.name
  36700. );
  36701. }
  36702. /**
  36703. * Exists.
  36704. *
  36705. * @param {string} modelName
  36706. * @param {number|string} id
  36707. * @returns {Promise<boolean>}
  36708. */
  36709. exists(modelName, id) {
  36710. throw new NotImplementedError(
  36711. "%s.exists is not implemented.",
  36712. this.constructor.name
  36713. );
  36714. }
  36715. /**
  36716. * Count.
  36717. *
  36718. * @param {string} modelName
  36719. * @param {object|undefined} where
  36720. * @returns {Promise<number>}
  36721. */
  36722. count(modelName, where = void 0) {
  36723. throw new NotImplementedError(
  36724. "%s.count is not implemented.",
  36725. this.constructor.name
  36726. );
  36727. }
  36728. };
  36729. }
  36730. });
  36731. // node_modules/@e22m4u/js-repository/src/adapter/builtin/memory-adapter.js
  36732. var memory_adapter_exports = {};
  36733. __export(memory_adapter_exports, {
  36734. MemoryAdapter: () => MemoryAdapter
  36735. });
  36736. var MemoryAdapter;
  36737. var init_memory_adapter = __esm({
  36738. "node_modules/@e22m4u/js-repository/src/adapter/builtin/memory-adapter.js"() {
  36739. init_adapter();
  36740. init_utils2();
  36741. init_utils2();
  36742. init_definition();
  36743. init_filter();
  36744. init_filter();
  36745. init_filter();
  36746. init_errors2();
  36747. init_definition();
  36748. MemoryAdapter = class extends Adapter {
  36749. /**
  36750. * Tables.
  36751. *
  36752. * @type {Map<string, Map<number, Record<string, any>>>}
  36753. */
  36754. _tables = /* @__PURE__ */ new Map();
  36755. /**
  36756. * Last ids.
  36757. *
  36758. * @type {Map<string, number>}
  36759. */
  36760. _lastIds = /* @__PURE__ */ new Map();
  36761. /**
  36762. * Get table or create.
  36763. *
  36764. * @param {string} modelName
  36765. * @returns {Map<number, object>}
  36766. */
  36767. _getTableOrCreate(modelName) {
  36768. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  36769. let table = this._tables.get(tableName);
  36770. if (table) return table;
  36771. table = /* @__PURE__ */ new Map();
  36772. this._tables.set(tableName, table);
  36773. return table;
  36774. }
  36775. /**
  36776. * Gen next id value.
  36777. *
  36778. * @param {string} modelName
  36779. * @param {string} propName
  36780. * @returns {number}
  36781. */
  36782. _genNextIdValue(modelName, propName) {
  36783. const propType = this.getService(
  36784. ModelDefinitionUtils
  36785. ).getDataTypeByPropertyName(modelName, propName);
  36786. if (propType !== DataType.ANY && propType !== DataType.NUMBER)
  36787. throw new InvalidArgumentError2(
  36788. "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.",
  36789. propName,
  36790. modelName,
  36791. capitalize(propType),
  36792. propName
  36793. );
  36794. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  36795. const lastId = this._lastIds.get(tableName) ?? 0;
  36796. const nextId = lastId + 1;
  36797. this._lastIds.set(tableName, nextId);
  36798. const table = this._getTableOrCreate(modelName);
  36799. const existedIds = Array.from(table.keys());
  36800. if (existedIds.includes(nextId))
  36801. return this._genNextIdValue(modelName, propName);
  36802. return nextId;
  36803. }
  36804. /**
  36805. * Create
  36806. *
  36807. * @param {string} modelName
  36808. * @param {object} modelData
  36809. * @param {object|undefined} filter
  36810. * @returns {Promise<object>}
  36811. */
  36812. // eslint-disable-next-line no-unused-vars
  36813. async create(modelName, modelData, filter = void 0) {
  36814. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36815. modelName
  36816. );
  36817. let idValue = modelData[pkPropName];
  36818. if (idValue == null || idValue === "" || idValue === 0) {
  36819. idValue = this._genNextIdValue(modelName, pkPropName);
  36820. }
  36821. const table = this._getTableOrCreate(modelName);
  36822. if (table.has(idValue))
  36823. throw new InvalidArgumentError2(
  36824. "The value %v of the primary key %v already exists in the model %v.",
  36825. idValue,
  36826. pkPropName,
  36827. modelName
  36828. );
  36829. modelData = cloneDeep(modelData);
  36830. modelData[pkPropName] = idValue;
  36831. const tableData = this.getService(
  36832. ModelDefinitionUtils
  36833. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36834. table.set(idValue, tableData);
  36835. return this.getService(
  36836. ModelDefinitionUtils
  36837. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36838. }
  36839. /**
  36840. * Replace by id.
  36841. *
  36842. * @param {string} modelName
  36843. * @param {string|number} id
  36844. * @param {object} modelData
  36845. * @param {object|undefined} filter
  36846. * @returns {Promise<object>}
  36847. */
  36848. // eslint-disable-next-line no-unused-vars
  36849. async replaceById(modelName, id, modelData, filter = void 0) {
  36850. const table = this._getTableOrCreate(modelName);
  36851. const isExists = table.has(id);
  36852. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36853. modelName
  36854. );
  36855. if (!isExists)
  36856. throw new InvalidArgumentError2(
  36857. "The value %v of the primary key %v does not exist in the model %v.",
  36858. id,
  36859. pkPropName,
  36860. modelName
  36861. );
  36862. modelData = cloneDeep(modelData);
  36863. modelData[pkPropName] = id;
  36864. const tableData = this.getService(
  36865. ModelDefinitionUtils
  36866. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36867. table.set(id, tableData);
  36868. return this.getService(
  36869. ModelDefinitionUtils
  36870. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36871. }
  36872. /**
  36873. * Replace or create.
  36874. *
  36875. * @param {string} modelName
  36876. * @param {object} modelData
  36877. * @param {object|undefined} filter
  36878. * @returns {Promise<object>}
  36879. */
  36880. // eslint-disable-next-line no-unused-vars
  36881. async replaceOrCreate(modelName, modelData, filter = void 0) {
  36882. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36883. modelName
  36884. );
  36885. let idValue = modelData[pkPropName];
  36886. if (idValue == null || idValue === "" || idValue === 0) {
  36887. idValue = this._genNextIdValue(modelName, pkPropName);
  36888. }
  36889. const table = this._getTableOrCreate(modelName);
  36890. modelData = cloneDeep(modelData);
  36891. modelData[pkPropName] = idValue;
  36892. const tableData = this.getService(
  36893. ModelDefinitionUtils
  36894. ).convertPropertyNamesToColumnNames(modelName, modelData);
  36895. table.set(idValue, tableData);
  36896. return this.getService(
  36897. ModelDefinitionUtils
  36898. ).convertColumnNamesToPropertyNames(modelName, tableData);
  36899. }
  36900. /**
  36901. * Patch.
  36902. *
  36903. * @param {string} modelName
  36904. * @param {object} modelData
  36905. * @param {object|undefined} where
  36906. * @returns {Promise<number>}
  36907. */
  36908. async patch(modelName, modelData, where = void 0) {
  36909. const table = this._getTableOrCreate(modelName);
  36910. const tableItems = Array.from(table.values());
  36911. if (!tableItems.length) return 0;
  36912. let modelItems = tableItems.map(
  36913. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  36914. modelName,
  36915. tableItem
  36916. )
  36917. );
  36918. if (where && typeof where === "object")
  36919. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  36920. const size = modelItems.length;
  36921. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36922. modelName
  36923. );
  36924. modelData = cloneDeep(modelData);
  36925. delete modelData[pkPropName];
  36926. modelItems.forEach((existingModelData) => {
  36927. const mergedModelData = Object.assign({}, existingModelData, modelData);
  36928. const mergedTableData = this.getService(
  36929. ModelDefinitionUtils
  36930. ).convertPropertyNamesToColumnNames(modelName, mergedModelData);
  36931. const idValue = existingModelData[pkPropName];
  36932. table.set(idValue, mergedTableData);
  36933. });
  36934. return size;
  36935. }
  36936. /**
  36937. * Patch by id.
  36938. *
  36939. * @param {string} modelName
  36940. * @param {string|number} id
  36941. * @param {object} modelData
  36942. * @param {object|undefined} filter
  36943. * @returns {Promise<object>}
  36944. */
  36945. // eslint-disable-next-line no-unused-vars
  36946. async patchById(modelName, id, modelData, filter = void 0) {
  36947. const table = this._getTableOrCreate(modelName);
  36948. const existingTableData = table.get(id);
  36949. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  36950. modelName
  36951. );
  36952. if (existingTableData == null)
  36953. throw new InvalidArgumentError2(
  36954. "The value %v of the primary key %v does not exist in the model %v.",
  36955. id,
  36956. pkPropName,
  36957. modelName
  36958. );
  36959. modelData = cloneDeep(modelData);
  36960. delete modelData[pkPropName];
  36961. const existingModelData = this.getService(
  36962. ModelDefinitionUtils
  36963. ).convertColumnNamesToPropertyNames(modelName, existingTableData);
  36964. const mergedModelData = Object.assign({}, existingModelData, modelData);
  36965. const mergedTableData = this.getService(
  36966. ModelDefinitionUtils
  36967. ).convertPropertyNamesToColumnNames(modelName, mergedModelData);
  36968. table.set(id, mergedTableData);
  36969. return this.getService(
  36970. ModelDefinitionUtils
  36971. ).convertColumnNamesToPropertyNames(modelName, mergedTableData);
  36972. }
  36973. /**
  36974. * Find.
  36975. *
  36976. * @param {string} modelName
  36977. * @param {object|undefined} filter
  36978. * @returns {Promise<object[]>}
  36979. */
  36980. async find(modelName, filter = void 0) {
  36981. const table = this._getTableOrCreate(modelName);
  36982. const tableItems = Array.from(table.values());
  36983. let modelItems = tableItems.map(
  36984. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  36985. modelName,
  36986. tableItem
  36987. )
  36988. );
  36989. if (filter && typeof filter === "object") {
  36990. if (filter.where)
  36991. modelItems = this.getService(WhereClauseTool).filter(
  36992. modelItems,
  36993. filter.where
  36994. );
  36995. if (filter.skip || filter.limit)
  36996. modelItems = this.getService(SliceClauseTool).slice(
  36997. modelItems,
  36998. filter.skip,
  36999. filter.limit
  37000. );
  37001. if (filter.order)
  37002. this.getService(OrderClauseTool).sort(modelItems, filter.order);
  37003. }
  37004. return modelItems;
  37005. }
  37006. /**
  37007. * Find by id.
  37008. *
  37009. * @param {string} modelName
  37010. * @param {string|number} id
  37011. * @param {object|undefined} filter
  37012. * @returns {Promise<object>}
  37013. */
  37014. // eslint-disable-next-line no-unused-vars
  37015. async findById(modelName, id, filter = void 0) {
  37016. const table = this._getTableOrCreate(modelName);
  37017. const tableData = table.get(id);
  37018. const pkPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37019. modelName
  37020. );
  37021. if (!tableData)
  37022. throw new InvalidArgumentError2(
  37023. "The value %v of the primary key %v does not exist in the model %v.",
  37024. id,
  37025. pkPropName,
  37026. modelName
  37027. );
  37028. return this.getService(
  37029. ModelDefinitionUtils
  37030. ).convertColumnNamesToPropertyNames(modelName, tableData);
  37031. }
  37032. /**
  37033. * Delete.
  37034. *
  37035. * @param {string} modelName
  37036. * @param {object|undefined} where
  37037. * @returns {Promise<number>}
  37038. */
  37039. async delete(modelName, where = void 0) {
  37040. const table = this._getTableOrCreate(modelName);
  37041. const tableItems = Array.from(table.values());
  37042. if (!tableItems.length) return 0;
  37043. let modelItems = tableItems.map(
  37044. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  37045. modelName,
  37046. tableItem
  37047. )
  37048. );
  37049. if (where && typeof where === "object")
  37050. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  37051. const size = modelItems.length;
  37052. const idPropName = this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37053. modelName
  37054. );
  37055. modelItems.forEach((modelData) => {
  37056. const idValue = modelData[idPropName];
  37057. table.delete(idValue);
  37058. });
  37059. return size;
  37060. }
  37061. /**
  37062. * Delete by id.
  37063. *
  37064. * @param {string} modelName
  37065. * @param {string|number} id
  37066. * @returns {Promise<boolean>}
  37067. */
  37068. async deleteById(modelName, id) {
  37069. const table = this._getTableOrCreate(modelName);
  37070. const isExists = table.has(id);
  37071. table.delete(id);
  37072. return isExists;
  37073. }
  37074. /**
  37075. * Exists.
  37076. *
  37077. * @param {string} modelName
  37078. * @param {string|number} id
  37079. * @returns {Promise<boolean>}
  37080. */
  37081. async exists(modelName, id) {
  37082. const table = this._getTableOrCreate(modelName);
  37083. return table.has(id);
  37084. }
  37085. /**
  37086. * Count.
  37087. *
  37088. * @param {string} modelName
  37089. * @param {object|undefined} where
  37090. * @returns {Promise<number>}
  37091. */
  37092. async count(modelName, where = void 0) {
  37093. const table = this._getTableOrCreate(modelName);
  37094. const tableItems = Array.from(table.values());
  37095. let modelItems = tableItems.map(
  37096. (tableItem) => this.getService(ModelDefinitionUtils).convertColumnNamesToPropertyNames(
  37097. modelName,
  37098. tableItem
  37099. )
  37100. );
  37101. if (where && typeof where === "object")
  37102. modelItems = this.getService(WhereClauseTool).filter(modelItems, where);
  37103. return modelItems.length;
  37104. }
  37105. };
  37106. }
  37107. });
  37108. // import("./builtin/**/*-adapter.js") in node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js
  37109. var globImport_builtin_adapter_js;
  37110. var init_ = __esm({
  37111. 'import("./builtin/**/*-adapter.js") in node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js'() {
  37112. globImport_builtin_adapter_js = __glob({
  37113. "./builtin/memory-adapter.js": () => Promise.resolve().then(() => (init_memory_adapter(), memory_adapter_exports))
  37114. });
  37115. }
  37116. });
  37117. // node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js
  37118. function findAdapterCtorInModule(module2) {
  37119. let adapterCtor;
  37120. if (!module2 || typeof module2 !== "object" || Array.isArray(module2)) return;
  37121. for (const ctor of Object.values(module2)) {
  37122. if (typeof ctor === "function" && ctor.prototype instanceof Adapter) {
  37123. adapterCtor = ctor;
  37124. break;
  37125. }
  37126. }
  37127. return adapterCtor;
  37128. }
  37129. var AdapterLoader;
  37130. var init_adapter_loader = __esm({
  37131. "node_modules/@e22m4u/js-repository/src/adapter/adapter-loader.js"() {
  37132. init_adapter();
  37133. init_src2();
  37134. init_errors2();
  37135. init_();
  37136. AdapterLoader = class extends Service {
  37137. /**
  37138. * Load by name.
  37139. *
  37140. * @param {string} adapterName
  37141. * @param {object|undefined} settings
  37142. * @returns {Promise<Adapter>}
  37143. */
  37144. async loadByName(adapterName, settings = void 0) {
  37145. if (!adapterName || typeof adapterName !== "string")
  37146. throw new InvalidArgumentError2(
  37147. "The adapter name should be a non-empty String, but %v given.",
  37148. adapterName
  37149. );
  37150. let adapterCtor;
  37151. try {
  37152. const module2 = await globImport_builtin_adapter_js(`./builtin/${adapterName}-adapter.js`);
  37153. adapterCtor = findAdapterCtorInModule(module2);
  37154. } catch (e) {
  37155. }
  37156. if (!adapterCtor)
  37157. try {
  37158. const module2 = await import(`@e22m4u/js-repository-${adapterName}-adapter`);
  37159. adapterCtor = findAdapterCtorInModule(module2);
  37160. } catch (e) {
  37161. }
  37162. if (!adapterCtor)
  37163. throw new InvalidArgumentError2(
  37164. "The adapter %v is not found.",
  37165. adapterName
  37166. );
  37167. return new adapterCtor(this.container, settings);
  37168. }
  37169. };
  37170. }
  37171. });
  37172. // node_modules/@e22m4u/js-repository/src/adapter/adapter-registry.js
  37173. var AdapterRegistry;
  37174. var init_adapter_registry = __esm({
  37175. "node_modules/@e22m4u/js-repository/src/adapter/adapter-registry.js"() {
  37176. init_adapter();
  37177. init_src2();
  37178. init_adapter_loader();
  37179. init_definition();
  37180. AdapterRegistry = class extends Service {
  37181. /**
  37182. * Adapters.
  37183. *
  37184. * @type {object}
  37185. */
  37186. _adapters = {};
  37187. /**
  37188. * Get adapter.
  37189. *
  37190. * @param {string} datasourceName
  37191. * @returns {Promise<Adapter>}
  37192. */
  37193. async getAdapter(datasourceName) {
  37194. let adapter = this._adapters[datasourceName];
  37195. if (adapter) return adapter;
  37196. const datasource = this.getService(DefinitionRegistry).getDatasource(datasourceName);
  37197. const adapterName = datasource.adapter;
  37198. adapter = await this.getService(AdapterLoader).loadByName(
  37199. adapterName,
  37200. datasource
  37201. );
  37202. this._adapters[datasourceName] = adapter;
  37203. return adapter;
  37204. }
  37205. };
  37206. }
  37207. });
  37208. // node_modules/@e22m4u/js-repository/src/adapter/index.js
  37209. var init_adapter2 = __esm({
  37210. "node_modules/@e22m4u/js-repository/src/adapter/index.js"() {
  37211. init_adapter();
  37212. init_adapter_loader();
  37213. init_adapter_registry();
  37214. }
  37215. });
  37216. // node_modules/@e22m4u/js-repository/src/repository/repository.js
  37217. var Repository;
  37218. var init_repository = __esm({
  37219. "node_modules/@e22m4u/js-repository/src/repository/repository.js"() {
  37220. init_src2();
  37221. init_adapter2();
  37222. init_adapter2();
  37223. init_errors2();
  37224. init_definition();
  37225. Repository = class extends Service {
  37226. /**
  37227. * Model name.
  37228. *
  37229. * @type {string}
  37230. */
  37231. _modelName;
  37232. /**
  37233. * Model name.
  37234. *
  37235. * @returns {string}
  37236. */
  37237. get modelName() {
  37238. return this._modelName;
  37239. }
  37240. /**
  37241. * Datasource name.
  37242. *
  37243. * @type {string}
  37244. */
  37245. _datasourceName;
  37246. /**
  37247. * Datasource name.
  37248. *
  37249. * @returns {string}
  37250. */
  37251. get datasourceName() {
  37252. return this._datasourceName;
  37253. }
  37254. /**
  37255. * Constructor.
  37256. *
  37257. * @typedef {import('@e22m4u/js-service').ServiceContainer} ServiceContainer
  37258. * @param {ServiceContainer} container
  37259. * @param {string} modelName
  37260. */
  37261. constructor(container, modelName) {
  37262. super(container);
  37263. this._modelName = modelName;
  37264. const modelDef = this.getService(DefinitionRegistry).getModel(modelName);
  37265. const datasourceName = modelDef.datasource;
  37266. if (!datasourceName)
  37267. throw new InvalidArgumentError2(
  37268. "The model %v does not have a specified datasource.",
  37269. modelName
  37270. );
  37271. this._datasourceName = datasourceName;
  37272. }
  37273. /**
  37274. * Get adapter.
  37275. *
  37276. * @returns {Adapter}
  37277. */
  37278. async getAdapter() {
  37279. return this.getService(AdapterRegistry).getAdapter(this.datasourceName);
  37280. }
  37281. /**
  37282. * Create.
  37283. *
  37284. * @param {object} data
  37285. * @param {object|undefined} filter
  37286. * @returns {Promise<object>}
  37287. */
  37288. async create(data, filter = void 0) {
  37289. const adapter = await this.getAdapter();
  37290. return adapter.create(this.modelName, data, filter);
  37291. }
  37292. /**
  37293. * Replace by id.
  37294. *
  37295. * @param {number|string} id
  37296. * @param {object} data
  37297. * @param {object|undefined} filter
  37298. * @returns {Promise<object>}
  37299. */
  37300. async replaceById(id, data, filter = void 0) {
  37301. const adapter = await this.getAdapter();
  37302. return adapter.replaceById(this.modelName, id, data, filter);
  37303. }
  37304. /**
  37305. * Replace or create.
  37306. *
  37307. * @param {object} data
  37308. * @param {object|undefined} filter
  37309. * @returns {Promise<object>}
  37310. */
  37311. async replaceOrCreate(data, filter = void 0) {
  37312. const adapter = await this.getAdapter();
  37313. return adapter.replaceOrCreate(this.modelName, data, filter);
  37314. }
  37315. /**
  37316. * Patch.
  37317. *
  37318. * @param {object} data
  37319. * @param {object|undefined} where
  37320. * @returns {Promise<number>}
  37321. */
  37322. async patch(data, where = void 0) {
  37323. const adapter = await this.getAdapter();
  37324. return adapter.patch(this.modelName, data, where);
  37325. }
  37326. /**
  37327. * Patch by id.
  37328. *
  37329. * @param {number|string} id
  37330. * @param {object} data
  37331. * @param {object|undefined} filter
  37332. * @returns {Promise<object>}
  37333. */
  37334. async patchById(id, data, filter = void 0) {
  37335. const adapter = await this.getAdapter();
  37336. return adapter.patchById(this.modelName, id, data, filter);
  37337. }
  37338. /**
  37339. * Find.
  37340. *
  37341. * @param {object|undefined} filter
  37342. * @returns {Promise<object[]>}
  37343. */
  37344. async find(filter = void 0) {
  37345. const adapter = await this.getAdapter();
  37346. return adapter.find(this.modelName, filter);
  37347. }
  37348. /**
  37349. * Find one.
  37350. *
  37351. * @param {object|undefined} filter
  37352. * @returns {Promise<object|undefined>}
  37353. */
  37354. async findOne(filter = void 0) {
  37355. const adapter = await this.getAdapter();
  37356. filter = filter ?? {};
  37357. filter.limit = 1;
  37358. const result = await adapter.find(this.modelName, filter);
  37359. return result.length ? result[0] : void 0;
  37360. }
  37361. /**
  37362. * Find by id.
  37363. *
  37364. * @param {number|string} id
  37365. * @param {object|undefined} filter
  37366. * @returns {Promise<object>}
  37367. */
  37368. async findById(id, filter = void 0) {
  37369. const adapter = await this.getAdapter();
  37370. return adapter.findById(this.modelName, id, filter);
  37371. }
  37372. /**
  37373. * Delete.
  37374. *
  37375. * @param {object|undefined} where
  37376. * @returns {Promise<number>}
  37377. */
  37378. async delete(where = void 0) {
  37379. const adapter = await this.getAdapter();
  37380. return adapter.delete(this.modelName, where);
  37381. }
  37382. /**
  37383. * Delete by id.
  37384. *
  37385. * @param {number|string} id
  37386. * @returns {Promise<boolean>}
  37387. */
  37388. async deleteById(id) {
  37389. const adapter = await this.getAdapter();
  37390. return adapter.deleteById(this.modelName, id);
  37391. }
  37392. /**
  37393. * Exists.
  37394. *
  37395. * @param {number|string} id
  37396. * @returns {Promise<boolean>}
  37397. */
  37398. async exists(id) {
  37399. const adapter = await this.getAdapter();
  37400. return adapter.exists(this.modelName, id);
  37401. }
  37402. /**
  37403. * Count.
  37404. *
  37405. * @param {object|undefined} where
  37406. * @returns {Promise<number>}
  37407. */
  37408. async count(where = void 0) {
  37409. const adapter = await this.getAdapter();
  37410. return adapter.count(this.modelName, where);
  37411. }
  37412. };
  37413. }
  37414. });
  37415. // node_modules/@e22m4u/js-repository/src/repository/repository-registry.js
  37416. var RepositoryRegistry;
  37417. var init_repository_registry = __esm({
  37418. "node_modules/@e22m4u/js-repository/src/repository/repository-registry.js"() {
  37419. init_src2();
  37420. init_repository();
  37421. init_errors2();
  37422. RepositoryRegistry = class extends Service {
  37423. /**
  37424. * Repositories.
  37425. *
  37426. * @type {object}
  37427. */
  37428. _repositories = {};
  37429. /**
  37430. * Repository ctor.
  37431. *
  37432. * @type {typeof Repository}
  37433. * @private
  37434. */
  37435. _repositoryCtor = Repository;
  37436. /**
  37437. * Set repository ctor.
  37438. *
  37439. * @param {typeof Repository} ctor
  37440. */
  37441. setRepositoryCtor(ctor) {
  37442. if (!ctor || typeof ctor !== "function" || !(ctor.prototype instanceof Repository)) {
  37443. throw new InvalidArgumentError2(
  37444. "The first argument of RepositoryRegistry.setRepositoryCtor must inherit from Repository class, but %v given.",
  37445. ctor
  37446. );
  37447. }
  37448. this._repositoryCtor = ctor;
  37449. }
  37450. /**
  37451. * Get repository.
  37452. *
  37453. * @param {string} modelName
  37454. * @returns {Repository}
  37455. */
  37456. getRepository(modelName) {
  37457. let repository = this._repositories[modelName];
  37458. if (repository) return repository;
  37459. repository = new this._repositoryCtor(this.container, modelName);
  37460. this._repositories[modelName] = repository;
  37461. return repository;
  37462. }
  37463. };
  37464. }
  37465. });
  37466. // node_modules/@e22m4u/js-repository/src/repository/index.js
  37467. var init_repository2 = __esm({
  37468. "node_modules/@e22m4u/js-repository/src/repository/index.js"() {
  37469. init_repository();
  37470. init_repository_registry();
  37471. }
  37472. });
  37473. // src/index.js
  37474. var src_exports = {};
  37475. __export(src_exports, {
  37476. MongodbAdapter: () => MongodbAdapter
  37477. });
  37478. module.exports = __toCommonJS(src_exports);
  37479. // src/mongodb-adapter.js
  37480. var import_mongodb2 = __toESM(require_lib3(), 1);
  37481. var import_mongodb3 = __toESM(require_lib3(), 1);
  37482. // src/utils/is-iso-date.js
  37483. function isIsoDate(value) {
  37484. if (!value) return false;
  37485. if (value instanceof Date) return true;
  37486. if (!/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(value)) return false;
  37487. const d = new Date(value);
  37488. return d instanceof Date && !isNaN(d.getTime()) && d.toISOString() === value;
  37489. }
  37490. // src/utils/is-object-id.js
  37491. var import_mongodb = __toESM(require_lib3(), 1);
  37492. function isObjectId(value) {
  37493. if (!value) return false;
  37494. if (value instanceof import_mongodb.ObjectId) return true;
  37495. if (typeof value !== "string") return false;
  37496. return value.match(/^[a-fA-F0-9]{24}$/) != null;
  37497. }
  37498. // node_modules/@e22m4u/js-repository/src/schema.js
  37499. init_src2();
  37500. init_repository2();
  37501. init_definition();
  37502. init_repository2();
  37503. // node_modules/@e22m4u/js-repository/src/index.js
  37504. init_utils2();
  37505. init_errors2();
  37506. init_filter();
  37507. init_adapter2();
  37508. init_relations2();
  37509. init_definition();
  37510. init_repository2();
  37511. // src/utils/create-mongodb-url.js
  37512. function createMongodbUrl(options = {}) {
  37513. if (!options || typeof options !== "object" || Array.isArray(options))
  37514. throw new InvalidArgumentError2(
  37515. 'The first argument of "createMongodbUrl" must be an Object, but %v given.',
  37516. options
  37517. );
  37518. if (options.protocol && typeof options.protocol !== "string")
  37519. throw new InvalidArgumentError2(
  37520. 'MongoDB option "protocol" must be a String, but %v given.',
  37521. options.protocol
  37522. );
  37523. if (options.hostname && typeof options.hostname !== "string")
  37524. throw new InvalidArgumentError2(
  37525. 'MongoDB option "hostname" must be a String, but %v given.',
  37526. options.hostname
  37527. );
  37528. if (options.host && typeof options.host !== "string")
  37529. throw new InvalidArgumentError2(
  37530. 'MongoDB option "host" must be a String, but %v given.',
  37531. options.host
  37532. );
  37533. if (options.port && typeof options.port !== "number" && typeof options.port !== "string") {
  37534. throw new InvalidArgumentError2(
  37535. 'MongoDB option "port" must be a Number or a String, but %v given.',
  37536. options.port
  37537. );
  37538. }
  37539. if (options.database && typeof options.database !== "string")
  37540. throw new InvalidArgumentError2(
  37541. 'MongoDB option "database" must be a String, but %v given.',
  37542. options.database
  37543. );
  37544. if (options.db && typeof options.db !== "string")
  37545. throw new InvalidArgumentError2(
  37546. 'MongoDB option "db" must be a String, but %v given.',
  37547. options.db
  37548. );
  37549. if (options.username && typeof options.username !== "string")
  37550. throw new InvalidArgumentError2(
  37551. 'MongoDB option "username" must be a String, but %v given.',
  37552. options.username
  37553. );
  37554. if (options.password && typeof options.password !== "string" && typeof options.password !== "number") {
  37555. throw new InvalidArgumentError2(
  37556. 'MongoDB option "password" must be a String or a Number, but %v given.',
  37557. options.password
  37558. );
  37559. }
  37560. if (options.pass && typeof options.pass !== "string" && typeof options.pass !== "number") {
  37561. throw new InvalidArgumentError2(
  37562. 'MongoDB option "pass" must be a String or a Number, but %v given.',
  37563. options.pass
  37564. );
  37565. }
  37566. const protocol = options.protocol || "mongodb";
  37567. const hostname = options.hostname || options.host || "127.0.0.1";
  37568. const port = options.port || 27017;
  37569. const database = options.database || options.db || "database";
  37570. const username = options.username || options.user;
  37571. const password = options.password || options.pass || void 0;
  37572. let portUrl = "";
  37573. if (protocol !== "mongodb+srv") {
  37574. portUrl = ":" + port;
  37575. }
  37576. if (username && password) {
  37577. return `${protocol}://${username}:${password}@${hostname}${portUrl}/${database}`;
  37578. } else {
  37579. return `${protocol}://${hostname}${portUrl}/${database}`;
  37580. }
  37581. }
  37582. // src/utils/transform-values-deep.js
  37583. function transformValuesDeep(value, transformer) {
  37584. if (!transformer || typeof transformer !== "function")
  37585. throw new InvalidArgumentError2(
  37586. 'The second argument of "transformValuesDeep" must be a Function, but %v given.',
  37587. transformer
  37588. );
  37589. if (Array.isArray(value)) {
  37590. value.forEach((v, i) => value[i] = transformValuesDeep(v, transformer));
  37591. return value;
  37592. } else if (value && typeof value === "object") {
  37593. if (!value.constructor || value.constructor && value.constructor.name === "Object") {
  37594. Object.keys(value).forEach((key) => {
  37595. if (Object.prototype.hasOwnProperty.call(value, key))
  37596. value[key] = transformValuesDeep(value[key], transformer);
  37597. });
  37598. return value;
  37599. } else {
  37600. return transformer(value);
  37601. }
  37602. } else {
  37603. return transformer(value);
  37604. }
  37605. }
  37606. // src/mongodb-adapter.js
  37607. init_src2();
  37608. var MONGODB_OPTION_NAMES = [
  37609. "appname",
  37610. "authMechanism",
  37611. "authMechanismProperties",
  37612. "authSource",
  37613. "compressors",
  37614. "connectTimeoutMS",
  37615. "directConnection",
  37616. "heartbeatFrequencyMS",
  37617. "journal",
  37618. "loadBalanced",
  37619. "localThresholdMS",
  37620. "maxIdleTimeMS",
  37621. "maxPoolSize",
  37622. "maxConnecting",
  37623. "maxStalenessSeconds",
  37624. "minPoolSize",
  37625. "proxyHost",
  37626. "proxyPort",
  37627. "proxyUsername",
  37628. "proxyPassword",
  37629. "readConcernLevel",
  37630. "readPreference",
  37631. "readPreferenceTags",
  37632. "replicaSet",
  37633. "retryReads",
  37634. "retryWrites",
  37635. "serverSelectionTimeoutMS",
  37636. "serverSelectionTryOnce",
  37637. "socketTimeoutMS",
  37638. "srvMaxHosts",
  37639. "srvServiceName",
  37640. "ssl",
  37641. "timeoutMS",
  37642. "tls",
  37643. "tlsAllowInvalidCertificates",
  37644. "tlsAllowInvalidHostnames",
  37645. "tlsCAFile",
  37646. "tlsCertificateKeyFile",
  37647. "tlsCertificateKeyFilePassword",
  37648. "tlsInsecure",
  37649. "w",
  37650. "waitQueueTimeoutMS",
  37651. "wTimeoutMS",
  37652. "zlibCompressionLevel"
  37653. ];
  37654. var DEFAULT_SETTINGS = {
  37655. // connectTimeoutMS: 2500,
  37656. // serverSelectionTimeoutMS: 2500,
  37657. };
  37658. var MongodbAdapter = class extends Adapter {
  37659. /**
  37660. * Mongodb instance.
  37661. *
  37662. * @type {MongoClient}
  37663. * @private
  37664. */
  37665. _client;
  37666. /**
  37667. * Client.
  37668. *
  37669. * @returns {MongoClient}
  37670. */
  37671. get client() {
  37672. return this._client;
  37673. }
  37674. /**
  37675. * Collections.
  37676. *
  37677. * @type {Map<any, any>}
  37678. * @private
  37679. */
  37680. _collections = /* @__PURE__ */ new Map();
  37681. /**
  37682. * Constructor.
  37683. *
  37684. * @param {ServiceContainer} container
  37685. * @param settings
  37686. */
  37687. constructor(container, settings) {
  37688. settings = Object.assign({}, DEFAULT_SETTINGS, settings || {});
  37689. settings.protocol = settings.protocol || "mongodb";
  37690. settings.hostname = settings.hostname || settings.host || "127.0.0.1";
  37691. settings.port = settings.port || 27017;
  37692. settings.database = settings.database || settings.db || "database";
  37693. super(container, settings);
  37694. const options = selectObjectKeys(this.settings, MONGODB_OPTION_NAMES);
  37695. const url = createMongodbUrl(this.settings);
  37696. this._client = new import_mongodb3.MongoClient(url, options);
  37697. }
  37698. /**
  37699. * Get id prop name.
  37700. *
  37701. * @param modelName
  37702. */
  37703. _getIdPropName(modelName) {
  37704. return this.getService(ModelDefinitionUtils).getPrimaryKeyAsPropertyName(
  37705. modelName
  37706. );
  37707. }
  37708. /**
  37709. * Get id col name.
  37710. *
  37711. * @param modelName
  37712. */
  37713. _getIdColName(modelName) {
  37714. return this.getService(ModelDefinitionUtils).getPrimaryKeyAsColumnName(
  37715. modelName
  37716. );
  37717. }
  37718. /**
  37719. * Coerce id.
  37720. *
  37721. * @param value
  37722. * @return {ObjectId|*}
  37723. * @private
  37724. */
  37725. _coerceId(value) {
  37726. if (value == null) return value;
  37727. if (isObjectId(value)) return new import_mongodb2.ObjectId(value);
  37728. return value;
  37729. }
  37730. /**
  37731. * Coerce date.
  37732. *
  37733. * @param value
  37734. * @returns {Date|*}
  37735. * @private
  37736. */
  37737. _coerceDate(value) {
  37738. if (value == null) return value;
  37739. if (value instanceof Date) return value;
  37740. if (isIsoDate(value)) return new Date(value);
  37741. return value;
  37742. }
  37743. /**
  37744. * To database.
  37745. *
  37746. * @param {string} modelName
  37747. * @param {object} modelData
  37748. * @return {object}
  37749. * @private
  37750. */
  37751. _toDatabase(modelName, modelData) {
  37752. const tableData = this.getService(
  37753. ModelDefinitionUtils
  37754. ).convertPropertyNamesToColumnNames(modelName, modelData);
  37755. const idColName = this._getIdColName(modelName);
  37756. if (idColName !== "id" && idColName !== "_id")
  37757. throw new InvalidArgumentError2(
  37758. 'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
  37759. idColName
  37760. );
  37761. if (idColName in tableData && idColName !== "_id") {
  37762. tableData._id = tableData[idColName];
  37763. delete tableData[idColName];
  37764. }
  37765. return transformValuesDeep(tableData, (value) => {
  37766. if (value instanceof import_mongodb2.ObjectId) return value;
  37767. if (value instanceof Date) return value;
  37768. if (isObjectId(value)) return new import_mongodb2.ObjectId(value);
  37769. if (isIsoDate(value)) return new Date(value);
  37770. return value;
  37771. });
  37772. }
  37773. /**
  37774. * From database.
  37775. *
  37776. * @param {string} modelName
  37777. * @param {object} tableData
  37778. * @return {object}
  37779. * @private
  37780. */
  37781. _fromDatabase(modelName, tableData) {
  37782. if ("_id" in tableData) {
  37783. const idColName = this._getIdColName(modelName);
  37784. if (idColName !== "id" && idColName !== "_id")
  37785. throw new InvalidArgumentError2(
  37786. 'MongoDB is not supporting custom names of the primary key. Do use "id" as a primary key instead of %v.',
  37787. idColName
  37788. );
  37789. if (idColName !== "_id") {
  37790. tableData[idColName] = tableData._id;
  37791. delete tableData._id;
  37792. }
  37793. }
  37794. const modelData = this.getService(
  37795. ModelDefinitionUtils
  37796. ).convertColumnNamesToPropertyNames(modelName, tableData);
  37797. return transformValuesDeep(modelData, (value) => {
  37798. if (value instanceof import_mongodb2.ObjectId) return String(value);
  37799. if (value instanceof Date) return value.toISOString();
  37800. return value;
  37801. });
  37802. }
  37803. /**
  37804. * Get collection.
  37805. *
  37806. * @param {string} modelName
  37807. * @return {*}
  37808. * @private
  37809. */
  37810. _getCollection(modelName) {
  37811. let collection = this._collections.get(modelName);
  37812. if (collection) return collection;
  37813. const tableName = this.getService(ModelDefinitionUtils).getTableNameByModelName(modelName);
  37814. collection = this.client.db(this.settings.database).collection(tableName);
  37815. this._collections.set(modelName, collection);
  37816. return collection;
  37817. }
  37818. /**
  37819. * Get id type.
  37820. *
  37821. * @param modelName
  37822. * @return {string|*}
  37823. * @private
  37824. */
  37825. _getIdType(modelName) {
  37826. const utils = this.getService(ModelDefinitionUtils);
  37827. const pkPropName = utils.getPrimaryKeyAsPropertyName(modelName);
  37828. return utils.getDataTypeByPropertyName(modelName, pkPropName);
  37829. }
  37830. /**
  37831. * Build projection.
  37832. *
  37833. * @param {string} modelName
  37834. * @param {string|string[]} fields
  37835. * @return {Record<string, number>|undefined}
  37836. * @private
  37837. */
  37838. _buildProjection(modelName, fields) {
  37839. if (fields == null) return;
  37840. if (Array.isArray(fields) === false) fields = [fields];
  37841. if (!fields.length) return;
  37842. if (fields.indexOf("_id") === -1) fields.push("_id");
  37843. return fields.reduce((acc, field) => {
  37844. if (!field || typeof field !== "string")
  37845. throw new InvalidArgumentError2(
  37846. 'The provided option "fields" should be a non-empty String or an Array of non-empty String, but %v given.',
  37847. field
  37848. );
  37849. let colName = this._getColName(modelName, field);
  37850. acc[colName] = 1;
  37851. return acc;
  37852. }, {});
  37853. }
  37854. /**
  37855. * Get col name.
  37856. *
  37857. * @param {string} modelName
  37858. * @param {string} propName
  37859. * @return {string}
  37860. * @private
  37861. */
  37862. _getColName(modelName, propName) {
  37863. if (!propName || typeof propName !== "string")
  37864. throw new InvalidArgumentError2(
  37865. "A property name must be a non-empty String, but %v given.",
  37866. propName
  37867. );
  37868. const utils = this.getService(ModelDefinitionUtils);
  37869. let colName = propName;
  37870. try {
  37871. colName = utils.getColumnNameByPropertyName(modelName, propName);
  37872. } catch (error) {
  37873. if (!(error instanceof InvalidArgumentError2) || error.message.indexOf("does not have the property") === -1) {
  37874. throw error;
  37875. }
  37876. }
  37877. return colName;
  37878. }
  37879. /**
  37880. * Build sort.
  37881. *
  37882. * @param {string} modelName
  37883. * @param {string|string[]} clause
  37884. * @return {object|undefined}
  37885. * @private
  37886. */
  37887. _buildSort(modelName, clause) {
  37888. if (clause == null) return;
  37889. if (Array.isArray(clause) === false) clause = [clause];
  37890. if (!clause.length) return;
  37891. const utils = this.getService(ModelDefinitionUtils);
  37892. const idPropName = this._getIdPropName(modelName);
  37893. return clause.reduce((acc, order) => {
  37894. if (!order || typeof order !== "string")
  37895. throw new InvalidArgumentError2(
  37896. 'The provided option "order" should be a non-empty String or an Array of non-empty String, but %v given.',
  37897. order
  37898. );
  37899. const direction = order.match(/\s+(A|DE)SC$/);
  37900. let field = order.replace(/\s+(A|DE)SC$/, "").trim();
  37901. if (field === idPropName) {
  37902. field = "_id";
  37903. } else {
  37904. try {
  37905. field = utils.getColumnNameByPropertyName(modelName, field);
  37906. } catch (error) {
  37907. if (!(error instanceof InvalidArgumentError2) || error.message.indexOf("does not have the property") === -1) {
  37908. throw error;
  37909. }
  37910. }
  37911. }
  37912. acc[field] = direction && direction[1] === "DE" ? -1 : 1;
  37913. return acc;
  37914. }, {});
  37915. }
  37916. /**
  37917. * Build query.
  37918. *
  37919. * @param {string} modelName
  37920. * @param {object} clause
  37921. * @return {object}
  37922. * @private
  37923. */
  37924. _buildQuery(modelName, clause) {
  37925. if (clause == null) return;
  37926. if (typeof clause !== "object" || Array.isArray(clause))
  37927. throw new InvalidArgumentError2(
  37928. 'The provided option "where" should be an Object, but %v given.',
  37929. clause
  37930. );
  37931. const query = {};
  37932. const idPropName = this._getIdPropName(modelName);
  37933. Object.keys(clause).forEach((key) => {
  37934. if (String(key).indexOf("$") !== -1)
  37935. throw new InvalidArgumentError2(
  37936. 'The symbol "$" is not supported, but %v given.',
  37937. key
  37938. );
  37939. let cond = clause[key];
  37940. if (key === "and" || key === "or" || key === "nor") {
  37941. if (cond == null) return;
  37942. if (!Array.isArray(cond))
  37943. throw new InvalidOperatorValueError(key, "an Array", cond);
  37944. if (cond.length === 0) return;
  37945. cond = cond.map((c) => this._buildQuery(modelName, c));
  37946. cond = cond.filter((c) => c != null);
  37947. const opKey = "$" + key;
  37948. query[opKey] = query[opKey] ?? [];
  37949. query[opKey] = [...query[opKey], ...cond];
  37950. return;
  37951. }
  37952. if (key === idPropName) {
  37953. key = "_id";
  37954. } else {
  37955. key = this._getColName(modelName, key);
  37956. }
  37957. if (typeof cond === "string") {
  37958. query[key] = this._coerceId(cond);
  37959. query[key] = this._coerceDate(query[key]);
  37960. return;
  37961. }
  37962. if (cond instanceof import_mongodb2.ObjectId) {
  37963. query[key] = cond;
  37964. return;
  37965. }
  37966. if (cond && cond.constructor && cond.constructor.name === "Object") {
  37967. const opConds = [];
  37968. if ("eq" in cond) {
  37969. let eq = this._coerceId(cond.eq);
  37970. eq = this._coerceDate(eq);
  37971. opConds.push({ $eq: eq });
  37972. }
  37973. if ("neq" in cond) {
  37974. let neq = this._coerceId(cond.neq);
  37975. neq = this._coerceDate(neq);
  37976. opConds.push({ $ne: neq });
  37977. }
  37978. if ("gt" in cond) {
  37979. const gt = this._coerceDate(cond.gt);
  37980. opConds.push({ $gt: gt });
  37981. }
  37982. if ("lt" in cond) {
  37983. const lt = this._coerceDate(cond.lt);
  37984. opConds.push({ $lt: lt });
  37985. }
  37986. if ("gte" in cond) {
  37987. const gte = this._coerceDate(cond.gte);
  37988. opConds.push({ $gte: gte });
  37989. }
  37990. if ("lte" in cond) {
  37991. const lte = this._coerceDate(cond.lte);
  37992. opConds.push({ $lte: lte });
  37993. }
  37994. if ("inq" in cond) {
  37995. if (!cond.inq || !Array.isArray(cond.inq))
  37996. throw new InvalidOperatorValueError(
  37997. "inq",
  37998. "an Array of possible values",
  37999. cond.inq
  38000. );
  38001. const inq = cond.inq.map((v) => {
  38002. v = this._coerceId(v);
  38003. v = this._coerceDate(v);
  38004. return v;
  38005. });
  38006. opConds.push({ $in: inq });
  38007. }
  38008. if ("nin" in cond) {
  38009. if (!cond.nin || !Array.isArray(cond.nin))
  38010. throw new InvalidOperatorValueError(
  38011. "nin",
  38012. "an Array of possible values",
  38013. cond
  38014. );
  38015. const nin = cond.nin.map((v) => {
  38016. v = this._coerceId(v);
  38017. v = this._coerceDate(v);
  38018. return v;
  38019. });
  38020. opConds.push({ $nin: nin });
  38021. }
  38022. if ("between" in cond) {
  38023. if (!Array.isArray(cond.between) || cond.between.length !== 2)
  38024. throw new InvalidOperatorValueError(
  38025. "between",
  38026. "an Array of 2 elements",
  38027. cond.between
  38028. );
  38029. const gte = this._coerceDate(cond.between[0]);
  38030. const lte = this._coerceDate(cond.between[1]);
  38031. opConds.push({ $gte: gte, $lte: lte });
  38032. }
  38033. if ("exists" in cond) {
  38034. if (typeof cond.exists !== "boolean")
  38035. throw new InvalidOperatorValueError(
  38036. "exists",
  38037. "a Boolean",
  38038. cond.exists
  38039. );
  38040. opConds.push({ $exists: cond.exists });
  38041. }
  38042. if ("like" in cond) {
  38043. if (typeof cond.like !== "string" && !(cond.like instanceof RegExp))
  38044. throw new InvalidOperatorValueError(
  38045. "like",
  38046. "a String or RegExp",
  38047. cond.like
  38048. );
  38049. opConds.push({ $regex: stringToRegexp(cond.like) });
  38050. }
  38051. if ("nlike" in cond) {
  38052. if (typeof cond.nlike !== "string" && !(cond.nlike instanceof RegExp))
  38053. throw new InvalidOperatorValueError(
  38054. "nlike",
  38055. "a String or RegExp",
  38056. cond.nlike
  38057. );
  38058. opConds.push({ $not: stringToRegexp(cond.nlike) });
  38059. }
  38060. if ("ilike" in cond) {
  38061. if (typeof cond.ilike !== "string" && !(cond.ilike instanceof RegExp))
  38062. throw new InvalidOperatorValueError(
  38063. "ilike",
  38064. "a String or RegExp",
  38065. cond.ilike
  38066. );
  38067. opConds.push({ $regex: stringToRegexp(cond.ilike, "i") });
  38068. }
  38069. if ("nilike" in cond) {
  38070. if (typeof cond.nilike !== "string" && !(cond.nilike instanceof RegExp)) {
  38071. throw new InvalidOperatorValueError(
  38072. "nilike",
  38073. "a String or RegExp",
  38074. cond.nilike
  38075. );
  38076. }
  38077. opConds.push({ $not: stringToRegexp(cond.nilike, "i") });
  38078. }
  38079. if ("regexp" in cond) {
  38080. if (typeof cond.regexp !== "string" && !(cond.regexp instanceof RegExp)) {
  38081. throw new InvalidOperatorValueError(
  38082. "regexp",
  38083. "a String or RegExp",
  38084. cond.regexp
  38085. );
  38086. }
  38087. const flags = cond.flags || void 0;
  38088. if (flags && typeof flags !== "string")
  38089. throw new InvalidArgumentError2(
  38090. "RegExp flags must be a String, but %v given.",
  38091. cond.flags
  38092. );
  38093. opConds.push({ $regex: stringToRegexp(cond.regexp, flags) });
  38094. }
  38095. if (opConds.length === 1) {
  38096. query[key] = opConds[0];
  38097. } else if (opConds.length > 1) {
  38098. query["$and"] = query["$and"] ?? [];
  38099. opConds.forEach((c) => query["$and"].push({ [key]: c }));
  38100. }
  38101. return;
  38102. }
  38103. query[key] = cond;
  38104. });
  38105. return Object.keys(query).length ? query : void 0;
  38106. }
  38107. /**
  38108. * Create.
  38109. *
  38110. * @param {string} modelName
  38111. * @param {object} modelData
  38112. * @param {object|undefined} filter
  38113. * @return {Promise<object>}
  38114. */
  38115. async create(modelName, modelData, filter = void 0) {
  38116. const idPropName = this._getIdPropName(modelName);
  38117. const idValue = modelData[idPropName];
  38118. if (idValue == null || idValue === "" || idValue === 0) {
  38119. const pkType = this._getIdType(modelName);
  38120. if (pkType !== DataType.STRING && pkType !== DataType.ANY)
  38121. throw new InvalidArgumentError2(
  38122. "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
  38123. capitalize(pkType),
  38124. idPropName
  38125. );
  38126. delete modelData[idPropName];
  38127. }
  38128. const tableData = this._toDatabase(modelName, modelData);
  38129. const table = this._getCollection(modelName);
  38130. const { insertedId } = await table.insertOne(tableData);
  38131. const projection = this._buildProjection(
  38132. modelName,
  38133. filter && filter.fields
  38134. );
  38135. const insertedData = await table.findOne({ _id: insertedId }, { projection });
  38136. return this._fromDatabase(modelName, insertedData);
  38137. }
  38138. /**
  38139. * Replace by id.
  38140. *
  38141. * @param {string} modelName
  38142. * @param {string|number} id
  38143. * @param {object} modelData
  38144. * @param {object|undefined} filter
  38145. * @return {Promise<object>}
  38146. */
  38147. async replaceById(modelName, id, modelData, filter = void 0) {
  38148. id = this._coerceId(id);
  38149. const idPropName = this._getIdPropName(modelName);
  38150. modelData[idPropName] = id;
  38151. const tableData = this._toDatabase(modelName, modelData);
  38152. const table = this._getCollection(modelName);
  38153. const { matchedCount } = await table.replaceOne({ _id: id }, tableData);
  38154. if (matchedCount < 1)
  38155. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38156. const projection = this._buildProjection(
  38157. modelName,
  38158. filter && filter.fields
  38159. );
  38160. const replacedData = await table.findOne({ _id: id }, { projection });
  38161. return this._fromDatabase(modelName, replacedData);
  38162. }
  38163. /**
  38164. * Replace or create.
  38165. *
  38166. * @param {string} modelName
  38167. * @param {object} modelData
  38168. * @param {object|undefined} filter
  38169. * @return {Promise<object>}
  38170. */
  38171. async replaceOrCreate(modelName, modelData, filter = void 0) {
  38172. const idPropName = this._getIdPropName(modelName);
  38173. let idValue = modelData[idPropName];
  38174. idValue = this._coerceId(idValue);
  38175. if (idValue == null || idValue === "" || idValue === 0) {
  38176. const pkType = this._getIdType(modelName);
  38177. if (pkType !== DataType.STRING && pkType !== DataType.ANY)
  38178. throw new InvalidArgumentError2(
  38179. "MongoDB unable to generate primary keys of %s. Do provide your own value for the %v property or set property type to String.",
  38180. capitalize(pkType),
  38181. idPropName
  38182. );
  38183. delete modelData[idPropName];
  38184. idValue = void 0;
  38185. }
  38186. const tableData = this._toDatabase(modelName, modelData);
  38187. const table = this._getCollection(modelName);
  38188. if (idValue == null) {
  38189. const { insertedId } = await table.insertOne(tableData);
  38190. idValue = insertedId;
  38191. } else {
  38192. const { upsertedId } = await table.replaceOne({ _id: idValue }, tableData, {
  38193. upsert: true
  38194. });
  38195. if (upsertedId) idValue = upsertedId;
  38196. }
  38197. const projection = this._buildProjection(
  38198. modelName,
  38199. filter && filter.fields
  38200. );
  38201. const upsertedData = await table.findOne({ _id: idValue }, { projection });
  38202. return this._fromDatabase(modelName, upsertedData);
  38203. }
  38204. /**
  38205. * Patch.
  38206. *
  38207. * @param {string} modelName
  38208. * @param {object} modelData
  38209. * @param {object|undefined} where
  38210. * @return {Promise<number>}
  38211. */
  38212. async patch(modelName, modelData, where = void 0) {
  38213. const idPropName = this._getIdPropName(modelName);
  38214. delete modelData[idPropName];
  38215. const query = this._buildQuery(modelName, where) || {};
  38216. const tableData = this._toDatabase(modelName, modelData);
  38217. const table = this._getCollection(modelName);
  38218. const { matchedCount } = await table.updateMany(query, { $set: tableData });
  38219. return matchedCount;
  38220. }
  38221. /**
  38222. * Patch by id.
  38223. *
  38224. * @param {string} modelName
  38225. * @param {string|number} id
  38226. * @param {object} modelData
  38227. * @param {object|undefined} filter
  38228. * @return {Promise<object>}
  38229. */
  38230. async patchById(modelName, id, modelData, filter = void 0) {
  38231. id = this._coerceId(id);
  38232. const idPropName = this._getIdPropName(modelName);
  38233. delete modelData[idPropName];
  38234. const tableData = this._toDatabase(modelName, modelData);
  38235. const table = this._getCollection(modelName);
  38236. const { matchedCount } = await table.updateOne({ _id: id }, { $set: tableData });
  38237. if (matchedCount < 1)
  38238. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38239. const projection = this._buildProjection(
  38240. modelName,
  38241. filter && filter.fields
  38242. );
  38243. const patchedData = await table.findOne({ _id: id }, { projection });
  38244. return this._fromDatabase(modelName, patchedData);
  38245. }
  38246. /**
  38247. * Find.
  38248. *
  38249. * @param {string} modelName
  38250. * @param {object|undefined} filter
  38251. * @return {Promise<object[]>}
  38252. */
  38253. async find(modelName, filter = void 0) {
  38254. filter = filter || {};
  38255. const query = this._buildQuery(modelName, filter.where);
  38256. const sort = this._buildSort(modelName, filter.order);
  38257. const limit = filter.limit || void 0;
  38258. const skip = filter.skip || void 0;
  38259. const projection = this._buildProjection(modelName, filter.fields);
  38260. const collection = this._getCollection(modelName);
  38261. const options = { sort, limit, skip, projection };
  38262. const tableItems = await collection.find(query, options).toArray();
  38263. return tableItems.map((v) => this._fromDatabase(modelName, v));
  38264. }
  38265. /**
  38266. * Find by id.
  38267. *
  38268. * @param {string} modelName
  38269. * @param {string|number} id
  38270. * @param {object|undefined} filter
  38271. * @return {Promise<object>}
  38272. */
  38273. async findById(modelName, id, filter = void 0) {
  38274. id = this._coerceId(id);
  38275. const table = this._getCollection(modelName);
  38276. const projection = this._buildProjection(
  38277. modelName,
  38278. filter && filter.fields
  38279. );
  38280. const patchedData = await table.findOne({ _id: id }, { projection });
  38281. if (!patchedData)
  38282. throw new InvalidArgumentError2("Identifier %v is not found.", String(id));
  38283. return this._fromDatabase(modelName, patchedData);
  38284. }
  38285. /**
  38286. * Delete.
  38287. *
  38288. * @param {string} modelName
  38289. * @param {object|undefined} where
  38290. * @return {Promise<number>}
  38291. */
  38292. async delete(modelName, where = void 0) {
  38293. const table = this._getCollection(modelName);
  38294. const query = this._buildQuery(modelName, where);
  38295. const { deletedCount } = await table.deleteMany(query);
  38296. return deletedCount;
  38297. }
  38298. /**
  38299. * Delete by id.
  38300. *
  38301. * @param {string} modelName
  38302. * @param {string|number} id
  38303. * @return {Promise<boolean>}
  38304. */
  38305. async deleteById(modelName, id) {
  38306. id = this._coerceId(id);
  38307. const table = this._getCollection(modelName);
  38308. const { deletedCount } = await table.deleteOne({ _id: id });
  38309. return deletedCount > 0;
  38310. }
  38311. /**
  38312. * Exists.
  38313. *
  38314. * @param {string} modelName
  38315. * @param {string|number} id
  38316. * @return {Promise<boolean>}
  38317. */
  38318. async exists(modelName, id) {
  38319. id = this._coerceId(id);
  38320. const table = this._getCollection(modelName);
  38321. const result = await table.findOne({ _id: id }, {});
  38322. return result != null;
  38323. }
  38324. /**
  38325. * Count.
  38326. *
  38327. * @param {string} modelName
  38328. * @param {object|undefined} where
  38329. * @return {Promise<number>}
  38330. */
  38331. async count(modelName, where = void 0) {
  38332. const query = this._buildQuery(modelName, where);
  38333. const table = this._getCollection(modelName);
  38334. return await table.count(query);
  38335. }
  38336. };
  38337. // Annotate the CommonJS export names for ESM import in node:
  38338. 0 && (module.exports = {
  38339. MongodbAdapter
  38340. });