ajv.bundle.js 270 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023
  1. (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Ajv = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. module.exports = {
  4. setup: setupAsync,
  5. compile: compileAsync
  6. };
  7. var util = require('./compile/util');
  8. var ASYNC = {
  9. '*': checkGenerators,
  10. 'co*': checkGenerators,
  11. 'es7': checkAsyncFunction
  12. };
  13. var TRANSPILE = {
  14. 'nodent': getNodent,
  15. 'regenerator': getRegenerator
  16. };
  17. var MODES = [
  18. { async: 'co*' },
  19. { async: 'es7', transpile: 'nodent' },
  20. { async: 'co*', transpile: 'regenerator' }
  21. ];
  22. var regenerator, nodent;
  23. function setupAsync(opts, required) {
  24. if (required !== false) required = true;
  25. var async = opts.async
  26. , transpile = opts.transpile
  27. , check;
  28. switch (typeof transpile) {
  29. case 'string':
  30. var get = TRANSPILE[transpile];
  31. if (!get) throw new Error('bad transpiler: ' + transpile);
  32. return (opts._transpileFunc = get(opts, required));
  33. case 'undefined':
  34. case 'boolean':
  35. if (typeof async == 'string') {
  36. check = ASYNC[async];
  37. if (!check) throw new Error('bad async mode: ' + async);
  38. return (opts.transpile = check(opts, required));
  39. }
  40. for (var i=0; i<MODES.length; i++) {
  41. var _opts = MODES[i];
  42. if (setupAsync(_opts, false)) {
  43. util.copy(_opts, opts);
  44. return opts.transpile;
  45. }
  46. }
  47. /* istanbul ignore next */
  48. throw new Error('generators, nodent and regenerator are not available');
  49. case 'function':
  50. return (opts._transpileFunc = opts.transpile);
  51. default:
  52. throw new Error('bad transpiler: ' + transpile);
  53. }
  54. }
  55. function checkGenerators(opts, required) {
  56. /* jshint evil: true */
  57. try {
  58. (new Function('(function*(){})()'))();
  59. return true;
  60. } catch(e) {
  61. /* istanbul ignore next */
  62. if (required) throw new Error('generators not supported');
  63. }
  64. }
  65. function checkAsyncFunction(opts, required) {
  66. /* jshint evil: true */
  67. try {
  68. (new Function('(async function(){})()'))();
  69. /* istanbul ignore next */
  70. return true;
  71. } catch(e) {
  72. if (required) throw new Error('es7 async functions not supported');
  73. }
  74. }
  75. function getRegenerator(opts, required) {
  76. try {
  77. if (!regenerator) {
  78. var name = 'regenerator';
  79. regenerator = require(name);
  80. regenerator.runtime();
  81. }
  82. if (!opts.async || opts.async === true)
  83. opts.async = 'es7';
  84. return regeneratorTranspile;
  85. } catch(e) {
  86. /* istanbul ignore next */
  87. if (required) throw new Error('regenerator not available');
  88. }
  89. }
  90. function regeneratorTranspile(code) {
  91. return regenerator.compile(code).code;
  92. }
  93. function getNodent(opts, required) {
  94. /* jshint evil: true */
  95. try {
  96. if (!nodent) {
  97. var name = 'nodent';
  98. nodent = require(name)({ log: false, dontInstallRequireHook: true });
  99. }
  100. if (opts.async != 'es7') {
  101. if (opts.async && opts.async !== true) console.warn('nodent transpiles only es7 async functions');
  102. opts.async = 'es7';
  103. }
  104. return nodentTranspile;
  105. } catch(e) {
  106. /* istanbul ignore next */
  107. if (required) throw new Error('nodent not available');
  108. }
  109. }
  110. function nodentTranspile(code) {
  111. return nodent.compile(code, '', { promises: true, sourcemap: false }).code;
  112. }
  113. /**
  114. * Creates validating function for passed schema with asynchronous loading of missing schemas.
  115. * `loadSchema` option should be a function that accepts schema uri and node-style callback.
  116. * @this Ajv
  117. * @param {Object} schema schema object
  118. * @param {Function} callback node-style callback, it is always called with 2 parameters: error (or null) and validating function.
  119. */
  120. function compileAsync(schema, callback) {
  121. /* eslint no-shadow: 0 */
  122. /* jshint validthis: true */
  123. var schemaObj;
  124. var self = this;
  125. try {
  126. schemaObj = this._addSchema(schema);
  127. } catch(e) {
  128. setTimeout(function() { callback(e); });
  129. return;
  130. }
  131. if (schemaObj.validate) {
  132. setTimeout(function() { callback(null, schemaObj.validate); });
  133. } else {
  134. if (typeof this._opts.loadSchema != 'function')
  135. throw new Error('options.loadSchema should be a function');
  136. _compileAsync(schema, callback, true);
  137. }
  138. function _compileAsync(schema, callback, firstCall) {
  139. var validate;
  140. try { validate = self.compile(schema); }
  141. catch(e) {
  142. if (e.missingSchema) loadMissingSchema(e);
  143. else deferCallback(e);
  144. return;
  145. }
  146. deferCallback(null, validate);
  147. function loadMissingSchema(e) {
  148. var ref = e.missingSchema;
  149. if (self._refs[ref] || self._schemas[ref])
  150. return callback(new Error('Schema ' + ref + ' is loaded but ' + e.missingRef + ' cannot be resolved'));
  151. var _callbacks = self._loadingSchemas[ref];
  152. if (_callbacks) {
  153. if (typeof _callbacks == 'function')
  154. self._loadingSchemas[ref] = [_callbacks, schemaLoaded];
  155. else
  156. _callbacks[_callbacks.length] = schemaLoaded;
  157. } else {
  158. self._loadingSchemas[ref] = schemaLoaded;
  159. self._opts.loadSchema(ref, function (err, sch) {
  160. var _callbacks = self._loadingSchemas[ref];
  161. delete self._loadingSchemas[ref];
  162. if (typeof _callbacks == 'function') {
  163. _callbacks(err, sch);
  164. } else {
  165. for (var i=0; i<_callbacks.length; i++)
  166. _callbacks[i](err, sch);
  167. }
  168. });
  169. }
  170. function schemaLoaded(err, sch) {
  171. if (err) return callback(err);
  172. if (!(self._refs[ref] || self._schemas[ref])) {
  173. try {
  174. self.addSchema(sch, ref);
  175. } catch(e) {
  176. callback(e);
  177. return;
  178. }
  179. }
  180. _compileAsync(schema, callback);
  181. }
  182. }
  183. function deferCallback(err, validate) {
  184. if (firstCall) setTimeout(function() { callback(err, validate); });
  185. else return callback(err, validate);
  186. }
  187. }
  188. }
  189. },{"./compile/util":11}],2:[function(require,module,exports){
  190. 'use strict';
  191. var Cache = module.exports = function Cache() {
  192. this._cache = {};
  193. };
  194. Cache.prototype.put = function Cache_put(key, value) {
  195. this._cache[key] = value;
  196. };
  197. Cache.prototype.get = function Cache_get(key) {
  198. return this._cache[key];
  199. };
  200. Cache.prototype.del = function Cache_del(key) {
  201. delete this._cache[key];
  202. };
  203. Cache.prototype.clear = function Cache_clear() {
  204. this._cache = {};
  205. };
  206. },{}],3:[function(require,module,exports){
  207. 'use strict';
  208. //all requires must be explicit because browserify won't work with dynamic requires
  209. module.exports = {
  210. '$ref': require('../dotjs/ref'),
  211. allOf: require('../dotjs/allOf'),
  212. anyOf: require('../dotjs/anyOf'),
  213. dependencies: require('../dotjs/dependencies'),
  214. 'enum': require('../dotjs/enum'),
  215. format: require('../dotjs/format'),
  216. items: require('../dotjs/items'),
  217. maximum: require('../dotjs/_limit'),
  218. minimum: require('../dotjs/_limit'),
  219. maxItems: require('../dotjs/_limitItems'),
  220. minItems: require('../dotjs/_limitItems'),
  221. maxLength: require('../dotjs/_limitLength'),
  222. minLength: require('../dotjs/_limitLength'),
  223. maxProperties: require('../dotjs/_limitProperties'),
  224. minProperties: require('../dotjs/_limitProperties'),
  225. multipleOf: require('../dotjs/multipleOf'),
  226. not: require('../dotjs/not'),
  227. oneOf: require('../dotjs/oneOf'),
  228. pattern: require('../dotjs/pattern'),
  229. properties: require('../dotjs/properties'),
  230. required: require('../dotjs/required'),
  231. uniqueItems: require('../dotjs/uniqueItems'),
  232. validate: require('../dotjs/validate')
  233. };
  234. },{"../dotjs/_limit":14,"../dotjs/_limitItems":15,"../dotjs/_limitLength":16,"../dotjs/_limitProperties":17,"../dotjs/allOf":18,"../dotjs/anyOf":19,"../dotjs/dependencies":22,"../dotjs/enum":23,"../dotjs/format":24,"../dotjs/items":25,"../dotjs/multipleOf":26,"../dotjs/not":27,"../dotjs/oneOf":28,"../dotjs/pattern":29,"../dotjs/properties":31,"../dotjs/ref":32,"../dotjs/required":33,"../dotjs/uniqueItems":35,"../dotjs/validate":36}],4:[function(require,module,exports){
  235. 'use strict';
  236. /*eslint complexity: 0*/
  237. module.exports = function equal(a, b) {
  238. if (a === b) return true;
  239. var arrA = Array.isArray(a)
  240. , arrB = Array.isArray(b)
  241. , i;
  242. if (arrA && arrB) {
  243. if (a.length != b.length) return false;
  244. for (i = 0; i < a.length; i++)
  245. if (!equal(a[i], b[i])) return false;
  246. return true;
  247. }
  248. if (arrA != arrB) return false;
  249. if (a && b && typeof a === 'object' && typeof b === 'object') {
  250. var keys = Object.keys(a);
  251. if (keys.length !== Object.keys(b).length) return false;
  252. var dateA = a instanceof Date
  253. , dateB = b instanceof Date;
  254. if (dateA && dateB) return a.getTime() == b.getTime();
  255. if (dateA != dateB) return false;
  256. var regexpA = a instanceof RegExp
  257. , regexpB = b instanceof RegExp;
  258. if (regexpA && regexpB) return a.toString() == b.toString();
  259. if (regexpA != regexpB) return false;
  260. for (i = 0; i < keys.length; i++)
  261. if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
  262. for (i = 0; i < keys.length; i++)
  263. if(!equal(a[keys[i]], b[keys[i]])) return false;
  264. return true;
  265. }
  266. return false;
  267. };
  268. },{}],5:[function(require,module,exports){
  269. 'use strict';
  270. var util = require('./util');
  271. var DATE = /^\d\d\d\d-(\d\d)-(\d\d)$/;
  272. var DAYS = [0,31,29,31,30,31,30,31,31,30,31,30,31];
  273. var TIME = /^(\d\d):(\d\d):(\d\d)(\.\d+)?(z|[+-]\d\d:\d\d)?$/i;
  274. var HOSTNAME = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[-0-9a-z]{0,61}[0-9a-z])?)*$/i;
  275. var URI = /^(?:[a-z][a-z0-9+\-.]*:)?(?:\/?\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:]|%[0-9a-f]{2})*@)?(?:\[(?:(?:(?:(?:[0-9a-f]{1,4}:){6}|::(?:[0-9a-f]{1,4}:){5}|(?:[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){4}|(?:(?:[0-9a-f]{1,4}:){0,1}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){3}|(?:(?:[0-9a-f]{1,4}:){0,2}[0-9a-f]{1,4})?::(?:[0-9a-f]{1,4}:){2}|(?:(?:[0-9a-f]{1,4}:){0,3}[0-9a-f]{1,4})?::[0-9a-f]{1,4}:|(?:(?:[0-9a-f]{1,4}:){0,4}[0-9a-f]{1,4})?::)(?:[0-9a-f]{1,4}:[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?))|(?:(?:[0-9a-f]{1,4}:){0,5}[0-9a-f]{1,4})?::[0-9a-f]{1,4}|(?:(?:[0-9a-f]{1,4}:){0,6}[0-9a-f]{1,4})?::)|[Vv][0-9a-f]+\.[a-z0-9\-._~!$&'()*+,;=:]+)\]|(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)|(?:[a-z0-9\-._~!$&'()*+,;=]|%[0-9a-f]{2})*)(?::\d*)?(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*|\/(?:(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)?|(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})+(?:\/(?:[a-z0-9\-._~!$&'()*+,;=:@]|%[0-9a-f]{2})*)*)(?:\?(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?(?:\#(?:[a-z0-9\-._~!$&'()*+,;=:@\/?]|%[0-9a-f]{2})*)?$/i;
  276. var UUID = /^(?:urn\:uuid\:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
  277. var JSON_POINTER = /^(?:\/(?:[^~\/]|~0|~1)*)*$|^\#(?:\/(?:[a-z0-9_\-\.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
  278. var RELATIVE_JSON_POINTER = /^(?:0|[1-9][0-9]*)(?:\#|(?:\/(?:[^~\/]|~0|~1)*)*)$/;
  279. module.exports = formats;
  280. function formats(mode) {
  281. mode = mode == 'full' ? 'full' : 'fast';
  282. var formatDefs = util.copy(formats[mode]);
  283. for (var fName in formats.compare) {
  284. formatDefs[fName] = {
  285. validate: formatDefs[fName],
  286. compare: formats.compare[fName]
  287. };
  288. }
  289. return formatDefs;
  290. }
  291. formats.fast = {
  292. // date: http://tools.ietf.org/html/rfc3339#section-5.6
  293. date: /^\d\d\d\d-[0-1]\d-[0-3]\d$/,
  294. // date-time: http://tools.ietf.org/html/rfc3339#section-5.6
  295. time: /^[0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)?$/i,
  296. 'date-time': /^\d\d\d\d-[0-1]\d-[0-3]\d[t\s][0-2]\d:[0-5]\d:[0-5]\d(?:\.\d+)?(?:z|[+-]\d\d:\d\d)$/i,
  297. // uri: https://github.com/mafintosh/is-my-json-valid/blob/master/formats.js
  298. uri: /^(?:[a-z][a-z0-9+-.]*)?(?:\:|\/)\/?[^\s]*$/i,
  299. // email (sources from jsen validator):
  300. // http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address#answer-8829363
  301. // http://www.w3.org/TR/html5/forms.html#valid-e-mail-address (search for 'willful violation')
  302. email: /^[a-z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*$/i,
  303. hostname: HOSTNAME,
  304. // optimized https://www.safaribooksonline.com/library/view/regular-expressions-cookbook/9780596802837/ch07s16.html
  305. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  306. // optimized http://stackoverflow.com/questions/53497/regular-expression-that-matches-valid-ipv6-addresses
  307. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  308. regex: regex,
  309. // uuid: http://tools.ietf.org/html/rfc4122
  310. uuid: UUID,
  311. // JSON-pointer: https://tools.ietf.org/html/rfc6901
  312. // uri fragment: https://tools.ietf.org/html/rfc3986#appendix-A
  313. 'json-pointer': JSON_POINTER,
  314. // relative JSON-pointer: http://tools.ietf.org/html/draft-luff-relative-json-pointer-00
  315. 'relative-json-pointer': RELATIVE_JSON_POINTER
  316. };
  317. formats.full = {
  318. date: date,
  319. time: time,
  320. 'date-time': date_time,
  321. uri: uri,
  322. email: /^[a-z0-9!#$%&'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i,
  323. hostname: hostname,
  324. ipv4: /^(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)$/,
  325. ipv6: /^\s*(?:(?:(?:[0-9a-f]{1,4}:){7}(?:[0-9a-f]{1,4}|:))|(?:(?:[0-9a-f]{1,4}:){6}(?::[0-9a-f]{1,4}|(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){5}(?:(?:(?::[0-9a-f]{1,4}){1,2})|:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(?:(?:[0-9a-f]{1,4}:){4}(?:(?:(?::[0-9a-f]{1,4}){1,3})|(?:(?::[0-9a-f]{1,4})?:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){3}(?:(?:(?::[0-9a-f]{1,4}){1,4})|(?:(?::[0-9a-f]{1,4}){0,2}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){2}(?:(?:(?::[0-9a-f]{1,4}){1,5})|(?:(?::[0-9a-f]{1,4}){0,3}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?:(?:[0-9a-f]{1,4}:){1}(?:(?:(?::[0-9a-f]{1,4}){1,6})|(?:(?::[0-9a-f]{1,4}){0,4}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(?::(?:(?:(?::[0-9a-f]{1,4}){1,7})|(?:(?::[0-9a-f]{1,4}){0,5}:(?:(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(?:%.+)?\s*$/i,
  326. regex: regex,
  327. uuid: UUID,
  328. 'json-pointer': JSON_POINTER,
  329. 'relative-json-pointer': RELATIVE_JSON_POINTER
  330. };
  331. formats.compare = {
  332. date: compareDate,
  333. time: compareTime,
  334. 'date-time': compareDateTime
  335. };
  336. function date(str) {
  337. // full-date from http://tools.ietf.org/html/rfc3339#section-5.6
  338. var matches = str.match(DATE);
  339. if (!matches) return false;
  340. var month = +matches[1];
  341. var day = +matches[2];
  342. return month >= 1 && month <= 12 && day >= 1 && day <= DAYS[month];
  343. }
  344. function time(str, full) {
  345. var matches = str.match(TIME);
  346. if (!matches) return false;
  347. var hour = matches[1];
  348. var minute = matches[2];
  349. var second = matches[3];
  350. var timeZone = matches[5];
  351. return hour <= 23 && minute <= 59 && second <= 59 && (!full || timeZone);
  352. }
  353. var DATE_TIME_SEPARATOR = /t|\s/i;
  354. function date_time(str) {
  355. // http://tools.ietf.org/html/rfc3339#section-5.6
  356. var dateTime = str.split(DATE_TIME_SEPARATOR);
  357. return dateTime.length == 2 && date(dateTime[0]) && time(dateTime[1], true);
  358. }
  359. function hostname(str) {
  360. // https://tools.ietf.org/html/rfc1034#section-3.5
  361. // https://tools.ietf.org/html/rfc1123#section-2
  362. return str.length <= 255 && HOSTNAME.test(str);
  363. }
  364. var NOT_URI_FRAGMENT = /\/|\:/;
  365. function uri(str) {
  366. // http://jmrware.com/articles/2009/uri_regexp/URI_regex.html + optional protocol + required "."
  367. return NOT_URI_FRAGMENT.test(str) && URI.test(str);
  368. }
  369. function regex(str) {
  370. try {
  371. new RegExp(str);
  372. return true;
  373. } catch(e) {
  374. return false;
  375. }
  376. }
  377. function compareDate(d1, d2) {
  378. if (!(d1 && d2)) return;
  379. if (d1 > d2) return 1;
  380. if (d1 < d2) return -1;
  381. if (d1 === d2) return 0;
  382. }
  383. function compareTime(t1, t2) {
  384. if (!(t1 && t2)) return;
  385. t1 = t1.match(TIME);
  386. t2 = t2.match(TIME);
  387. if (!(t1 && t2)) return;
  388. t1 = t1[1] + t1[2] + t1[3] + (t1[4]||'');
  389. t2 = t2[1] + t2[2] + t2[3] + (t2[4]||'');
  390. if (t1 > t2) return 1;
  391. if (t1 < t2) return -1;
  392. if (t1 === t2) return 0;
  393. }
  394. function compareDateTime(dt1, dt2) {
  395. if (!(dt1 && dt2)) return;
  396. dt1 = dt1.split(DATE_TIME_SEPARATOR);
  397. dt2 = dt2.split(DATE_TIME_SEPARATOR);
  398. var res = compareDate(dt1[0], dt2[0]);
  399. if (res === undefined) return;
  400. return res || compareTime(dt1[1], dt2[1]);
  401. }
  402. },{"./util":11}],6:[function(require,module,exports){
  403. 'use strict';
  404. var resolve = require('./resolve')
  405. , util = require('./util')
  406. , stableStringify = require('json-stable-stringify')
  407. , async = require('../async');
  408. var beautify;
  409. function loadBeautify(){
  410. if (beautify === undefined) {
  411. var name = 'js-beautify';
  412. try { beautify = require(name).js_beautify; }
  413. catch(e) { beautify = false; }
  414. }
  415. }
  416. var validateGenerator = require('../dotjs/validate');
  417. /**
  418. * Functions below are used inside compiled validations function
  419. */
  420. var co = require('co');
  421. var ucs2length = util.ucs2length;
  422. var equal = require('./equal');
  423. // this error is thrown by async schemas to return validation errors via exception
  424. var ValidationError = require('./validation_error');
  425. module.exports = compile;
  426. /**
  427. * Compiles schema to validation function
  428. * @this Ajv
  429. * @param {Object} schema schema object
  430. * @param {Object} root object with information about the root schema for this schema
  431. * @param {Object} localRefs the hash of local references inside the schema (created by resolve.id), used for inline resolution
  432. * @param {String} baseId base ID for IDs in the schema
  433. * @return {Function} validation function
  434. */
  435. function compile(schema, root, localRefs, baseId) {
  436. /* jshint validthis: true, evil: true */
  437. /* eslint no-shadow: 0 */
  438. var self = this
  439. , opts = this._opts
  440. , refVal = [ undefined ]
  441. , refs = {}
  442. , patterns = []
  443. , patternsHash = {}
  444. , defaults = []
  445. , defaultsHash = {}
  446. , customRules = []
  447. , keepSourceCode = opts.sourceCode !== false;
  448. root = root || { schema: schema, refVal: refVal, refs: refs };
  449. var c = checkCompiling.call(this, schema, root, baseId);
  450. var compilation = this._compilations[c.index];
  451. if (c.compiling) return (compilation.callValidate = callValidate);
  452. var formats = this._formats;
  453. var RULES = this.RULES;
  454. try {
  455. var v = localCompile(schema, root, localRefs, baseId);
  456. compilation.validate = v;
  457. var cv = compilation.callValidate;
  458. if (cv) {
  459. cv.schema = v.schema;
  460. cv.errors = null;
  461. cv.refs = v.refs;
  462. cv.refVal = v.refVal;
  463. cv.root = v.root;
  464. cv.$async = v.$async;
  465. if (keepSourceCode) cv.sourceCode = v.sourceCode;
  466. }
  467. return v;
  468. } finally {
  469. endCompiling.call(this, schema, root, baseId);
  470. }
  471. function callValidate() {
  472. var validate = compilation.validate;
  473. var result = validate.apply(null, arguments);
  474. callValidate.errors = validate.errors;
  475. return result;
  476. }
  477. function localCompile(_schema, _root, localRefs, baseId) {
  478. var isRoot = !_root || (_root && _root.schema == _schema);
  479. if (_root.schema != root.schema)
  480. return compile.call(self, _schema, _root, localRefs, baseId);
  481. var $async = _schema.$async === true;
  482. if ($async && !opts.transpile) async.setup(opts);
  483. var sourceCode = validateGenerator({
  484. isTop: true,
  485. schema: _schema,
  486. isRoot: isRoot,
  487. baseId: baseId,
  488. root: _root,
  489. schemaPath: '',
  490. errSchemaPath: '#',
  491. errorPath: '""',
  492. RULES: RULES,
  493. validate: validateGenerator,
  494. util: util,
  495. resolve: resolve,
  496. resolveRef: resolveRef,
  497. usePattern: usePattern,
  498. useDefault: useDefault,
  499. useCustomRule: useCustomRule,
  500. opts: opts,
  501. formats: formats,
  502. self: self
  503. });
  504. sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode)
  505. + vars(defaults, defaultCode) + vars(customRules, customRuleCode)
  506. + sourceCode;
  507. if (opts.beautify) {
  508. loadBeautify();
  509. /* istanbul ignore else */
  510. if (beautify) sourceCode = beautify(sourceCode, opts.beautify);
  511. else console.error('"npm install js-beautify" to use beautify option');
  512. }
  513. // console.log('\n\n\n *** \n', sourceCode);
  514. var validate, validateCode
  515. , transpile = opts._transpileFunc;
  516. try {
  517. validateCode = $async && transpile
  518. ? transpile(sourceCode)
  519. : sourceCode;
  520. var makeValidate = new Function(
  521. 'self',
  522. 'RULES',
  523. 'formats',
  524. 'root',
  525. 'refVal',
  526. 'defaults',
  527. 'customRules',
  528. 'co',
  529. 'equal',
  530. 'ucs2length',
  531. 'ValidationError',
  532. validateCode
  533. );
  534. validate = makeValidate(
  535. self,
  536. RULES,
  537. formats,
  538. root,
  539. refVal,
  540. defaults,
  541. customRules,
  542. co,
  543. equal,
  544. ucs2length,
  545. ValidationError
  546. );
  547. refVal[0] = validate;
  548. } catch(e) {
  549. console.error('Error compiling schema, function code:', validateCode);
  550. throw e;
  551. }
  552. validate.schema = _schema;
  553. validate.errors = null;
  554. validate.refs = refs;
  555. validate.refVal = refVal;
  556. validate.root = isRoot ? validate : _root;
  557. if ($async) validate.$async = true;
  558. if (keepSourceCode) validate.sourceCode = sourceCode;
  559. if (opts.sourceCode === true) {
  560. validate.source = {
  561. patterns: patterns,
  562. defaults: defaults
  563. };
  564. }
  565. return validate;
  566. }
  567. function resolveRef(baseId, ref, isRoot) {
  568. ref = resolve.url(baseId, ref);
  569. var refIndex = refs[ref];
  570. var _refVal, refCode;
  571. if (refIndex !== undefined) {
  572. _refVal = refVal[refIndex];
  573. refCode = 'refVal[' + refIndex + ']';
  574. return resolvedRef(_refVal, refCode);
  575. }
  576. if (!isRoot && root.refs) {
  577. var rootRefId = root.refs[ref];
  578. if (rootRefId !== undefined) {
  579. _refVal = root.refVal[rootRefId];
  580. refCode = addLocalRef(ref, _refVal);
  581. return resolvedRef(_refVal, refCode);
  582. }
  583. }
  584. refCode = addLocalRef(ref);
  585. var v = resolve.call(self, localCompile, root, ref);
  586. if (!v) {
  587. var localSchema = localRefs && localRefs[ref];
  588. if (localSchema) {
  589. v = resolve.inlineRef(localSchema, opts.inlineRefs)
  590. ? localSchema
  591. : compile.call(self, localSchema, root, localRefs, baseId);
  592. }
  593. }
  594. if (v) {
  595. replaceLocalRef(ref, v);
  596. return resolvedRef(v, refCode);
  597. }
  598. }
  599. function addLocalRef(ref, v) {
  600. var refId = refVal.length;
  601. refVal[refId] = v;
  602. refs[ref] = refId;
  603. return 'refVal' + refId;
  604. }
  605. function replaceLocalRef(ref, v) {
  606. var refId = refs[ref];
  607. refVal[refId] = v;
  608. }
  609. function resolvedRef(refVal, code) {
  610. return typeof refVal == 'object'
  611. ? { code: code, schema: refVal, inline: true }
  612. : { code: code, $async: refVal && refVal.$async };
  613. }
  614. function usePattern(regexStr) {
  615. var index = patternsHash[regexStr];
  616. if (index === undefined) {
  617. index = patternsHash[regexStr] = patterns.length;
  618. patterns[index] = regexStr;
  619. }
  620. return 'pattern' + index;
  621. }
  622. function useDefault(value) {
  623. switch (typeof value) {
  624. case 'boolean':
  625. case 'number':
  626. return '' + value;
  627. case 'string':
  628. return util.toQuotedString(value);
  629. case 'object':
  630. if (value === null) return 'null';
  631. var valueStr = stableStringify(value);
  632. var index = defaultsHash[valueStr];
  633. if (index === undefined) {
  634. index = defaultsHash[valueStr] = defaults.length;
  635. defaults[index] = value;
  636. }
  637. return 'default' + index;
  638. }
  639. }
  640. function useCustomRule(rule, schema, parentSchema, it) {
  641. var validateSchema = rule.definition.validateSchema;
  642. if (validateSchema && self._opts.validateSchema !== false) {
  643. var valid = validateSchema(schema);
  644. if (!valid) {
  645. var message = 'keyword schema is invalid: ' + self.errorsText(validateSchema.errors);
  646. if (self._opts.validateSchema == 'log') console.error(message);
  647. else throw new Error(message);
  648. }
  649. }
  650. var compile = rule.definition.compile
  651. , inline = rule.definition.inline
  652. , macro = rule.definition.macro;
  653. var validate;
  654. if (compile) {
  655. validate = compile.call(self, schema, parentSchema, it);
  656. } else if (macro) {
  657. validate = macro.call(self, schema, parentSchema, it);
  658. if (opts.validateSchema !== false) self.validateSchema(validate, true);
  659. } else if (inline) {
  660. validate = inline.call(self, it, rule.keyword, schema, parentSchema);
  661. } else {
  662. validate = rule.definition.validate;
  663. }
  664. var index = customRules.length;
  665. customRules[index] = validate;
  666. return {
  667. code: 'customRule' + index,
  668. validate: validate
  669. };
  670. }
  671. }
  672. /**
  673. * Checks if the schema is currently compiled
  674. * @this Ajv
  675. * @param {Object} schema schema to compile
  676. * @param {Object} root root object
  677. * @param {String} baseId base schema ID
  678. * @return {Object} object with properties "index" (compilation index) and "compiling" (boolean)
  679. */
  680. function checkCompiling(schema, root, baseId) {
  681. /* jshint validthis: true */
  682. var index = compIndex.call(this, schema, root, baseId);
  683. if (index >= 0) return { index: index, compiling: true };
  684. index = this._compilations.length;
  685. this._compilations[index] = {
  686. schema: schema,
  687. root: root,
  688. baseId: baseId
  689. };
  690. return { index: index, compiling: false };
  691. }
  692. /**
  693. * Removes the schema from the currently compiled list
  694. * @this Ajv
  695. * @param {Object} schema schema to compile
  696. * @param {Object} root root object
  697. * @param {String} baseId base schema ID
  698. */
  699. function endCompiling(schema, root, baseId) {
  700. /* jshint validthis: true */
  701. var i = compIndex.call(this, schema, root, baseId);
  702. if (i >= 0) this._compilations.splice(i, 1);
  703. }
  704. /**
  705. * Index of schema compilation in the currently compiled list
  706. * @this Ajv
  707. * @param {Object} schema schema to compile
  708. * @param {Object} root root object
  709. * @param {String} baseId base schema ID
  710. * @return {Integer} compilation index
  711. */
  712. function compIndex(schema, root, baseId) {
  713. /* jshint validthis: true */
  714. for (var i=0; i<this._compilations.length; i++) {
  715. var c = this._compilations[i];
  716. if (c.schema == schema && c.root == root && c.baseId == baseId) return i;
  717. }
  718. return -1;
  719. }
  720. function patternCode(i, patterns) {
  721. return 'var pattern' + i + ' = new RegExp(' + util.toQuotedString(patterns[i]) + ');';
  722. }
  723. function defaultCode(i) {
  724. return 'var default' + i + ' = defaults[' + i + '];';
  725. }
  726. function refValCode(i, refVal) {
  727. return refVal[i] ? 'var refVal' + i + ' = refVal[' + i + '];' : '';
  728. }
  729. function customRuleCode(i) {
  730. return 'var customRule' + i + ' = customRules[' + i + '];';
  731. }
  732. function vars(arr, statement) {
  733. if (!arr.length) return '';
  734. var code = '';
  735. for (var i=0; i<arr.length; i++)
  736. code += statement(i, arr);
  737. return code;
  738. }
  739. },{"../async":1,"../dotjs/validate":36,"./equal":4,"./resolve":7,"./util":11,"./validation_error":12,"co":41,"json-stable-stringify":42}],7:[function(require,module,exports){
  740. 'use strict';
  741. var url = require('url')
  742. , equal = require('./equal')
  743. , util = require('./util')
  744. , SchemaObject = require('./schema_obj');
  745. module.exports = resolve;
  746. resolve.normalizeId = normalizeId;
  747. resolve.fullPath = getFullPath;
  748. resolve.url = resolveUrl;
  749. resolve.ids = resolveIds;
  750. resolve.inlineRef = inlineRef;
  751. resolve.schema = resolveSchema;
  752. /**
  753. * [resolve and compile the references ($ref)]
  754. * @this Ajv
  755. * @param {Function} compile reference to schema compilation funciton (localCompile)
  756. * @param {Object} root object with information about the root schema for the current schema
  757. * @param {String} ref reference to resolve
  758. * @return {Object|Function} schema object (if the schema can be inlined) or validation function
  759. */
  760. function resolve(compile, root, ref) {
  761. /* jshint validthis: true */
  762. var refVal = this._refs[ref];
  763. if (typeof refVal == 'string') {
  764. if (this._refs[refVal]) refVal = this._refs[refVal];
  765. else return resolve.call(this, compile, root, refVal);
  766. }
  767. refVal = refVal || this._schemas[ref];
  768. if (refVal instanceof SchemaObject) {
  769. return inlineRef(refVal.schema, this._opts.inlineRefs)
  770. ? refVal.schema
  771. : refVal.validate || this._compile(refVal);
  772. }
  773. var res = resolveSchema.call(this, root, ref);
  774. var schema, v, baseId;
  775. if (res) {
  776. schema = res.schema;
  777. root = res.root;
  778. baseId = res.baseId;
  779. }
  780. if (schema instanceof SchemaObject) {
  781. v = schema.validate || compile.call(this, schema.schema, root, undefined, baseId);
  782. } else if (schema) {
  783. v = inlineRef(schema, this._opts.inlineRefs)
  784. ? schema
  785. : compile.call(this, schema, root, undefined, baseId);
  786. }
  787. return v;
  788. }
  789. /**
  790. * Resolve schema, its root and baseId
  791. * @this Ajv
  792. * @param {Object} root root object with properties schema, refVal, refs
  793. * @param {String} ref reference to resolve
  794. * @return {Object} object with properties schema, root, baseId
  795. */
  796. function resolveSchema(root, ref) {
  797. /* jshint validthis: true */
  798. var p = url.parse(ref, false, true)
  799. , refPath = _getFullPath(p)
  800. , baseId = getFullPath(root.schema.id);
  801. if (refPath !== baseId) {
  802. var id = normalizeId(refPath);
  803. var refVal = this._refs[id];
  804. if (typeof refVal == 'string') {
  805. return resolveRecursive.call(this, root, refVal, p);
  806. } else if (refVal instanceof SchemaObject) {
  807. if (!refVal.validate) this._compile(refVal);
  808. root = refVal;
  809. } else {
  810. refVal = this._schemas[id];
  811. if (refVal instanceof SchemaObject) {
  812. if (!refVal.validate) this._compile(refVal);
  813. if (id == normalizeId(ref))
  814. return { schema: refVal, root: root, baseId: baseId };
  815. root = refVal;
  816. } else {
  817. return;
  818. }
  819. }
  820. if (!root.schema) return;
  821. baseId = getFullPath(root.schema.id);
  822. }
  823. return getJsonPointer.call(this, p, baseId, root.schema, root);
  824. }
  825. /* @this Ajv */
  826. function resolveRecursive(root, ref, parsedRef) {
  827. /* jshint validthis: true */
  828. var res = resolveSchema.call(this, root, ref);
  829. if (res) {
  830. var schema = res.schema;
  831. var baseId = res.baseId;
  832. root = res.root;
  833. if (schema.id) baseId = resolveUrl(baseId, schema.id);
  834. return getJsonPointer.call(this, parsedRef, baseId, schema, root);
  835. }
  836. }
  837. var PREVENT_SCOPE_CHANGE = util.toHash(['properties', 'patternProperties', 'enum', 'dependencies', 'definitions']);
  838. /* @this Ajv */
  839. function getJsonPointer(parsedRef, baseId, schema, root) {
  840. /* jshint validthis: true */
  841. parsedRef.hash = parsedRef.hash || '';
  842. if (parsedRef.hash.slice(0,2) != '#/') return;
  843. var parts = parsedRef.hash.split('/');
  844. for (var i = 1; i < parts.length; i++) {
  845. var part = parts[i];
  846. if (part) {
  847. part = util.unescapeFragment(part);
  848. schema = schema[part];
  849. if (!schema) break;
  850. if (schema.id && !PREVENT_SCOPE_CHANGE[part]) baseId = resolveUrl(baseId, schema.id);
  851. if (schema.$ref) {
  852. var $ref = resolveUrl(baseId, schema.$ref);
  853. var res = resolveSchema.call(this, root, $ref);
  854. if (res) {
  855. schema = res.schema;
  856. root = res.root;
  857. baseId = res.baseId;
  858. }
  859. }
  860. }
  861. }
  862. if (schema && schema != root.schema)
  863. return { schema: schema, root: root, baseId: baseId };
  864. }
  865. var SIMPLE_INLINED = util.toHash([
  866. 'type', 'format', 'pattern',
  867. 'maxLength', 'minLength',
  868. 'maxProperties', 'minProperties',
  869. 'maxItems', 'minItems',
  870. 'maximum', 'minimum',
  871. 'uniqueItems', 'multipleOf',
  872. 'required', 'enum'
  873. ]);
  874. function inlineRef(schema, limit) {
  875. if (limit === false) return false;
  876. if (limit === undefined || limit === true) return checkNoRef(schema);
  877. else if (limit) return countKeys(schema) <= limit;
  878. }
  879. function checkNoRef(schema) {
  880. var item;
  881. if (Array.isArray(schema)) {
  882. for (var i=0; i<schema.length; i++) {
  883. item = schema[i];
  884. if (typeof item == 'object' && !checkNoRef(item)) return false;
  885. }
  886. } else {
  887. for (var key in schema) {
  888. if (key == '$ref') return false;
  889. item = schema[key];
  890. if (typeof item == 'object' && !checkNoRef(item)) return false;
  891. }
  892. }
  893. return true;
  894. }
  895. function countKeys(schema) {
  896. var count = 0, item;
  897. if (Array.isArray(schema)) {
  898. for (var i=0; i<schema.length; i++) {
  899. item = schema[i];
  900. if (typeof item == 'object') count += countKeys(item);
  901. if (count == Infinity) return Infinity;
  902. }
  903. } else {
  904. for (var key in schema) {
  905. if (key == '$ref') return Infinity;
  906. if (SIMPLE_INLINED[key]) {
  907. count++;
  908. } else {
  909. item = schema[key];
  910. if (typeof item == 'object') count += countKeys(item) + 1;
  911. if (count == Infinity) return Infinity;
  912. }
  913. }
  914. }
  915. return count;
  916. }
  917. function getFullPath(id, normalize) {
  918. if (normalize !== false) id = normalizeId(id);
  919. var p = url.parse(id, false, true);
  920. return _getFullPath(p);
  921. }
  922. function _getFullPath(p) {
  923. var protocolSeparator = p.protocol || p.href.slice(0,2) == '//' ? '//' : '';
  924. return (p.protocol||'') + protocolSeparator + (p.host||'') + (p.path||'') + '#';
  925. }
  926. var TRAILING_SLASH_HASH = /#\/?$/;
  927. function normalizeId(id) {
  928. return id ? id.replace(TRAILING_SLASH_HASH, '') : '';
  929. }
  930. function resolveUrl(baseId, id) {
  931. id = normalizeId(id);
  932. return url.resolve(baseId, id);
  933. }
  934. /* @this Ajv */
  935. function resolveIds(schema) {
  936. /* eslint no-shadow: 0 */
  937. /* jshint validthis: true */
  938. var id = normalizeId(schema.id);
  939. var localRefs = {};
  940. _resolveIds.call(this, schema, getFullPath(id, false), id);
  941. return localRefs;
  942. /* @this Ajv */
  943. function _resolveIds(schema, fullPath, baseId) {
  944. /* jshint validthis: true */
  945. if (Array.isArray(schema)) {
  946. for (var i=0; i<schema.length; i++)
  947. _resolveIds.call(this, schema[i], fullPath+'/'+i, baseId);
  948. } else if (schema && typeof schema == 'object') {
  949. if (typeof schema.id == 'string') {
  950. var id = baseId = baseId
  951. ? url.resolve(baseId, schema.id)
  952. : schema.id;
  953. id = normalizeId(id);
  954. var refVal = this._refs[id];
  955. if (typeof refVal == 'string') refVal = this._refs[refVal];
  956. if (refVal && refVal.schema) {
  957. if (!equal(schema, refVal.schema))
  958. throw new Error('id "' + id + '" resolves to more than one schema');
  959. } else if (id != normalizeId(fullPath)) {
  960. if (id[0] == '#') {
  961. if (localRefs[id] && !equal(schema, localRefs[id]))
  962. throw new Error('id "' + id + '" resolves to more than one schema');
  963. localRefs[id] = schema;
  964. } else {
  965. this._refs[id] = fullPath;
  966. }
  967. }
  968. }
  969. for (var key in schema)
  970. _resolveIds.call(this, schema[key], fullPath+'/'+util.escapeFragment(key), baseId);
  971. }
  972. }
  973. }
  974. },{"./equal":4,"./schema_obj":9,"./util":11,"url":50}],8:[function(require,module,exports){
  975. 'use strict';
  976. var ruleModules = require('./_rules')
  977. , toHash = require('./util').toHash;
  978. module.exports = function rules() {
  979. var RULES = [
  980. { type: 'number',
  981. rules: [ 'maximum', 'minimum', 'multipleOf'] },
  982. { type: 'string',
  983. rules: [ 'maxLength', 'minLength', 'pattern', 'format' ] },
  984. { type: 'array',
  985. rules: [ 'maxItems', 'minItems', 'uniqueItems', 'items' ] },
  986. { type: 'object',
  987. rules: [ 'maxProperties', 'minProperties', 'required', 'dependencies', 'properties' ] },
  988. { rules: [ '$ref', 'enum', 'not', 'anyOf', 'oneOf', 'allOf' ] }
  989. ];
  990. var ALL = [ 'type', 'additionalProperties', 'patternProperties' ];
  991. var KEYWORDS = [ 'additionalItems', '$schema', 'id', 'title', 'description', 'default' ];
  992. var TYPES = [ 'number', 'integer', 'string', 'array', 'object', 'boolean', 'null' ];
  993. RULES.all = toHash(ALL);
  994. RULES.forEach(function (group) {
  995. group.rules = group.rules.map(function (keyword) {
  996. ALL.push(keyword);
  997. var rule = RULES.all[keyword] = {
  998. keyword: keyword,
  999. code: ruleModules[keyword]
  1000. };
  1001. return rule;
  1002. });
  1003. });
  1004. RULES.keywords = toHash(ALL.concat(KEYWORDS));
  1005. RULES.types = toHash(TYPES);
  1006. RULES.custom = {};
  1007. return RULES;
  1008. };
  1009. },{"./_rules":3,"./util":11}],9:[function(require,module,exports){
  1010. 'use strict';
  1011. var util = require('./util');
  1012. module.exports = SchemaObject;
  1013. function SchemaObject(obj) {
  1014. util.copy(obj, this);
  1015. }
  1016. },{"./util":11}],10:[function(require,module,exports){
  1017. 'use strict';
  1018. // https://mathiasbynens.be/notes/javascript-encoding
  1019. // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
  1020. module.exports = function ucs2length(str) {
  1021. var length = 0
  1022. , len = str.length
  1023. , pos = 0
  1024. , value;
  1025. while (pos < len) {
  1026. length++;
  1027. value = str.charCodeAt(pos++);
  1028. if (value >= 0xD800 && value <= 0xDBFF && pos < len) {
  1029. // high surrogate, and there is a next character
  1030. value = str.charCodeAt(pos);
  1031. if ((value & 0xFC00) == 0xDC00) pos++; // low surrogate
  1032. }
  1033. }
  1034. return length;
  1035. };
  1036. },{}],11:[function(require,module,exports){
  1037. 'use strict';
  1038. module.exports = {
  1039. copy: copy,
  1040. checkDataType: checkDataType,
  1041. checkDataTypes: checkDataTypes,
  1042. coerceToTypes: coerceToTypes,
  1043. toHash: toHash,
  1044. getProperty: getProperty,
  1045. escapeQuotes: escapeQuotes,
  1046. ucs2length: require('./ucs2length'),
  1047. varOccurences: varOccurences,
  1048. varReplace: varReplace,
  1049. cleanUpCode: cleanUpCode,
  1050. cleanUpVarErrors: cleanUpVarErrors,
  1051. schemaHasRules: schemaHasRules,
  1052. schemaHasRulesExcept: schemaHasRulesExcept,
  1053. stableStringify: require('json-stable-stringify'),
  1054. toQuotedString: toQuotedString,
  1055. getPathExpr: getPathExpr,
  1056. getPath: getPath,
  1057. getData: getData,
  1058. unescapeFragment: unescapeFragment,
  1059. escapeFragment: escapeFragment,
  1060. escapeJsonPointer: escapeJsonPointer
  1061. };
  1062. function copy(o, to) {
  1063. to = to || {};
  1064. for (var key in o) to[key] = o[key];
  1065. return to;
  1066. }
  1067. function checkDataType(dataType, data, negate) {
  1068. var EQUAL = negate ? ' !== ' : ' === '
  1069. , AND = negate ? ' || ' : ' && '
  1070. , OK = negate ? '!' : ''
  1071. , NOT = negate ? '' : '!';
  1072. switch (dataType) {
  1073. case 'null': return data + EQUAL + 'null';
  1074. case 'array': return OK + 'Array.isArray(' + data + ')';
  1075. case 'object': return '(' + OK + data + AND +
  1076. 'typeof ' + data + EQUAL + '"object"' + AND +
  1077. NOT + 'Array.isArray(' + data + '))';
  1078. case 'integer': return '(typeof ' + data + EQUAL + '"number"' + AND +
  1079. NOT + '(' + data + ' % 1)' +
  1080. AND + data + EQUAL + data + ')';
  1081. default: return 'typeof ' + data + EQUAL + '"' + dataType + '"';
  1082. }
  1083. }
  1084. function checkDataTypes(dataTypes, data) {
  1085. switch (dataTypes.length) {
  1086. case 1: return checkDataType(dataTypes[0], data, true);
  1087. default:
  1088. var code = '';
  1089. var types = toHash(dataTypes);
  1090. if (types.array && types.object) {
  1091. code = types.null ? '(': '(!' + data + ' || ';
  1092. code += 'typeof ' + data + ' !== "object")';
  1093. delete types.null;
  1094. delete types.array;
  1095. delete types.object;
  1096. }
  1097. if (types.number) delete types.integer;
  1098. for (var t in types)
  1099. code += (code ? ' && ' : '' ) + checkDataType(t, data, true);
  1100. return code;
  1101. }
  1102. }
  1103. var COERCE_TO_TYPES = toHash([ 'string', 'number', 'integer', 'boolean', 'null' ]);
  1104. function coerceToTypes(optionCoerceTypes, dataTypes) {
  1105. if (Array.isArray(dataTypes)) {
  1106. var types = [];
  1107. for (var i=0; i<dataTypes.length; i++) {
  1108. var t = dataTypes[i];
  1109. if (COERCE_TO_TYPES[t]) types[types.length] = t;
  1110. else if (optionCoerceTypes === 'array' && t === 'array') types[types.length] = t;
  1111. }
  1112. if (types.length) return types;
  1113. } else if (COERCE_TO_TYPES[dataTypes]) {
  1114. return [dataTypes];
  1115. } else if (optionCoerceTypes === 'array' && dataTypes === 'array') {
  1116. return ['array'];
  1117. }
  1118. }
  1119. function toHash(arr) {
  1120. var hash = {};
  1121. for (var i=0; i<arr.length; i++) hash[arr[i]] = true;
  1122. return hash;
  1123. }
  1124. var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
  1125. var SINGLE_QUOTE = /'|\\/g;
  1126. function getProperty(key) {
  1127. return typeof key == 'number'
  1128. ? '[' + key + ']'
  1129. : IDENTIFIER.test(key)
  1130. ? '.' + key
  1131. : "['" + escapeQuotes(key) + "']";
  1132. }
  1133. function escapeQuotes(str) {
  1134. return str.replace(SINGLE_QUOTE, '\\$&')
  1135. .replace(/\n/g, '\\n')
  1136. .replace(/\r/g, '\\r')
  1137. .replace(/\f/g, '\\f')
  1138. .replace(/\t/g, '\\t');
  1139. }
  1140. function varOccurences(str, dataVar) {
  1141. dataVar += '[^0-9]';
  1142. var matches = str.match(new RegExp(dataVar, 'g'));
  1143. return matches ? matches.length : 0;
  1144. }
  1145. function varReplace(str, dataVar, expr) {
  1146. dataVar += '([^0-9])';
  1147. expr = expr.replace(/\$/g, '$$$$');
  1148. return str.replace(new RegExp(dataVar, 'g'), expr + '$1');
  1149. }
  1150. var EMPTY_ELSE = /else\s*{\s*}/g
  1151. , EMPTY_IF_NO_ELSE = /if\s*\([^)]+\)\s*\{\s*\}(?!\s*else)/g
  1152. , EMPTY_IF_WITH_ELSE = /if\s*\(([^)]+)\)\s*\{\s*\}\s*else(?!\s*if)/g;
  1153. function cleanUpCode(out) {
  1154. return out.replace(EMPTY_ELSE, '')
  1155. .replace(EMPTY_IF_NO_ELSE, '')
  1156. .replace(EMPTY_IF_WITH_ELSE, 'if (!($1))');
  1157. }
  1158. var ERRORS_REGEXP = /[^v\.]errors/g
  1159. , REMOVE_ERRORS = /var errors = 0;|var vErrors = null;|validate.errors = vErrors;/g
  1160. , REMOVE_ERRORS_ASYNC = /var errors = 0;|var vErrors = null;/g
  1161. , RETURN_VALID = 'return errors === 0;'
  1162. , RETURN_TRUE = 'validate.errors = null; return true;'
  1163. , RETURN_ASYNC = /if \(errors === 0\) return true;\s*else throw new ValidationError\(vErrors\);/
  1164. , RETURN_TRUE_ASYNC = 'return true;';
  1165. function cleanUpVarErrors(out, async) {
  1166. var matches = out.match(ERRORS_REGEXP);
  1167. if (!matches || matches.length !== 2) return out;
  1168. return async
  1169. ? out.replace(REMOVE_ERRORS_ASYNC, '')
  1170. .replace(RETURN_ASYNC, RETURN_TRUE_ASYNC)
  1171. : out.replace(REMOVE_ERRORS, '')
  1172. .replace(RETURN_VALID, RETURN_TRUE);
  1173. }
  1174. function schemaHasRules(schema, rules) {
  1175. for (var key in schema) if (rules[key]) return true;
  1176. }
  1177. function schemaHasRulesExcept(schema, rules, exceptKeyword) {
  1178. for (var key in schema) if (key != exceptKeyword && rules[key]) return true;
  1179. }
  1180. function toQuotedString(str) {
  1181. return '\'' + escapeQuotes(str) + '\'';
  1182. }
  1183. function getPathExpr(currentPath, expr, jsonPointers, isNumber) {
  1184. var path = jsonPointers // false by default
  1185. ? '\'/\' + ' + expr + (isNumber ? '' : '.replace(/~/g, \'~0\').replace(/\\//g, \'~1\')')
  1186. : (isNumber ? '\'[\' + ' + expr + ' + \']\'' : '\'[\\\'\' + ' + expr + ' + \'\\\']\'');
  1187. return joinPaths(currentPath, path);
  1188. }
  1189. function getPath(currentPath, prop, jsonPointers) {
  1190. var path = jsonPointers // false by default
  1191. ? toQuotedString('/' + escapeJsonPointer(prop))
  1192. : toQuotedString(getProperty(prop));
  1193. return joinPaths(currentPath, path);
  1194. }
  1195. var JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
  1196. var RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
  1197. function getData($data, lvl, paths) {
  1198. var up, jsonPointer, data, matches;
  1199. if ($data === '') return 'rootData';
  1200. if ($data[0] == '/') {
  1201. if (!JSON_POINTER.test($data)) throw new Error('Invalid JSON-pointer: ' + $data);
  1202. jsonPointer = $data;
  1203. data = 'rootData';
  1204. } else {
  1205. matches = $data.match(RELATIVE_JSON_POINTER);
  1206. if (!matches) throw new Error('Invalid JSON-pointer: ' + $data);
  1207. up = +matches[1];
  1208. jsonPointer = matches[2];
  1209. if (jsonPointer == '#') {
  1210. if (up >= lvl) throw new Error('Cannot access property/index ' + up + ' levels up, current level is ' + lvl);
  1211. return paths[lvl - up];
  1212. }
  1213. if (up > lvl) throw new Error('Cannot access data ' + up + ' levels up, current level is ' + lvl);
  1214. data = 'data' + ((lvl - up) || '');
  1215. if (!jsonPointer) return data;
  1216. }
  1217. var expr = data;
  1218. var segments = jsonPointer.split('/');
  1219. for (var i=0; i<segments.length; i++) {
  1220. var segment = segments[i];
  1221. if (segment) {
  1222. data += getProperty(unescapeJsonPointer(segment));
  1223. expr += ' && ' + data;
  1224. }
  1225. }
  1226. return expr;
  1227. }
  1228. function joinPaths (a, b) {
  1229. if (a == '""') return b;
  1230. return (a + ' + ' + b).replace(/' \+ '/g, '');
  1231. }
  1232. function unescapeFragment(str) {
  1233. return unescapeJsonPointer(decodeURIComponent(str));
  1234. }
  1235. function escapeFragment(str) {
  1236. return encodeURIComponent(escapeJsonPointer(str));
  1237. }
  1238. function escapeJsonPointer(str) {
  1239. return str.replace(/~/g, '~0').replace(/\//g, '~1');
  1240. }
  1241. function unescapeJsonPointer(str) {
  1242. return str.replace(/~1/g, '/').replace(/~0/g, '~');
  1243. }
  1244. },{"./ucs2length":10,"json-stable-stringify":42}],12:[function(require,module,exports){
  1245. 'use strict';
  1246. module.exports = ValidationError;
  1247. function ValidationError(errors) {
  1248. this.message = 'validation failed';
  1249. this.errors = errors;
  1250. this.ajv = this.validation = true;
  1251. }
  1252. ValidationError.prototype = Object.create(Error.prototype);
  1253. ValidationError.prototype.constructor = ValidationError;
  1254. },{}],13:[function(require,module,exports){
  1255. 'use strict';
  1256. module.exports = function generate__formatLimit(it, $keyword) {
  1257. var out = ' ';
  1258. var $lvl = it.level;
  1259. var $dataLvl = it.dataLevel;
  1260. var $schema = it.schema[$keyword];
  1261. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1262. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1263. var $breakOnError = !it.opts.allErrors;
  1264. var $errorKeyword;
  1265. var $data = 'data' + ($dataLvl || '');
  1266. var $valid = 'valid' + $lvl;
  1267. out += 'var ' + ($valid) + ' = undefined;';
  1268. if (it.opts.format === false) {
  1269. out += ' ' + ($valid) + ' = true; ';
  1270. return out;
  1271. }
  1272. var $schemaFormat = it.schema.format,
  1273. $isDataFormat = it.opts.v5 && $schemaFormat.$data,
  1274. $closingBraces = '';
  1275. if ($isDataFormat) {
  1276. var $schemaValueFormat = it.util.getData($schemaFormat.$data, $dataLvl, it.dataPathArr),
  1277. $format = 'format' + $lvl,
  1278. $compare = 'compare' + $lvl;
  1279. out += ' var ' + ($format) + ' = formats[' + ($schemaValueFormat) + '] , ' + ($compare) + ' = ' + ($format) + ' && ' + ($format) + '.compare;';
  1280. } else {
  1281. var $format = it.formats[$schemaFormat];
  1282. if (!($format && $format.compare)) {
  1283. out += ' ' + ($valid) + ' = true; ';
  1284. return out;
  1285. }
  1286. var $compare = 'formats' + it.util.getProperty($schemaFormat) + '.compare';
  1287. }
  1288. var $isMax = $keyword == 'formatMaximum',
  1289. $exclusiveKeyword = 'formatExclusive' + ($isMax ? 'Maximum' : 'Minimum'),
  1290. $schemaExcl = it.schema[$exclusiveKeyword],
  1291. $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
  1292. $op = $isMax ? '<' : '>',
  1293. $result = 'result' + $lvl;
  1294. var $isData = it.opts.v5 && $schema && $schema.$data,
  1295. $schemaValue;
  1296. if ($isData) {
  1297. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1298. $schemaValue = 'schema' + $lvl;
  1299. } else {
  1300. $schemaValue = $schema;
  1301. }
  1302. if ($isDataExcl) {
  1303. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
  1304. $exclusive = 'exclusive' + $lvl,
  1305. $opExpr = 'op' + $lvl,
  1306. $opStr = '\' + ' + $opExpr + ' + \'';
  1307. out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
  1308. $schemaValueExcl = 'schemaExcl' + $lvl;
  1309. out += ' if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && ' + ($schemaValueExcl) + ' !== undefined) { ' + ($valid) + ' = false; ';
  1310. var $errorKeyword = $exclusiveKeyword;
  1311. var $$outStack = $$outStack || [];
  1312. $$outStack.push(out);
  1313. out = ''; /* istanbul ignore else */
  1314. if (it.createErrors !== false) {
  1315. out += ' { keyword: \'' + ($errorKeyword || '_formatExclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1316. if (it.opts.messages !== false) {
  1317. out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
  1318. }
  1319. if (it.opts.verbose) {
  1320. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1321. }
  1322. out += ' } ';
  1323. } else {
  1324. out += ' {} ';
  1325. }
  1326. var __err = out;
  1327. out = $$outStack.pop();
  1328. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1329. if (it.async) {
  1330. out += ' throw new ValidationError([' + (__err) + ']); ';
  1331. } else {
  1332. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1333. }
  1334. } else {
  1335. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1336. }
  1337. out += ' } ';
  1338. if ($breakOnError) {
  1339. $closingBraces += '}';
  1340. out += ' else { ';
  1341. }
  1342. if ($isData) {
  1343. out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
  1344. $closingBraces += '}';
  1345. }
  1346. if ($isDataFormat) {
  1347. out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
  1348. $closingBraces += '}';
  1349. }
  1350. out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
  1351. if ($isData) {
  1352. out += '' + ($schemaValue);
  1353. } else {
  1354. out += '' + (it.util.toQuotedString($schema));
  1355. }
  1356. out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; var ' + ($exclusive) + ' = ' + ($schemaValueExcl) + ' === true; if (' + ($valid) + ' === undefined) { ' + ($valid) + ' = ' + ($exclusive) + ' ? ' + ($result) + ' ' + ($op) + ' 0 : ' + ($result) + ' ' + ($op) + '= 0; } if (!' + ($valid) + ') var op' + ($lvl) + ' = ' + ($exclusive) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
  1357. } else {
  1358. var $exclusive = $schemaExcl === true,
  1359. $opStr = $op;
  1360. if (!$exclusive) $opStr += '=';
  1361. var $opExpr = '\'' + $opStr + '\'';
  1362. if ($isData) {
  1363. out += ' if (' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'string\') ' + ($valid) + ' = false; else { ';
  1364. $closingBraces += '}';
  1365. }
  1366. if ($isDataFormat) {
  1367. out += ' if (!' + ($compare) + ') ' + ($valid) + ' = true; else { ';
  1368. $closingBraces += '}';
  1369. }
  1370. out += ' var ' + ($result) + ' = ' + ($compare) + '(' + ($data) + ', ';
  1371. if ($isData) {
  1372. out += '' + ($schemaValue);
  1373. } else {
  1374. out += '' + (it.util.toQuotedString($schema));
  1375. }
  1376. out += ' ); if (' + ($result) + ' === undefined) ' + ($valid) + ' = false; if (' + ($valid) + ' === undefined) ' + ($valid) + ' = ' + ($result) + ' ' + ($op);
  1377. if (!$exclusive) {
  1378. out += '=';
  1379. }
  1380. out += ' 0;';
  1381. }
  1382. out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
  1383. var $errorKeyword = $keyword;
  1384. var $$outStack = $$outStack || [];
  1385. $$outStack.push(out);
  1386. out = ''; /* istanbul ignore else */
  1387. if (it.createErrors !== false) {
  1388. out += ' { keyword: \'' + ($errorKeyword || '_formatLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ';
  1389. if ($isData) {
  1390. out += '' + ($schemaValue);
  1391. } else {
  1392. out += '' + (it.util.toQuotedString($schema));
  1393. }
  1394. out += ' , exclusive: ' + ($exclusive) + ' } ';
  1395. if (it.opts.messages !== false) {
  1396. out += ' , message: \'should be ' + ($opStr) + ' "';
  1397. if ($isData) {
  1398. out += '\' + ' + ($schemaValue) + ' + \'';
  1399. } else {
  1400. out += '' + (it.util.escapeQuotes($schema));
  1401. }
  1402. out += '"\' ';
  1403. }
  1404. if (it.opts.verbose) {
  1405. out += ' , schema: ';
  1406. if ($isData) {
  1407. out += 'validate.schema' + ($schemaPath);
  1408. } else {
  1409. out += '' + (it.util.toQuotedString($schema));
  1410. }
  1411. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1412. }
  1413. out += ' } ';
  1414. } else {
  1415. out += ' {} ';
  1416. }
  1417. var __err = out;
  1418. out = $$outStack.pop();
  1419. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1420. if (it.async) {
  1421. out += ' throw new ValidationError([' + (__err) + ']); ';
  1422. } else {
  1423. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1424. }
  1425. } else {
  1426. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1427. }
  1428. out += '}';
  1429. return out;
  1430. }
  1431. },{}],14:[function(require,module,exports){
  1432. 'use strict';
  1433. module.exports = function generate__limit(it, $keyword) {
  1434. var out = ' ';
  1435. var $lvl = it.level;
  1436. var $dataLvl = it.dataLevel;
  1437. var $schema = it.schema[$keyword];
  1438. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1439. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1440. var $breakOnError = !it.opts.allErrors;
  1441. var $errorKeyword;
  1442. var $data = 'data' + ($dataLvl || '');
  1443. var $isData = it.opts.v5 && $schema && $schema.$data,
  1444. $schemaValue;
  1445. if ($isData) {
  1446. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1447. $schemaValue = 'schema' + $lvl;
  1448. } else {
  1449. $schemaValue = $schema;
  1450. }
  1451. var $isMax = $keyword == 'maximum',
  1452. $exclusiveKeyword = $isMax ? 'exclusiveMaximum' : 'exclusiveMinimum',
  1453. $schemaExcl = it.schema[$exclusiveKeyword],
  1454. $isDataExcl = it.opts.v5 && $schemaExcl && $schemaExcl.$data,
  1455. $op = $isMax ? '<' : '>',
  1456. $notOp = $isMax ? '>' : '<';
  1457. if ($isDataExcl) {
  1458. var $schemaValueExcl = it.util.getData($schemaExcl.$data, $dataLvl, it.dataPathArr),
  1459. $exclusive = 'exclusive' + $lvl,
  1460. $opExpr = 'op' + $lvl,
  1461. $opStr = '\' + ' + $opExpr + ' + \'';
  1462. out += ' var schemaExcl' + ($lvl) + ' = ' + ($schemaValueExcl) + '; ';
  1463. $schemaValueExcl = 'schemaExcl' + $lvl;
  1464. out += ' var exclusive' + ($lvl) + '; if (typeof ' + ($schemaValueExcl) + ' != \'boolean\' && typeof ' + ($schemaValueExcl) + ' != \'undefined\') { ';
  1465. var $errorKeyword = $exclusiveKeyword;
  1466. var $$outStack = $$outStack || [];
  1467. $$outStack.push(out);
  1468. out = ''; /* istanbul ignore else */
  1469. if (it.createErrors !== false) {
  1470. out += ' { keyword: \'' + ($errorKeyword || '_exclusiveLimit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1471. if (it.opts.messages !== false) {
  1472. out += ' , message: \'' + ($exclusiveKeyword) + ' should be boolean\' ';
  1473. }
  1474. if (it.opts.verbose) {
  1475. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1476. }
  1477. out += ' } ';
  1478. } else {
  1479. out += ' {} ';
  1480. }
  1481. var __err = out;
  1482. out = $$outStack.pop();
  1483. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1484. if (it.async) {
  1485. out += ' throw new ValidationError([' + (__err) + ']); ';
  1486. } else {
  1487. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1488. }
  1489. } else {
  1490. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1491. }
  1492. out += ' } else if( ';
  1493. if ($isData) {
  1494. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1495. }
  1496. out += ' ((exclusive' + ($lvl) + ' = ' + ($schemaValueExcl) + ' === true) ? ' + ($data) + ' ' + ($notOp) + '= ' + ($schemaValue) + ' : ' + ($data) + ' ' + ($notOp) + ' ' + ($schemaValue) + ') || ' + ($data) + ' !== ' + ($data) + ') { var op' + ($lvl) + ' = exclusive' + ($lvl) + ' ? \'' + ($op) + '\' : \'' + ($op) + '=\';';
  1497. } else {
  1498. var $exclusive = $schemaExcl === true,
  1499. $opStr = $op;
  1500. if (!$exclusive) $opStr += '=';
  1501. var $opExpr = '\'' + $opStr + '\'';
  1502. out += ' if ( ';
  1503. if ($isData) {
  1504. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1505. }
  1506. out += ' ' + ($data) + ' ' + ($notOp);
  1507. if ($exclusive) {
  1508. out += '=';
  1509. }
  1510. out += ' ' + ($schemaValue) + ' || ' + ($data) + ' !== ' + ($data) + ') {';
  1511. }
  1512. var $errorKeyword = $keyword;
  1513. var $$outStack = $$outStack || [];
  1514. $$outStack.push(out);
  1515. out = ''; /* istanbul ignore else */
  1516. if (it.createErrors !== false) {
  1517. out += ' { keyword: \'' + ($errorKeyword || '_limit') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { comparison: ' + ($opExpr) + ', limit: ' + ($schemaValue) + ', exclusive: ' + ($exclusive) + ' } ';
  1518. if (it.opts.messages !== false) {
  1519. out += ' , message: \'should be ' + ($opStr) + ' ';
  1520. if ($isData) {
  1521. out += '\' + ' + ($schemaValue);
  1522. } else {
  1523. out += '' + ($schema) + '\'';
  1524. }
  1525. }
  1526. if (it.opts.verbose) {
  1527. out += ' , schema: ';
  1528. if ($isData) {
  1529. out += 'validate.schema' + ($schemaPath);
  1530. } else {
  1531. out += '' + ($schema);
  1532. }
  1533. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1534. }
  1535. out += ' } ';
  1536. } else {
  1537. out += ' {} ';
  1538. }
  1539. var __err = out;
  1540. out = $$outStack.pop();
  1541. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1542. if (it.async) {
  1543. out += ' throw new ValidationError([' + (__err) + ']); ';
  1544. } else {
  1545. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1546. }
  1547. } else {
  1548. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1549. }
  1550. out += ' } ';
  1551. if ($breakOnError) {
  1552. out += ' else { ';
  1553. }
  1554. return out;
  1555. }
  1556. },{}],15:[function(require,module,exports){
  1557. 'use strict';
  1558. module.exports = function generate__limitItems(it, $keyword) {
  1559. var out = ' ';
  1560. var $lvl = it.level;
  1561. var $dataLvl = it.dataLevel;
  1562. var $schema = it.schema[$keyword];
  1563. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1564. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1565. var $breakOnError = !it.opts.allErrors;
  1566. var $errorKeyword;
  1567. var $data = 'data' + ($dataLvl || '');
  1568. var $isData = it.opts.v5 && $schema && $schema.$data,
  1569. $schemaValue;
  1570. if ($isData) {
  1571. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1572. $schemaValue = 'schema' + $lvl;
  1573. } else {
  1574. $schemaValue = $schema;
  1575. }
  1576. var $op = $keyword == 'maxItems' ? '>' : '<';
  1577. out += 'if ( ';
  1578. if ($isData) {
  1579. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1580. }
  1581. out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1582. var $errorKeyword = $keyword;
  1583. var $$outStack = $$outStack || [];
  1584. $$outStack.push(out);
  1585. out = ''; /* istanbul ignore else */
  1586. if (it.createErrors !== false) {
  1587. out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1588. if (it.opts.messages !== false) {
  1589. out += ' , message: \'should NOT have ';
  1590. if ($keyword == 'maxItems') {
  1591. out += 'more';
  1592. } else {
  1593. out += 'less';
  1594. }
  1595. out += ' than ';
  1596. if ($isData) {
  1597. out += '\' + ' + ($schemaValue) + ' + \'';
  1598. } else {
  1599. out += '' + ($schema);
  1600. }
  1601. out += ' items\' ';
  1602. }
  1603. if (it.opts.verbose) {
  1604. out += ' , schema: ';
  1605. if ($isData) {
  1606. out += 'validate.schema' + ($schemaPath);
  1607. } else {
  1608. out += '' + ($schema);
  1609. }
  1610. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1611. }
  1612. out += ' } ';
  1613. } else {
  1614. out += ' {} ';
  1615. }
  1616. var __err = out;
  1617. out = $$outStack.pop();
  1618. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1619. if (it.async) {
  1620. out += ' throw new ValidationError([' + (__err) + ']); ';
  1621. } else {
  1622. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1623. }
  1624. } else {
  1625. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1626. }
  1627. out += '} ';
  1628. if ($breakOnError) {
  1629. out += ' else { ';
  1630. }
  1631. return out;
  1632. }
  1633. },{}],16:[function(require,module,exports){
  1634. 'use strict';
  1635. module.exports = function generate__limitLength(it, $keyword) {
  1636. var out = ' ';
  1637. var $lvl = it.level;
  1638. var $dataLvl = it.dataLevel;
  1639. var $schema = it.schema[$keyword];
  1640. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1641. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1642. var $breakOnError = !it.opts.allErrors;
  1643. var $errorKeyword;
  1644. var $data = 'data' + ($dataLvl || '');
  1645. var $isData = it.opts.v5 && $schema && $schema.$data,
  1646. $schemaValue;
  1647. if ($isData) {
  1648. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1649. $schemaValue = 'schema' + $lvl;
  1650. } else {
  1651. $schemaValue = $schema;
  1652. }
  1653. var $op = $keyword == 'maxLength' ? '>' : '<';
  1654. out += 'if ( ';
  1655. if ($isData) {
  1656. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1657. }
  1658. if (it.opts.unicode === false) {
  1659. out += ' ' + ($data) + '.length ';
  1660. } else {
  1661. out += ' ucs2length(' + ($data) + ') ';
  1662. }
  1663. out += ' ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1664. var $errorKeyword = $keyword;
  1665. var $$outStack = $$outStack || [];
  1666. $$outStack.push(out);
  1667. out = ''; /* istanbul ignore else */
  1668. if (it.createErrors !== false) {
  1669. out += ' { keyword: \'' + ($errorKeyword || '_limitLength') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1670. if (it.opts.messages !== false) {
  1671. out += ' , message: \'should NOT be ';
  1672. if ($keyword == 'maxLength') {
  1673. out += 'longer';
  1674. } else {
  1675. out += 'shorter';
  1676. }
  1677. out += ' than ';
  1678. if ($isData) {
  1679. out += '\' + ' + ($schemaValue) + ' + \'';
  1680. } else {
  1681. out += '' + ($schema);
  1682. }
  1683. out += ' characters\' ';
  1684. }
  1685. if (it.opts.verbose) {
  1686. out += ' , schema: ';
  1687. if ($isData) {
  1688. out += 'validate.schema' + ($schemaPath);
  1689. } else {
  1690. out += '' + ($schema);
  1691. }
  1692. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1693. }
  1694. out += ' } ';
  1695. } else {
  1696. out += ' {} ';
  1697. }
  1698. var __err = out;
  1699. out = $$outStack.pop();
  1700. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1701. if (it.async) {
  1702. out += ' throw new ValidationError([' + (__err) + ']); ';
  1703. } else {
  1704. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1705. }
  1706. } else {
  1707. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1708. }
  1709. out += '} ';
  1710. if ($breakOnError) {
  1711. out += ' else { ';
  1712. }
  1713. return out;
  1714. }
  1715. },{}],17:[function(require,module,exports){
  1716. 'use strict';
  1717. module.exports = function generate__limitProperties(it, $keyword) {
  1718. var out = ' ';
  1719. var $lvl = it.level;
  1720. var $dataLvl = it.dataLevel;
  1721. var $schema = it.schema[$keyword];
  1722. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1723. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1724. var $breakOnError = !it.opts.allErrors;
  1725. var $errorKeyword;
  1726. var $data = 'data' + ($dataLvl || '');
  1727. var $isData = it.opts.v5 && $schema && $schema.$data,
  1728. $schemaValue;
  1729. if ($isData) {
  1730. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1731. $schemaValue = 'schema' + $lvl;
  1732. } else {
  1733. $schemaValue = $schema;
  1734. }
  1735. var $op = $keyword == 'maxProperties' ? '>' : '<';
  1736. out += 'if ( ';
  1737. if ($isData) {
  1738. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
  1739. }
  1740. out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
  1741. var $errorKeyword = $keyword;
  1742. var $$outStack = $$outStack || [];
  1743. $$outStack.push(out);
  1744. out = ''; /* istanbul ignore else */
  1745. if (it.createErrors !== false) {
  1746. out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
  1747. if (it.opts.messages !== false) {
  1748. out += ' , message: \'should NOT have ';
  1749. if ($keyword == 'maxProperties') {
  1750. out += 'more';
  1751. } else {
  1752. out += 'less';
  1753. }
  1754. out += ' than ';
  1755. if ($isData) {
  1756. out += '\' + ' + ($schemaValue) + ' + \'';
  1757. } else {
  1758. out += '' + ($schema);
  1759. }
  1760. out += ' properties\' ';
  1761. }
  1762. if (it.opts.verbose) {
  1763. out += ' , schema: ';
  1764. if ($isData) {
  1765. out += 'validate.schema' + ($schemaPath);
  1766. } else {
  1767. out += '' + ($schema);
  1768. }
  1769. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1770. }
  1771. out += ' } ';
  1772. } else {
  1773. out += ' {} ';
  1774. }
  1775. var __err = out;
  1776. out = $$outStack.pop();
  1777. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1778. if (it.async) {
  1779. out += ' throw new ValidationError([' + (__err) + ']); ';
  1780. } else {
  1781. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1782. }
  1783. } else {
  1784. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1785. }
  1786. out += '} ';
  1787. if ($breakOnError) {
  1788. out += ' else { ';
  1789. }
  1790. return out;
  1791. }
  1792. },{}],18:[function(require,module,exports){
  1793. 'use strict';
  1794. module.exports = function generate_allOf(it, $keyword) {
  1795. var out = ' ';
  1796. var $schema = it.schema[$keyword];
  1797. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1798. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1799. var $breakOnError = !it.opts.allErrors;
  1800. var $it = it.util.copy(it);
  1801. var $closingBraces = '';
  1802. $it.level++;
  1803. var $nextValid = 'valid' + $it.level;
  1804. var $currentBaseId = $it.baseId,
  1805. $allSchemasEmpty = true;
  1806. var arr1 = $schema;
  1807. if (arr1) {
  1808. var $sch, $i = -1,
  1809. l1 = arr1.length - 1;
  1810. while ($i < l1) {
  1811. $sch = arr1[$i += 1];
  1812. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  1813. $allSchemasEmpty = false;
  1814. $it.schema = $sch;
  1815. $it.schemaPath = $schemaPath + '[' + $i + ']';
  1816. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  1817. out += ' ' + (it.validate($it)) + ' ';
  1818. $it.baseId = $currentBaseId;
  1819. if ($breakOnError) {
  1820. out += ' if (' + ($nextValid) + ') { ';
  1821. $closingBraces += '}';
  1822. }
  1823. }
  1824. }
  1825. }
  1826. if ($breakOnError) {
  1827. if ($allSchemasEmpty) {
  1828. out += ' if (true) { ';
  1829. } else {
  1830. out += ' ' + ($closingBraces.slice(0, -1)) + ' ';
  1831. }
  1832. }
  1833. out = it.util.cleanUpCode(out);
  1834. return out;
  1835. }
  1836. },{}],19:[function(require,module,exports){
  1837. 'use strict';
  1838. module.exports = function generate_anyOf(it, $keyword) {
  1839. var out = ' ';
  1840. var $lvl = it.level;
  1841. var $dataLvl = it.dataLevel;
  1842. var $schema = it.schema[$keyword];
  1843. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1844. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1845. var $breakOnError = !it.opts.allErrors;
  1846. var $data = 'data' + ($dataLvl || '');
  1847. var $valid = 'valid' + $lvl;
  1848. var $errs = 'errs__' + $lvl;
  1849. var $it = it.util.copy(it);
  1850. var $closingBraces = '';
  1851. $it.level++;
  1852. var $nextValid = 'valid' + $it.level;
  1853. var $noEmptySchema = $schema.every(function($sch) {
  1854. return it.util.schemaHasRules($sch, it.RULES.all);
  1855. });
  1856. if ($noEmptySchema) {
  1857. var $currentBaseId = $it.baseId;
  1858. out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; ';
  1859. var $wasComposite = it.compositeRule;
  1860. it.compositeRule = $it.compositeRule = true;
  1861. var arr1 = $schema;
  1862. if (arr1) {
  1863. var $sch, $i = -1,
  1864. l1 = arr1.length - 1;
  1865. while ($i < l1) {
  1866. $sch = arr1[$i += 1];
  1867. $it.schema = $sch;
  1868. $it.schemaPath = $schemaPath + '[' + $i + ']';
  1869. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  1870. out += ' ' + (it.validate($it)) + ' ';
  1871. $it.baseId = $currentBaseId;
  1872. out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
  1873. $closingBraces += '}';
  1874. }
  1875. }
  1876. it.compositeRule = $it.compositeRule = $wasComposite;
  1877. out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */
  1878. if (it.createErrors !== false) {
  1879. out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1880. if (it.opts.messages !== false) {
  1881. out += ' , message: \'should match some schema in anyOf\' ';
  1882. }
  1883. if (it.opts.verbose) {
  1884. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1885. }
  1886. out += ' } ';
  1887. } else {
  1888. out += ' {} ';
  1889. }
  1890. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  1891. if (it.opts.allErrors) {
  1892. out += ' } ';
  1893. }
  1894. out = it.util.cleanUpCode(out);
  1895. } else {
  1896. if ($breakOnError) {
  1897. out += ' if (true) { ';
  1898. }
  1899. }
  1900. return out;
  1901. }
  1902. },{}],20:[function(require,module,exports){
  1903. 'use strict';
  1904. module.exports = function generate_constant(it, $keyword) {
  1905. var out = ' ';
  1906. var $lvl = it.level;
  1907. var $dataLvl = it.dataLevel;
  1908. var $schema = it.schema[$keyword];
  1909. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1910. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1911. var $breakOnError = !it.opts.allErrors;
  1912. var $data = 'data' + ($dataLvl || '');
  1913. var $valid = 'valid' + $lvl;
  1914. var $isData = it.opts.v5 && $schema && $schema.$data,
  1915. $schemaValue;
  1916. if ($isData) {
  1917. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1918. $schemaValue = 'schema' + $lvl;
  1919. } else {
  1920. $schemaValue = $schema;
  1921. }
  1922. if (!$isData) {
  1923. out += ' var schema' + ($lvl) + ' = validate.schema' + ($schemaPath) + ';';
  1924. }
  1925. out += 'var ' + ($valid) + ' = equal(' + ($data) + ', schema' + ($lvl) + '); if (!' + ($valid) + ') { ';
  1926. var $$outStack = $$outStack || [];
  1927. $$outStack.push(out);
  1928. out = ''; /* istanbul ignore else */
  1929. if (it.createErrors !== false) {
  1930. out += ' { keyword: \'' + ('constant') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  1931. if (it.opts.messages !== false) {
  1932. out += ' , message: \'should be equal to constant\' ';
  1933. }
  1934. if (it.opts.verbose) {
  1935. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  1936. }
  1937. out += ' } ';
  1938. } else {
  1939. out += ' {} ';
  1940. }
  1941. var __err = out;
  1942. out = $$outStack.pop();
  1943. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  1944. if (it.async) {
  1945. out += ' throw new ValidationError([' + (__err) + ']); ';
  1946. } else {
  1947. out += ' validate.errors = [' + (__err) + ']; return false; ';
  1948. }
  1949. } else {
  1950. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  1951. }
  1952. out += ' }';
  1953. return out;
  1954. }
  1955. },{}],21:[function(require,module,exports){
  1956. 'use strict';
  1957. module.exports = function generate_custom(it, $keyword) {
  1958. var out = ' ';
  1959. var $lvl = it.level;
  1960. var $dataLvl = it.dataLevel;
  1961. var $schema = it.schema[$keyword];
  1962. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  1963. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  1964. var $breakOnError = !it.opts.allErrors;
  1965. var $errorKeyword;
  1966. var $data = 'data' + ($dataLvl || '');
  1967. var $valid = 'valid' + $lvl;
  1968. var $errs = 'errs__' + $lvl;
  1969. var $isData = it.opts.v5 && $schema && $schema.$data,
  1970. $schemaValue;
  1971. if ($isData) {
  1972. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  1973. $schemaValue = 'schema' + $lvl;
  1974. } else {
  1975. $schemaValue = $schema;
  1976. }
  1977. var $rule = this,
  1978. $definition = 'definition' + $lvl,
  1979. $rDef = $rule.definition;
  1980. var $compile, $inline, $macro, $ruleValidate, $validateCode;
  1981. if ($isData && $rDef.$data) {
  1982. $validateCode = 'keywordValidate' + $lvl;
  1983. var $validateSchema = $rDef.validateSchema;
  1984. out += ' var ' + ($definition) + ' = RULES.custom[\'' + ($keyword) + '\'].definition; var ' + ($validateCode) + ' = ' + ($definition) + '.validate;';
  1985. } else {
  1986. $ruleValidate = it.useCustomRule($rule, $schema, it.schema, it);
  1987. $schemaValue = 'validate.schema' + $schemaPath;
  1988. $validateCode = $ruleValidate.code;
  1989. $compile = $rDef.compile;
  1990. $inline = $rDef.inline;
  1991. $macro = $rDef.macro;
  1992. }
  1993. var $ruleErrs = $validateCode + '.errors',
  1994. $i = 'i' + $lvl,
  1995. $ruleErr = 'ruleErr' + $lvl,
  1996. $asyncKeyword = $rDef.async;
  1997. if ($asyncKeyword && !it.async) throw new Error('async keyword in sync schema');
  1998. if (!($inline || $macro)) {
  1999. out += '' + ($ruleErrs) + ' = null;';
  2000. }
  2001. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  2002. if ($validateSchema) {
  2003. out += ' ' + ($valid) + ' = ' + ($definition) + '.validateSchema(' + ($schemaValue) + '); if (' + ($valid) + ') {';
  2004. }
  2005. if ($inline) {
  2006. if ($rDef.statements) {
  2007. out += ' ' + ($ruleValidate.validate) + ' ';
  2008. } else {
  2009. out += ' ' + ($valid) + ' = ' + ($ruleValidate.validate) + '; ';
  2010. }
  2011. } else if ($macro) {
  2012. var $it = it.util.copy(it);
  2013. $it.level++;
  2014. var $nextValid = 'valid' + $it.level;
  2015. $it.schema = $ruleValidate.validate;
  2016. $it.schemaPath = '';
  2017. var $wasComposite = it.compositeRule;
  2018. it.compositeRule = $it.compositeRule = true;
  2019. var $code = it.validate($it).replace(/validate\.schema/g, $validateCode);
  2020. it.compositeRule = $it.compositeRule = $wasComposite;
  2021. out += ' ' + ($code);
  2022. } else {
  2023. var $$outStack = $$outStack || [];
  2024. $$outStack.push(out);
  2025. out = '';
  2026. out += ' ' + ($validateCode) + '.call( ';
  2027. if (it.opts.passContext) {
  2028. out += 'this';
  2029. } else {
  2030. out += 'self';
  2031. }
  2032. if ($compile || $rDef.schema === false) {
  2033. out += ' , ' + ($data) + ' ';
  2034. } else {
  2035. out += ' , ' + ($schemaValue) + ' , ' + ($data) + ' , validate.schema' + (it.schemaPath) + ' ';
  2036. }
  2037. out += ' , (dataPath || \'\')';
  2038. if (it.errorPath != '""') {
  2039. out += ' + ' + (it.errorPath);
  2040. }
  2041. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  2042. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  2043. out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ' , rootData ) ';
  2044. var def_callRuleValidate = out;
  2045. out = $$outStack.pop();
  2046. if ($rDef.errors === false) {
  2047. out += ' ' + ($valid) + ' = ';
  2048. if ($asyncKeyword) {
  2049. out += '' + (it.yieldAwait);
  2050. }
  2051. out += '' + (def_callRuleValidate) + '; ';
  2052. } else {
  2053. if ($asyncKeyword) {
  2054. $ruleErrs = 'customErrors' + $lvl;
  2055. out += ' var ' + ($ruleErrs) + ' = null; try { ' + ($valid) + ' = ' + (it.yieldAwait) + (def_callRuleValidate) + '; } catch (e) { ' + ($valid) + ' = false; if (e instanceof ValidationError) ' + ($ruleErrs) + ' = e.errors; else throw e; } ';
  2056. } else {
  2057. out += ' ' + ($ruleErrs) + ' = null; ' + ($valid) + ' = ' + (def_callRuleValidate) + '; ';
  2058. }
  2059. }
  2060. }
  2061. if ($rDef.modifying) {
  2062. out += ' ' + ($data) + ' = ' + ($parentData) + '[' + ($parentDataProperty) + '];';
  2063. }
  2064. if ($validateSchema) {
  2065. out += ' }';
  2066. }
  2067. if ($rDef.valid) {
  2068. if ($breakOnError) {
  2069. out += ' if (true) { ';
  2070. }
  2071. } else {
  2072. out += ' if ( ';
  2073. if ($rDef.valid === undefined) {
  2074. out += ' !';
  2075. if ($macro) {
  2076. out += '' + ($nextValid);
  2077. } else {
  2078. out += '' + ($valid);
  2079. }
  2080. } else {
  2081. out += ' ' + (!$rDef.valid) + ' ';
  2082. }
  2083. out += ') { ';
  2084. $errorKeyword = $rule.keyword;
  2085. var $$outStack = $$outStack || [];
  2086. $$outStack.push(out);
  2087. out = '';
  2088. var $$outStack = $$outStack || [];
  2089. $$outStack.push(out);
  2090. out = ''; /* istanbul ignore else */
  2091. if (it.createErrors !== false) {
  2092. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  2093. if (it.opts.messages !== false) {
  2094. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  2095. }
  2096. if (it.opts.verbose) {
  2097. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2098. }
  2099. out += ' } ';
  2100. } else {
  2101. out += ' {} ';
  2102. }
  2103. var __err = out;
  2104. out = $$outStack.pop();
  2105. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2106. if (it.async) {
  2107. out += ' throw new ValidationError([' + (__err) + ']); ';
  2108. } else {
  2109. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2110. }
  2111. } else {
  2112. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2113. }
  2114. var def_customError = out;
  2115. out = $$outStack.pop();
  2116. if ($inline) {
  2117. if ($rDef.errors) {
  2118. if ($rDef.errors != 'full') {
  2119. out += ' for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  2120. if (it.opts.verbose) {
  2121. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  2122. }
  2123. out += ' } ';
  2124. }
  2125. } else {
  2126. if ($rDef.errors === false) {
  2127. out += ' ' + (def_customError) + ' ';
  2128. } else {
  2129. out += ' if (' + ($errs) + ' == errors) { ' + (def_customError) + ' } else { for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; if (' + ($ruleErr) + '.schemaPath === undefined) { ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; } ';
  2130. if (it.opts.verbose) {
  2131. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  2132. }
  2133. out += ' } } ';
  2134. }
  2135. }
  2136. } else if ($macro) {
  2137. out += ' var err = '; /* istanbul ignore else */
  2138. if (it.createErrors !== false) {
  2139. out += ' { keyword: \'' + ($errorKeyword || 'custom') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { keyword: \'' + ($rule.keyword) + '\' } ';
  2140. if (it.opts.messages !== false) {
  2141. out += ' , message: \'should pass "' + ($rule.keyword) + '" keyword validation\' ';
  2142. }
  2143. if (it.opts.verbose) {
  2144. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2145. }
  2146. out += ' } ';
  2147. } else {
  2148. out += ' {} ';
  2149. }
  2150. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2151. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2152. if (it.async) {
  2153. out += ' throw new ValidationError(vErrors); ';
  2154. } else {
  2155. out += ' validate.errors = vErrors; return false; ';
  2156. }
  2157. }
  2158. } else {
  2159. if ($rDef.errors === false) {
  2160. out += ' ' + (def_customError) + ' ';
  2161. } else {
  2162. out += ' if (Array.isArray(' + ($ruleErrs) + ')) { if (vErrors === null) vErrors = ' + ($ruleErrs) + '; else vErrors = vErrors.concat(' + ($ruleErrs) + '); errors = vErrors.length; for (var ' + ($i) + '=' + ($errs) + '; ' + ($i) + '<errors; ' + ($i) + '++) { var ' + ($ruleErr) + ' = vErrors[' + ($i) + ']; if (' + ($ruleErr) + '.dataPath === undefined) ' + ($ruleErr) + '.dataPath = (dataPath || \'\') + ' + (it.errorPath) + '; ' + ($ruleErr) + '.schemaPath = "' + ($errSchemaPath) + '"; ';
  2163. if (it.opts.verbose) {
  2164. out += ' ' + ($ruleErr) + '.schema = ' + ($schemaValue) + '; ' + ($ruleErr) + '.data = ' + ($data) + '; ';
  2165. }
  2166. out += ' } } else { ' + (def_customError) + ' } ';
  2167. }
  2168. }
  2169. out += ' } ';
  2170. if ($breakOnError) {
  2171. out += ' else { ';
  2172. }
  2173. }
  2174. return out;
  2175. }
  2176. },{}],22:[function(require,module,exports){
  2177. 'use strict';
  2178. module.exports = function generate_dependencies(it, $keyword) {
  2179. var out = ' ';
  2180. var $lvl = it.level;
  2181. var $dataLvl = it.dataLevel;
  2182. var $schema = it.schema[$keyword];
  2183. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2184. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2185. var $breakOnError = !it.opts.allErrors;
  2186. var $data = 'data' + ($dataLvl || '');
  2187. var $errs = 'errs__' + $lvl;
  2188. var $it = it.util.copy(it);
  2189. var $closingBraces = '';
  2190. $it.level++;
  2191. var $nextValid = 'valid' + $it.level;
  2192. var $schemaDeps = {},
  2193. $propertyDeps = {};
  2194. for ($property in $schema) {
  2195. var $sch = $schema[$property];
  2196. var $deps = Array.isArray($sch) ? $propertyDeps : $schemaDeps;
  2197. $deps[$property] = $sch;
  2198. }
  2199. out += 'var ' + ($errs) + ' = errors;';
  2200. var $currentErrorPath = it.errorPath;
  2201. out += 'var missing' + ($lvl) + ';';
  2202. for (var $property in $propertyDeps) {
  2203. $deps = $propertyDeps[$property];
  2204. out += ' if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined ';
  2205. if ($breakOnError) {
  2206. out += ' && ( ';
  2207. var arr1 = $deps;
  2208. if (arr1) {
  2209. var _$property, $i = -1,
  2210. l1 = arr1.length - 1;
  2211. while ($i < l1) {
  2212. _$property = arr1[$i += 1];
  2213. if ($i) {
  2214. out += ' || ';
  2215. }
  2216. var $prop = it.util.getProperty(_$property);
  2217. out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
  2218. }
  2219. }
  2220. out += ')) { ';
  2221. var $propertyPath = 'missing' + $lvl,
  2222. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  2223. if (it.opts._errorDataPathProperty) {
  2224. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  2225. }
  2226. var $$outStack = $$outStack || [];
  2227. $$outStack.push(out);
  2228. out = ''; /* istanbul ignore else */
  2229. if (it.createErrors !== false) {
  2230. out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
  2231. if (it.opts.messages !== false) {
  2232. out += ' , message: \'should have ';
  2233. if ($deps.length == 1) {
  2234. out += 'property ' + (it.util.escapeQuotes($deps[0]));
  2235. } else {
  2236. out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
  2237. }
  2238. out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
  2239. }
  2240. if (it.opts.verbose) {
  2241. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2242. }
  2243. out += ' } ';
  2244. } else {
  2245. out += ' {} ';
  2246. }
  2247. var __err = out;
  2248. out = $$outStack.pop();
  2249. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2250. if (it.async) {
  2251. out += ' throw new ValidationError([' + (__err) + ']); ';
  2252. } else {
  2253. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2254. }
  2255. } else {
  2256. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2257. }
  2258. } else {
  2259. out += ' ) { ';
  2260. var arr2 = $deps;
  2261. if (arr2) {
  2262. var $reqProperty, i2 = -1,
  2263. l2 = arr2.length - 1;
  2264. while (i2 < l2) {
  2265. $reqProperty = arr2[i2 += 1];
  2266. var $prop = it.util.getProperty($reqProperty),
  2267. $missingProperty = it.util.escapeQuotes($reqProperty);
  2268. if (it.opts._errorDataPathProperty) {
  2269. it.errorPath = it.util.getPath($currentErrorPath, $reqProperty, it.opts.jsonPointers);
  2270. }
  2271. out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */
  2272. if (it.createErrors !== false) {
  2273. out += ' { keyword: \'' + ('dependencies') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { property: \'' + (it.util.escapeQuotes($property)) + '\', missingProperty: \'' + ($missingProperty) + '\', depsCount: ' + ($deps.length) + ', deps: \'' + (it.util.escapeQuotes($deps.length == 1 ? $deps[0] : $deps.join(", "))) + '\' } ';
  2274. if (it.opts.messages !== false) {
  2275. out += ' , message: \'should have ';
  2276. if ($deps.length == 1) {
  2277. out += 'property ' + (it.util.escapeQuotes($deps[0]));
  2278. } else {
  2279. out += 'properties ' + (it.util.escapeQuotes($deps.join(", ")));
  2280. }
  2281. out += ' when property ' + (it.util.escapeQuotes($property)) + ' is present\' ';
  2282. }
  2283. if (it.opts.verbose) {
  2284. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2285. }
  2286. out += ' } ';
  2287. } else {
  2288. out += ' {} ';
  2289. }
  2290. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  2291. }
  2292. }
  2293. }
  2294. out += ' } ';
  2295. if ($breakOnError) {
  2296. $closingBraces += '}';
  2297. out += ' else { ';
  2298. }
  2299. }
  2300. it.errorPath = $currentErrorPath;
  2301. var $currentBaseId = $it.baseId;
  2302. for (var $property in $schemaDeps) {
  2303. var $sch = $schemaDeps[$property];
  2304. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2305. out += ' ' + ($nextValid) + ' = true; if (' + ($data) + (it.util.getProperty($property)) + ' !== undefined) { ';
  2306. $it.schema = $sch;
  2307. $it.schemaPath = $schemaPath + it.util.getProperty($property);
  2308. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($property);
  2309. out += ' ' + (it.validate($it)) + ' ';
  2310. $it.baseId = $currentBaseId;
  2311. out += ' } ';
  2312. if ($breakOnError) {
  2313. out += ' if (' + ($nextValid) + ') { ';
  2314. $closingBraces += '}';
  2315. }
  2316. }
  2317. }
  2318. if ($breakOnError) {
  2319. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  2320. }
  2321. out = it.util.cleanUpCode(out);
  2322. return out;
  2323. }
  2324. },{}],23:[function(require,module,exports){
  2325. 'use strict';
  2326. module.exports = function generate_enum(it, $keyword) {
  2327. var out = ' ';
  2328. var $lvl = it.level;
  2329. var $dataLvl = it.dataLevel;
  2330. var $schema = it.schema[$keyword];
  2331. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2332. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2333. var $breakOnError = !it.opts.allErrors;
  2334. var $data = 'data' + ($dataLvl || '');
  2335. var $valid = 'valid' + $lvl;
  2336. var $isData = it.opts.v5 && $schema && $schema.$data,
  2337. $schemaValue;
  2338. if ($isData) {
  2339. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2340. $schemaValue = 'schema' + $lvl;
  2341. } else {
  2342. $schemaValue = $schema;
  2343. }
  2344. var $i = 'i' + $lvl,
  2345. $vSchema = 'schema' + $lvl;
  2346. if (!$isData) {
  2347. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + ';';
  2348. }
  2349. out += 'var ' + ($valid) + ';';
  2350. if ($isData) {
  2351. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  2352. }
  2353. out += '' + ($valid) + ' = false;for (var ' + ($i) + '=0; ' + ($i) + '<' + ($vSchema) + '.length; ' + ($i) + '++) if (equal(' + ($data) + ', ' + ($vSchema) + '[' + ($i) + '])) { ' + ($valid) + ' = true; break; }';
  2354. if ($isData) {
  2355. out += ' } ';
  2356. }
  2357. out += ' if (!' + ($valid) + ') { ';
  2358. var $$outStack = $$outStack || [];
  2359. $$outStack.push(out);
  2360. out = ''; /* istanbul ignore else */
  2361. if (it.createErrors !== false) {
  2362. out += ' { keyword: \'' + ('enum') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { allowedValues: schema' + ($lvl) + ' } ';
  2363. if (it.opts.messages !== false) {
  2364. out += ' , message: \'should be equal to one of the allowed values\' ';
  2365. }
  2366. if (it.opts.verbose) {
  2367. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2368. }
  2369. out += ' } ';
  2370. } else {
  2371. out += ' {} ';
  2372. }
  2373. var __err = out;
  2374. out = $$outStack.pop();
  2375. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2376. if (it.async) {
  2377. out += ' throw new ValidationError([' + (__err) + ']); ';
  2378. } else {
  2379. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2380. }
  2381. } else {
  2382. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2383. }
  2384. out += ' }';
  2385. if ($breakOnError) {
  2386. out += ' else { ';
  2387. }
  2388. return out;
  2389. }
  2390. },{}],24:[function(require,module,exports){
  2391. 'use strict';
  2392. module.exports = function generate_format(it, $keyword) {
  2393. var out = ' ';
  2394. var $lvl = it.level;
  2395. var $dataLvl = it.dataLevel;
  2396. var $schema = it.schema[$keyword];
  2397. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2398. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2399. var $breakOnError = !it.opts.allErrors;
  2400. var $data = 'data' + ($dataLvl || '');
  2401. if (it.opts.format === false) {
  2402. if ($breakOnError) {
  2403. out += ' if (true) { ';
  2404. }
  2405. return out;
  2406. }
  2407. var $isData = it.opts.v5 && $schema && $schema.$data,
  2408. $schemaValue;
  2409. if ($isData) {
  2410. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2411. $schemaValue = 'schema' + $lvl;
  2412. } else {
  2413. $schemaValue = $schema;
  2414. }
  2415. var $unknownFormats = it.opts.unknownFormats,
  2416. $allowUnknown = Array.isArray($unknownFormats);
  2417. if ($isData) {
  2418. var $format = 'format' + $lvl;
  2419. out += ' var ' + ($format) + ' = formats[' + ($schemaValue) + ']; var isObject' + ($lvl) + ' = typeof ' + ($format) + ' == \'object\' && !(' + ($format) + ' instanceof RegExp) && ' + ($format) + '.validate; if (isObject' + ($lvl) + ') { ';
  2420. if (it.async) {
  2421. out += ' var async' + ($lvl) + ' = ' + ($format) + '.async; ';
  2422. }
  2423. out += ' ' + ($format) + ' = ' + ($format) + '.validate; } if ( ';
  2424. if ($isData) {
  2425. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  2426. }
  2427. out += ' (';
  2428. if ($unknownFormats === true || $allowUnknown) {
  2429. out += ' (' + ($schemaValue) + ' && !' + ($format) + ' ';
  2430. if ($allowUnknown) {
  2431. out += ' && self._opts.unknownFormats.indexOf(' + ($schemaValue) + ') == -1 ';
  2432. }
  2433. out += ') || ';
  2434. }
  2435. out += ' (' + ($format) + ' && !(typeof ' + ($format) + ' == \'function\' ? ';
  2436. if (it.async) {
  2437. out += ' (async' + ($lvl) + ' ? ' + (it.yieldAwait) + ' ' + ($format) + '(' + ($data) + ') : ' + ($format) + '(' + ($data) + ')) ';
  2438. } else {
  2439. out += ' ' + ($format) + '(' + ($data) + ') ';
  2440. }
  2441. out += ' : ' + ($format) + '.test(' + ($data) + '))))) {';
  2442. } else {
  2443. var $format = it.formats[$schema];
  2444. if (!$format) {
  2445. if ($unknownFormats === true || ($allowUnknown && $unknownFormats.indexOf($schema) == -1)) {
  2446. throw new Error('unknown format "' + $schema + '" is used in schema at path "' + it.errSchemaPath + '"');
  2447. } else {
  2448. if (!$allowUnknown) {
  2449. console.warn('unknown format "' + $schema + '" ignored in schema at path "' + it.errSchemaPath + '"');
  2450. if ($unknownFormats !== 'ignore') console.warn('In the next major version it will throw exception. See option unknownFormats for more information');
  2451. }
  2452. if ($breakOnError) {
  2453. out += ' if (true) { ';
  2454. }
  2455. return out;
  2456. }
  2457. }
  2458. var $isObject = typeof $format == 'object' && !($format instanceof RegExp) && $format.validate;
  2459. if ($isObject) {
  2460. var $async = $format.async === true;
  2461. $format = $format.validate;
  2462. }
  2463. if ($async) {
  2464. if (!it.async) throw new Error('async format in sync schema');
  2465. var $formatRef = 'formats' + it.util.getProperty($schema) + '.validate';
  2466. out += ' if (!(' + (it.yieldAwait) + ' ' + ($formatRef) + '(' + ($data) + '))) { ';
  2467. } else {
  2468. out += ' if (! ';
  2469. var $formatRef = 'formats' + it.util.getProperty($schema);
  2470. if ($isObject) $formatRef += '.validate';
  2471. if (typeof $format == 'function') {
  2472. out += ' ' + ($formatRef) + '(' + ($data) + ') ';
  2473. } else {
  2474. out += ' ' + ($formatRef) + '.test(' + ($data) + ') ';
  2475. }
  2476. out += ') { ';
  2477. }
  2478. }
  2479. var $$outStack = $$outStack || [];
  2480. $$outStack.push(out);
  2481. out = ''; /* istanbul ignore else */
  2482. if (it.createErrors !== false) {
  2483. out += ' { keyword: \'' + ('format') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { format: ';
  2484. if ($isData) {
  2485. out += '' + ($schemaValue);
  2486. } else {
  2487. out += '' + (it.util.toQuotedString($schema));
  2488. }
  2489. out += ' } ';
  2490. if (it.opts.messages !== false) {
  2491. out += ' , message: \'should match format "';
  2492. if ($isData) {
  2493. out += '\' + ' + ($schemaValue) + ' + \'';
  2494. } else {
  2495. out += '' + (it.util.escapeQuotes($schema));
  2496. }
  2497. out += '"\' ';
  2498. }
  2499. if (it.opts.verbose) {
  2500. out += ' , schema: ';
  2501. if ($isData) {
  2502. out += 'validate.schema' + ($schemaPath);
  2503. } else {
  2504. out += '' + (it.util.toQuotedString($schema));
  2505. }
  2506. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2507. }
  2508. out += ' } ';
  2509. } else {
  2510. out += ' {} ';
  2511. }
  2512. var __err = out;
  2513. out = $$outStack.pop();
  2514. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2515. if (it.async) {
  2516. out += ' throw new ValidationError([' + (__err) + ']); ';
  2517. } else {
  2518. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2519. }
  2520. } else {
  2521. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2522. }
  2523. out += ' } ';
  2524. if ($breakOnError) {
  2525. out += ' else { ';
  2526. }
  2527. return out;
  2528. }
  2529. },{}],25:[function(require,module,exports){
  2530. 'use strict';
  2531. module.exports = function generate_items(it, $keyword) {
  2532. var out = ' ';
  2533. var $lvl = it.level;
  2534. var $dataLvl = it.dataLevel;
  2535. var $schema = it.schema[$keyword];
  2536. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2537. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2538. var $breakOnError = !it.opts.allErrors;
  2539. var $data = 'data' + ($dataLvl || '');
  2540. var $valid = 'valid' + $lvl;
  2541. var $errs = 'errs__' + $lvl;
  2542. var $it = it.util.copy(it);
  2543. var $closingBraces = '';
  2544. $it.level++;
  2545. var $nextValid = 'valid' + $it.level;
  2546. var $idx = 'i' + $lvl,
  2547. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  2548. $nextData = 'data' + $dataNxt,
  2549. $currentBaseId = it.baseId;
  2550. out += 'var ' + ($errs) + ' = errors;var ' + ($valid) + ';';
  2551. if (Array.isArray($schema)) {
  2552. var $additionalItems = it.schema.additionalItems;
  2553. if ($additionalItems === false) {
  2554. out += ' ' + ($valid) + ' = ' + ($data) + '.length <= ' + ($schema.length) + '; ';
  2555. var $currErrSchemaPath = $errSchemaPath;
  2556. $errSchemaPath = it.errSchemaPath + '/additionalItems';
  2557. out += ' if (!' + ($valid) + ') { ';
  2558. var $$outStack = $$outStack || [];
  2559. $$outStack.push(out);
  2560. out = ''; /* istanbul ignore else */
  2561. if (it.createErrors !== false) {
  2562. out += ' { keyword: \'' + ('additionalItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schema.length) + ' } ';
  2563. if (it.opts.messages !== false) {
  2564. out += ' , message: \'should NOT have more than ' + ($schema.length) + ' items\' ';
  2565. }
  2566. if (it.opts.verbose) {
  2567. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2568. }
  2569. out += ' } ';
  2570. } else {
  2571. out += ' {} ';
  2572. }
  2573. var __err = out;
  2574. out = $$outStack.pop();
  2575. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2576. if (it.async) {
  2577. out += ' throw new ValidationError([' + (__err) + ']); ';
  2578. } else {
  2579. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2580. }
  2581. } else {
  2582. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2583. }
  2584. out += ' } ';
  2585. $errSchemaPath = $currErrSchemaPath;
  2586. if ($breakOnError) {
  2587. $closingBraces += '}';
  2588. out += ' else { ';
  2589. }
  2590. }
  2591. var arr1 = $schema;
  2592. if (arr1) {
  2593. var $sch, $i = -1,
  2594. l1 = arr1.length - 1;
  2595. while ($i < l1) {
  2596. $sch = arr1[$i += 1];
  2597. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2598. out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($i) + ') { ';
  2599. var $passData = $data + '[' + $i + ']';
  2600. $it.schema = $sch;
  2601. $it.schemaPath = $schemaPath + '[' + $i + ']';
  2602. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  2603. $it.errorPath = it.util.getPathExpr(it.errorPath, $i, it.opts.jsonPointers, true);
  2604. $it.dataPathArr[$dataNxt] = $i;
  2605. var $code = it.validate($it);
  2606. $it.baseId = $currentBaseId;
  2607. if (it.util.varOccurences($code, $nextData) < 2) {
  2608. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2609. } else {
  2610. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2611. }
  2612. out += ' } ';
  2613. if ($breakOnError) {
  2614. out += ' if (' + ($nextValid) + ') { ';
  2615. $closingBraces += '}';
  2616. }
  2617. }
  2618. }
  2619. }
  2620. if (typeof $additionalItems == 'object' && it.util.schemaHasRules($additionalItems, it.RULES.all)) {
  2621. $it.schema = $additionalItems;
  2622. $it.schemaPath = it.schemaPath + '.additionalItems';
  2623. $it.errSchemaPath = it.errSchemaPath + '/additionalItems';
  2624. out += ' ' + ($nextValid) + ' = true; if (' + ($data) + '.length > ' + ($schema.length) + ') { for (var ' + ($idx) + ' = ' + ($schema.length) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
  2625. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  2626. var $passData = $data + '[' + $idx + ']';
  2627. $it.dataPathArr[$dataNxt] = $idx;
  2628. var $code = it.validate($it);
  2629. $it.baseId = $currentBaseId;
  2630. if (it.util.varOccurences($code, $nextData) < 2) {
  2631. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2632. } else {
  2633. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2634. }
  2635. if ($breakOnError) {
  2636. out += ' if (!' + ($nextValid) + ') break; ';
  2637. }
  2638. out += ' } } ';
  2639. if ($breakOnError) {
  2640. out += ' if (' + ($nextValid) + ') { ';
  2641. $closingBraces += '}';
  2642. }
  2643. }
  2644. } else if (it.util.schemaHasRules($schema, it.RULES.all)) {
  2645. $it.schema = $schema;
  2646. $it.schemaPath = $schemaPath;
  2647. $it.errSchemaPath = $errSchemaPath;
  2648. out += ' for (var ' + ($idx) + ' = ' + (0) + '; ' + ($idx) + ' < ' + ($data) + '.length; ' + ($idx) + '++) { ';
  2649. $it.errorPath = it.util.getPathExpr(it.errorPath, $idx, it.opts.jsonPointers, true);
  2650. var $passData = $data + '[' + $idx + ']';
  2651. $it.dataPathArr[$dataNxt] = $idx;
  2652. var $code = it.validate($it);
  2653. $it.baseId = $currentBaseId;
  2654. if (it.util.varOccurences($code, $nextData) < 2) {
  2655. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  2656. } else {
  2657. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  2658. }
  2659. if ($breakOnError) {
  2660. out += ' if (!' + ($nextValid) + ') break; ';
  2661. }
  2662. out += ' } ';
  2663. if ($breakOnError) {
  2664. out += ' if (' + ($nextValid) + ') { ';
  2665. $closingBraces += '}';
  2666. }
  2667. }
  2668. if ($breakOnError) {
  2669. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  2670. }
  2671. out = it.util.cleanUpCode(out);
  2672. return out;
  2673. }
  2674. },{}],26:[function(require,module,exports){
  2675. 'use strict';
  2676. module.exports = function generate_multipleOf(it, $keyword) {
  2677. var out = ' ';
  2678. var $lvl = it.level;
  2679. var $dataLvl = it.dataLevel;
  2680. var $schema = it.schema[$keyword];
  2681. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2682. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2683. var $breakOnError = !it.opts.allErrors;
  2684. var $data = 'data' + ($dataLvl || '');
  2685. var $isData = it.opts.v5 && $schema && $schema.$data,
  2686. $schemaValue;
  2687. if ($isData) {
  2688. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2689. $schemaValue = 'schema' + $lvl;
  2690. } else {
  2691. $schemaValue = $schema;
  2692. }
  2693. out += 'var division' + ($lvl) + ';if (';
  2694. if ($isData) {
  2695. out += ' ' + ($schemaValue) + ' !== undefined && ( typeof ' + ($schemaValue) + ' != \'number\' || ';
  2696. }
  2697. out += ' (division' + ($lvl) + ' = ' + ($data) + ' / ' + ($schemaValue) + ', ';
  2698. if (it.opts.multipleOfPrecision) {
  2699. out += ' Math.abs(Math.round(division' + ($lvl) + ') - division' + ($lvl) + ') > 1e-' + (it.opts.multipleOfPrecision) + ' ';
  2700. } else {
  2701. out += ' division' + ($lvl) + ' !== parseInt(division' + ($lvl) + ') ';
  2702. }
  2703. out += ' ) ';
  2704. if ($isData) {
  2705. out += ' ) ';
  2706. }
  2707. out += ' ) { ';
  2708. var $$outStack = $$outStack || [];
  2709. $$outStack.push(out);
  2710. out = ''; /* istanbul ignore else */
  2711. if (it.createErrors !== false) {
  2712. out += ' { keyword: \'' + ('multipleOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { multipleOf: ' + ($schemaValue) + ' } ';
  2713. if (it.opts.messages !== false) {
  2714. out += ' , message: \'should be multiple of ';
  2715. if ($isData) {
  2716. out += '\' + ' + ($schemaValue);
  2717. } else {
  2718. out += '' + ($schema) + '\'';
  2719. }
  2720. }
  2721. if (it.opts.verbose) {
  2722. out += ' , schema: ';
  2723. if ($isData) {
  2724. out += 'validate.schema' + ($schemaPath);
  2725. } else {
  2726. out += '' + ($schema);
  2727. }
  2728. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2729. }
  2730. out += ' } ';
  2731. } else {
  2732. out += ' {} ';
  2733. }
  2734. var __err = out;
  2735. out = $$outStack.pop();
  2736. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2737. if (it.async) {
  2738. out += ' throw new ValidationError([' + (__err) + ']); ';
  2739. } else {
  2740. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2741. }
  2742. } else {
  2743. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2744. }
  2745. out += '} ';
  2746. if ($breakOnError) {
  2747. out += ' else { ';
  2748. }
  2749. return out;
  2750. }
  2751. },{}],27:[function(require,module,exports){
  2752. 'use strict';
  2753. module.exports = function generate_not(it, $keyword) {
  2754. var out = ' ';
  2755. var $lvl = it.level;
  2756. var $dataLvl = it.dataLevel;
  2757. var $schema = it.schema[$keyword];
  2758. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2759. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2760. var $breakOnError = !it.opts.allErrors;
  2761. var $data = 'data' + ($dataLvl || '');
  2762. var $errs = 'errs__' + $lvl;
  2763. var $it = it.util.copy(it);
  2764. $it.level++;
  2765. var $nextValid = 'valid' + $it.level;
  2766. if (it.util.schemaHasRules($schema, it.RULES.all)) {
  2767. $it.schema = $schema;
  2768. $it.schemaPath = $schemaPath;
  2769. $it.errSchemaPath = $errSchemaPath;
  2770. out += ' var ' + ($errs) + ' = errors; ';
  2771. var $wasComposite = it.compositeRule;
  2772. it.compositeRule = $it.compositeRule = true;
  2773. $it.createErrors = false;
  2774. var $allErrorsOption;
  2775. if ($it.opts.allErrors) {
  2776. $allErrorsOption = $it.opts.allErrors;
  2777. $it.opts.allErrors = false;
  2778. }
  2779. out += ' ' + (it.validate($it)) + ' ';
  2780. $it.createErrors = true;
  2781. if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
  2782. it.compositeRule = $it.compositeRule = $wasComposite;
  2783. out += ' if (' + ($nextValid) + ') { ';
  2784. var $$outStack = $$outStack || [];
  2785. $$outStack.push(out);
  2786. out = ''; /* istanbul ignore else */
  2787. if (it.createErrors !== false) {
  2788. out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2789. if (it.opts.messages !== false) {
  2790. out += ' , message: \'should NOT be valid\' ';
  2791. }
  2792. if (it.opts.verbose) {
  2793. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2794. }
  2795. out += ' } ';
  2796. } else {
  2797. out += ' {} ';
  2798. }
  2799. var __err = out;
  2800. out = $$outStack.pop();
  2801. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2802. if (it.async) {
  2803. out += ' throw new ValidationError([' + (__err) + ']); ';
  2804. } else {
  2805. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2806. }
  2807. } else {
  2808. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2809. }
  2810. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
  2811. if (it.opts.allErrors) {
  2812. out += ' } ';
  2813. }
  2814. } else {
  2815. out += ' var err = '; /* istanbul ignore else */
  2816. if (it.createErrors !== false) {
  2817. out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2818. if (it.opts.messages !== false) {
  2819. out += ' , message: \'should NOT be valid\' ';
  2820. }
  2821. if (it.opts.verbose) {
  2822. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2823. }
  2824. out += ' } ';
  2825. } else {
  2826. out += ' {} ';
  2827. }
  2828. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2829. if ($breakOnError) {
  2830. out += ' if (false) { ';
  2831. }
  2832. }
  2833. return out;
  2834. }
  2835. },{}],28:[function(require,module,exports){
  2836. 'use strict';
  2837. module.exports = function generate_oneOf(it, $keyword) {
  2838. var out = ' ';
  2839. var $lvl = it.level;
  2840. var $dataLvl = it.dataLevel;
  2841. var $schema = it.schema[$keyword];
  2842. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2843. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2844. var $breakOnError = !it.opts.allErrors;
  2845. var $data = 'data' + ($dataLvl || '');
  2846. var $valid = 'valid' + $lvl;
  2847. var $errs = 'errs__' + $lvl;
  2848. var $it = it.util.copy(it);
  2849. var $closingBraces = '';
  2850. $it.level++;
  2851. var $nextValid = 'valid' + $it.level;
  2852. out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;';
  2853. var $currentBaseId = $it.baseId;
  2854. var $wasComposite = it.compositeRule;
  2855. it.compositeRule = $it.compositeRule = true;
  2856. var arr1 = $schema;
  2857. if (arr1) {
  2858. var $sch, $i = -1,
  2859. l1 = arr1.length - 1;
  2860. while ($i < l1) {
  2861. $sch = arr1[$i += 1];
  2862. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  2863. $it.schema = $sch;
  2864. $it.schemaPath = $schemaPath + '[' + $i + ']';
  2865. $it.errSchemaPath = $errSchemaPath + '/' + $i;
  2866. out += ' ' + (it.validate($it)) + ' ';
  2867. $it.baseId = $currentBaseId;
  2868. } else {
  2869. out += ' var ' + ($nextValid) + ' = true; ';
  2870. }
  2871. if ($i) {
  2872. out += ' if (' + ($nextValid) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
  2873. $closingBraces += '}';
  2874. }
  2875. out += ' if (' + ($nextValid) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
  2876. }
  2877. }
  2878. it.compositeRule = $it.compositeRule = $wasComposite;
  2879. out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
  2880. var $$outStack = $$outStack || [];
  2881. $$outStack.push(out);
  2882. out = ''; /* istanbul ignore else */
  2883. if (it.createErrors !== false) {
  2884. out += ' { keyword: \'' + ('oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
  2885. if (it.opts.messages !== false) {
  2886. out += ' , message: \'should match exactly one schema in oneOf\' ';
  2887. }
  2888. if (it.opts.verbose) {
  2889. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2890. }
  2891. out += ' } ';
  2892. } else {
  2893. out += ' {} ';
  2894. }
  2895. var __err = out;
  2896. out = $$outStack.pop();
  2897. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2898. if (it.async) {
  2899. out += ' throw new ValidationError([' + (__err) + ']); ';
  2900. } else {
  2901. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2902. }
  2903. } else {
  2904. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2905. }
  2906. out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
  2907. if (it.opts.allErrors) {
  2908. out += ' } ';
  2909. }
  2910. return out;
  2911. }
  2912. },{}],29:[function(require,module,exports){
  2913. 'use strict';
  2914. module.exports = function generate_pattern(it, $keyword) {
  2915. var out = ' ';
  2916. var $lvl = it.level;
  2917. var $dataLvl = it.dataLevel;
  2918. var $schema = it.schema[$keyword];
  2919. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2920. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2921. var $breakOnError = !it.opts.allErrors;
  2922. var $data = 'data' + ($dataLvl || '');
  2923. var $isData = it.opts.v5 && $schema && $schema.$data,
  2924. $schemaValue;
  2925. if ($isData) {
  2926. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  2927. $schemaValue = 'schema' + $lvl;
  2928. } else {
  2929. $schemaValue = $schema;
  2930. }
  2931. var $regexp = $isData ? '(new RegExp(' + $schemaValue + '))' : it.usePattern($schema);
  2932. out += 'if ( ';
  2933. if ($isData) {
  2934. out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'string\') || ';
  2935. }
  2936. out += ' !' + ($regexp) + '.test(' + ($data) + ') ) { ';
  2937. var $$outStack = $$outStack || [];
  2938. $$outStack.push(out);
  2939. out = ''; /* istanbul ignore else */
  2940. if (it.createErrors !== false) {
  2941. out += ' { keyword: \'' + ('pattern') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { pattern: ';
  2942. if ($isData) {
  2943. out += '' + ($schemaValue);
  2944. } else {
  2945. out += '' + (it.util.toQuotedString($schema));
  2946. }
  2947. out += ' } ';
  2948. if (it.opts.messages !== false) {
  2949. out += ' , message: \'should match pattern "';
  2950. if ($isData) {
  2951. out += '\' + ' + ($schemaValue) + ' + \'';
  2952. } else {
  2953. out += '' + (it.util.escapeQuotes($schema));
  2954. }
  2955. out += '"\' ';
  2956. }
  2957. if (it.opts.verbose) {
  2958. out += ' , schema: ';
  2959. if ($isData) {
  2960. out += 'validate.schema' + ($schemaPath);
  2961. } else {
  2962. out += '' + (it.util.toQuotedString($schema));
  2963. }
  2964. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  2965. }
  2966. out += ' } ';
  2967. } else {
  2968. out += ' {} ';
  2969. }
  2970. var __err = out;
  2971. out = $$outStack.pop();
  2972. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  2973. if (it.async) {
  2974. out += ' throw new ValidationError([' + (__err) + ']); ';
  2975. } else {
  2976. out += ' validate.errors = [' + (__err) + ']; return false; ';
  2977. }
  2978. } else {
  2979. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  2980. }
  2981. out += '} ';
  2982. if ($breakOnError) {
  2983. out += ' else { ';
  2984. }
  2985. return out;
  2986. }
  2987. },{}],30:[function(require,module,exports){
  2988. 'use strict';
  2989. module.exports = function generate_patternRequired(it, $keyword) {
  2990. var out = ' ';
  2991. var $lvl = it.level;
  2992. var $dataLvl = it.dataLevel;
  2993. var $schema = it.schema[$keyword];
  2994. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  2995. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  2996. var $breakOnError = !it.opts.allErrors;
  2997. var $data = 'data' + ($dataLvl || '');
  2998. var $valid = 'valid' + $lvl;
  2999. var $key = 'key' + $lvl,
  3000. $matched = 'patternMatched' + $lvl,
  3001. $closingBraces = '',
  3002. $ownProperties = it.opts.ownProperties;
  3003. out += 'var ' + ($valid) + ' = true;';
  3004. var arr1 = $schema;
  3005. if (arr1) {
  3006. var $pProperty, i1 = -1,
  3007. l1 = arr1.length - 1;
  3008. while (i1 < l1) {
  3009. $pProperty = arr1[i1 += 1];
  3010. out += ' var ' + ($matched) + ' = false; for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3011. if ($ownProperties) {
  3012. out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
  3013. }
  3014. out += ' ' + ($matched) + ' = ' + (it.usePattern($pProperty)) + '.test(' + ($key) + '); if (' + ($matched) + ') break; } ';
  3015. var $missingPattern = it.util.escapeQuotes($pProperty);
  3016. out += ' if (!' + ($matched) + ') { ' + ($valid) + ' = false; var err = '; /* istanbul ignore else */
  3017. if (it.createErrors !== false) {
  3018. out += ' { keyword: \'' + ('patternRequired') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingPattern: \'' + ($missingPattern) + '\' } ';
  3019. if (it.opts.messages !== false) {
  3020. out += ' , message: \'should have property matching pattern \\\'' + ($missingPattern) + '\\\'\' ';
  3021. }
  3022. if (it.opts.verbose) {
  3023. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3024. }
  3025. out += ' } ';
  3026. } else {
  3027. out += ' {} ';
  3028. }
  3029. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  3030. if ($breakOnError) {
  3031. $closingBraces += '}';
  3032. out += ' else { ';
  3033. }
  3034. }
  3035. }
  3036. out += '' + ($closingBraces);
  3037. return out;
  3038. }
  3039. },{}],31:[function(require,module,exports){
  3040. 'use strict';
  3041. module.exports = function generate_properties(it, $keyword) {
  3042. var out = ' ';
  3043. var $lvl = it.level;
  3044. var $dataLvl = it.dataLevel;
  3045. var $schema = it.schema[$keyword];
  3046. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3047. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3048. var $breakOnError = !it.opts.allErrors;
  3049. var $data = 'data' + ($dataLvl || '');
  3050. var $valid = 'valid' + $lvl;
  3051. var $errs = 'errs__' + $lvl;
  3052. var $it = it.util.copy(it);
  3053. var $closingBraces = '';
  3054. $it.level++;
  3055. var $nextValid = 'valid' + $it.level;
  3056. var $key = 'key' + $lvl,
  3057. $dataNxt = $it.dataLevel = it.dataLevel + 1,
  3058. $nextData = 'data' + $dataNxt;
  3059. var $schemaKeys = Object.keys($schema || {}),
  3060. $pProperties = it.schema.patternProperties || {},
  3061. $pPropertyKeys = Object.keys($pProperties),
  3062. $aProperties = it.schema.additionalProperties,
  3063. $someProperties = $schemaKeys.length || $pPropertyKeys.length,
  3064. $noAdditional = $aProperties === false,
  3065. $additionalIsSchema = typeof $aProperties == 'object' && Object.keys($aProperties).length,
  3066. $removeAdditional = it.opts.removeAdditional,
  3067. $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional,
  3068. $ownProperties = it.opts.ownProperties,
  3069. $currentBaseId = it.baseId;
  3070. var $required = it.schema.required;
  3071. if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired) var $requiredHash = it.util.toHash($required);
  3072. if (it.opts.v5) {
  3073. var $pgProperties = it.schema.patternGroups || {},
  3074. $pgPropertyKeys = Object.keys($pgProperties);
  3075. }
  3076. out += 'var ' + ($errs) + ' = errors;var ' + ($nextValid) + ' = true;';
  3077. if ($checkAdditional) {
  3078. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3079. if ($ownProperties) {
  3080. out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
  3081. }
  3082. if ($someProperties) {
  3083. out += ' var isAdditional' + ($lvl) + ' = !(false ';
  3084. if ($schemaKeys.length) {
  3085. if ($schemaKeys.length > 5) {
  3086. out += ' || validate.schema' + ($schemaPath) + '[' + ($key) + '] ';
  3087. } else {
  3088. var arr1 = $schemaKeys;
  3089. if (arr1) {
  3090. var $propertyKey, i1 = -1,
  3091. l1 = arr1.length - 1;
  3092. while (i1 < l1) {
  3093. $propertyKey = arr1[i1 += 1];
  3094. out += ' || ' + ($key) + ' == ' + (it.util.toQuotedString($propertyKey)) + ' ';
  3095. }
  3096. }
  3097. }
  3098. }
  3099. if ($pPropertyKeys.length) {
  3100. var arr2 = $pPropertyKeys;
  3101. if (arr2) {
  3102. var $pProperty, $i = -1,
  3103. l2 = arr2.length - 1;
  3104. while ($i < l2) {
  3105. $pProperty = arr2[$i += 1];
  3106. out += ' || ' + (it.usePattern($pProperty)) + '.test(' + ($key) + ') ';
  3107. }
  3108. }
  3109. }
  3110. if (it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length) {
  3111. var arr3 = $pgPropertyKeys;
  3112. if (arr3) {
  3113. var $pgProperty, $i = -1,
  3114. l3 = arr3.length - 1;
  3115. while ($i < l3) {
  3116. $pgProperty = arr3[$i += 1];
  3117. out += ' || ' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ') ';
  3118. }
  3119. }
  3120. }
  3121. out += ' ); if (isAdditional' + ($lvl) + ') { ';
  3122. }
  3123. if ($removeAdditional == 'all') {
  3124. out += ' delete ' + ($data) + '[' + ($key) + ']; ';
  3125. } else {
  3126. var $currentErrorPath = it.errorPath;
  3127. var $additionalProperty = '\' + ' + $key + ' + \'';
  3128. if (it.opts._errorDataPathProperty) {
  3129. it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3130. }
  3131. if ($noAdditional) {
  3132. if ($removeAdditional) {
  3133. out += ' delete ' + ($data) + '[' + ($key) + ']; ';
  3134. } else {
  3135. out += ' ' + ($nextValid) + ' = false; ';
  3136. var $currErrSchemaPath = $errSchemaPath;
  3137. $errSchemaPath = it.errSchemaPath + '/additionalProperties';
  3138. var $$outStack = $$outStack || [];
  3139. $$outStack.push(out);
  3140. out = ''; /* istanbul ignore else */
  3141. if (it.createErrors !== false) {
  3142. out += ' { keyword: \'' + ('additionalProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { additionalProperty: \'' + ($additionalProperty) + '\' } ';
  3143. if (it.opts.messages !== false) {
  3144. out += ' , message: \'should NOT have additional properties\' ';
  3145. }
  3146. if (it.opts.verbose) {
  3147. out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3148. }
  3149. out += ' } ';
  3150. } else {
  3151. out += ' {} ';
  3152. }
  3153. var __err = out;
  3154. out = $$outStack.pop();
  3155. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3156. if (it.async) {
  3157. out += ' throw new ValidationError([' + (__err) + ']); ';
  3158. } else {
  3159. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3160. }
  3161. } else {
  3162. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3163. }
  3164. $errSchemaPath = $currErrSchemaPath;
  3165. if ($breakOnError) {
  3166. out += ' break; ';
  3167. }
  3168. }
  3169. } else if ($additionalIsSchema) {
  3170. if ($removeAdditional == 'failing') {
  3171. out += ' var ' + ($errs) + ' = errors; ';
  3172. var $wasComposite = it.compositeRule;
  3173. it.compositeRule = $it.compositeRule = true;
  3174. $it.schema = $aProperties;
  3175. $it.schemaPath = it.schemaPath + '.additionalProperties';
  3176. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  3177. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3178. var $passData = $data + '[' + $key + ']';
  3179. $it.dataPathArr[$dataNxt] = $key;
  3180. var $code = it.validate($it);
  3181. $it.baseId = $currentBaseId;
  3182. if (it.util.varOccurences($code, $nextData) < 2) {
  3183. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3184. } else {
  3185. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3186. }
  3187. out += ' if (!' + ($nextValid) + ') { errors = ' + ($errs) + '; if (validate.errors !== null) { if (errors) validate.errors.length = errors; else validate.errors = null; } delete ' + ($data) + '[' + ($key) + ']; } ';
  3188. it.compositeRule = $it.compositeRule = $wasComposite;
  3189. } else {
  3190. $it.schema = $aProperties;
  3191. $it.schemaPath = it.schemaPath + '.additionalProperties';
  3192. $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
  3193. $it.errorPath = it.opts._errorDataPathProperty ? it.errorPath : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3194. var $passData = $data + '[' + $key + ']';
  3195. $it.dataPathArr[$dataNxt] = $key;
  3196. var $code = it.validate($it);
  3197. $it.baseId = $currentBaseId;
  3198. if (it.util.varOccurences($code, $nextData) < 2) {
  3199. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3200. } else {
  3201. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3202. }
  3203. if ($breakOnError) {
  3204. out += ' if (!' + ($nextValid) + ') break; ';
  3205. }
  3206. }
  3207. }
  3208. it.errorPath = $currentErrorPath;
  3209. }
  3210. if ($someProperties) {
  3211. out += ' } ';
  3212. }
  3213. out += ' } ';
  3214. if ($breakOnError) {
  3215. out += ' if (' + ($nextValid) + ') { ';
  3216. $closingBraces += '}';
  3217. }
  3218. }
  3219. var $useDefaults = it.opts.useDefaults && !it.compositeRule;
  3220. if ($schemaKeys.length) {
  3221. var arr4 = $schemaKeys;
  3222. if (arr4) {
  3223. var $propertyKey, i4 = -1,
  3224. l4 = arr4.length - 1;
  3225. while (i4 < l4) {
  3226. $propertyKey = arr4[i4 += 1];
  3227. var $sch = $schema[$propertyKey];
  3228. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3229. var $prop = it.util.getProperty($propertyKey),
  3230. $passData = $data + $prop,
  3231. $hasDefault = $useDefaults && $sch.default !== undefined;
  3232. $it.schema = $sch;
  3233. $it.schemaPath = $schemaPath + $prop;
  3234. $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
  3235. $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
  3236. $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
  3237. var $code = it.validate($it);
  3238. $it.baseId = $currentBaseId;
  3239. if (it.util.varOccurences($code, $nextData) < 2) {
  3240. $code = it.util.varReplace($code, $nextData, $passData);
  3241. var $useData = $passData;
  3242. } else {
  3243. var $useData = $nextData;
  3244. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ';
  3245. }
  3246. if ($hasDefault) {
  3247. out += ' ' + ($code) + ' ';
  3248. } else {
  3249. if ($requiredHash && $requiredHash[$propertyKey]) {
  3250. out += ' if (' + ($useData) + ' === undefined) { ' + ($nextValid) + ' = false; ';
  3251. var $currentErrorPath = it.errorPath,
  3252. $currErrSchemaPath = $errSchemaPath,
  3253. $missingProperty = it.util.escapeQuotes($propertyKey);
  3254. if (it.opts._errorDataPathProperty) {
  3255. it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
  3256. }
  3257. $errSchemaPath = it.errSchemaPath + '/required';
  3258. var $$outStack = $$outStack || [];
  3259. $$outStack.push(out);
  3260. out = ''; /* istanbul ignore else */
  3261. if (it.createErrors !== false) {
  3262. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3263. if (it.opts.messages !== false) {
  3264. out += ' , message: \'';
  3265. if (it.opts._errorDataPathProperty) {
  3266. out += 'is a required property';
  3267. } else {
  3268. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3269. }
  3270. out += '\' ';
  3271. }
  3272. if (it.opts.verbose) {
  3273. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3274. }
  3275. out += ' } ';
  3276. } else {
  3277. out += ' {} ';
  3278. }
  3279. var __err = out;
  3280. out = $$outStack.pop();
  3281. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3282. if (it.async) {
  3283. out += ' throw new ValidationError([' + (__err) + ']); ';
  3284. } else {
  3285. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3286. }
  3287. } else {
  3288. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3289. }
  3290. $errSchemaPath = $currErrSchemaPath;
  3291. it.errorPath = $currentErrorPath;
  3292. out += ' } else { ';
  3293. } else {
  3294. if ($breakOnError) {
  3295. out += ' if (' + ($useData) + ' === undefined) { ' + ($nextValid) + ' = true; } else { ';
  3296. } else {
  3297. out += ' if (' + ($useData) + ' !== undefined) { ';
  3298. }
  3299. }
  3300. out += ' ' + ($code) + ' } ';
  3301. }
  3302. }
  3303. if ($breakOnError) {
  3304. out += ' if (' + ($nextValid) + ') { ';
  3305. $closingBraces += '}';
  3306. }
  3307. }
  3308. }
  3309. }
  3310. var arr5 = $pPropertyKeys;
  3311. if (arr5) {
  3312. var $pProperty, i5 = -1,
  3313. l5 = arr5.length - 1;
  3314. while (i5 < l5) {
  3315. $pProperty = arr5[i5 += 1];
  3316. var $sch = $pProperties[$pProperty];
  3317. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3318. $it.schema = $sch;
  3319. $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
  3320. $it.errSchemaPath = it.errSchemaPath + '/patternProperties/' + it.util.escapeFragment($pProperty);
  3321. out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3322. if ($ownProperties) {
  3323. out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
  3324. }
  3325. out += ' if (' + (it.usePattern($pProperty)) + '.test(' + ($key) + ')) { ';
  3326. $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3327. var $passData = $data + '[' + $key + ']';
  3328. $it.dataPathArr[$dataNxt] = $key;
  3329. var $code = it.validate($it);
  3330. $it.baseId = $currentBaseId;
  3331. if (it.util.varOccurences($code, $nextData) < 2) {
  3332. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3333. } else {
  3334. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3335. }
  3336. if ($breakOnError) {
  3337. out += ' if (!' + ($nextValid) + ') break; ';
  3338. }
  3339. out += ' } ';
  3340. if ($breakOnError) {
  3341. out += ' else ' + ($nextValid) + ' = true; ';
  3342. }
  3343. out += ' } ';
  3344. if ($breakOnError) {
  3345. out += ' if (' + ($nextValid) + ') { ';
  3346. $closingBraces += '}';
  3347. }
  3348. }
  3349. }
  3350. }
  3351. if (it.opts.v5) {
  3352. var arr6 = $pgPropertyKeys;
  3353. if (arr6) {
  3354. var $pgProperty, i6 = -1,
  3355. l6 = arr6.length - 1;
  3356. while (i6 < l6) {
  3357. $pgProperty = arr6[i6 += 1];
  3358. var $pgSchema = $pgProperties[$pgProperty],
  3359. $sch = $pgSchema.schema;
  3360. if (it.util.schemaHasRules($sch, it.RULES.all)) {
  3361. $it.schema = $sch;
  3362. $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
  3363. $it.errSchemaPath = it.errSchemaPath + '/patternGroups/' + it.util.escapeFragment($pgProperty) + '/schema';
  3364. out += ' var pgPropCount' + ($lvl) + ' = 0; for (var ' + ($key) + ' in ' + ($data) + ') { ';
  3365. if ($ownProperties) {
  3366. out += ' if (!Object.prototype.hasOwnProperty.call(' + ($data) + ', ' + ($key) + ')) continue; ';
  3367. }
  3368. out += ' if (' + (it.usePattern($pgProperty)) + '.test(' + ($key) + ')) { pgPropCount' + ($lvl) + '++; ';
  3369. $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
  3370. var $passData = $data + '[' + $key + ']';
  3371. $it.dataPathArr[$dataNxt] = $key;
  3372. var $code = it.validate($it);
  3373. $it.baseId = $currentBaseId;
  3374. if (it.util.varOccurences($code, $nextData) < 2) {
  3375. out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
  3376. } else {
  3377. out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
  3378. }
  3379. if ($breakOnError) {
  3380. out += ' if (!' + ($nextValid) + ') break; ';
  3381. }
  3382. out += ' } ';
  3383. if ($breakOnError) {
  3384. out += ' else ' + ($nextValid) + ' = true; ';
  3385. }
  3386. out += ' } ';
  3387. if ($breakOnError) {
  3388. out += ' if (' + ($nextValid) + ') { ';
  3389. $closingBraces += '}';
  3390. }
  3391. var $pgMin = $pgSchema.minimum,
  3392. $pgMax = $pgSchema.maximum;
  3393. if ($pgMin !== undefined || $pgMax !== undefined) {
  3394. out += ' var ' + ($valid) + ' = true; ';
  3395. var $currErrSchemaPath = $errSchemaPath;
  3396. if ($pgMin !== undefined) {
  3397. var $limit = $pgMin,
  3398. $reason = 'minimum',
  3399. $moreOrLess = 'less';
  3400. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' >= ' + ($pgMin) + '; ';
  3401. $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum';
  3402. out += ' if (!' + ($valid) + ') { ';
  3403. var $$outStack = $$outStack || [];
  3404. $$outStack.push(out);
  3405. out = ''; /* istanbul ignore else */
  3406. if (it.createErrors !== false) {
  3407. out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  3408. if (it.opts.messages !== false) {
  3409. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  3410. }
  3411. if (it.opts.verbose) {
  3412. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3413. }
  3414. out += ' } ';
  3415. } else {
  3416. out += ' {} ';
  3417. }
  3418. var __err = out;
  3419. out = $$outStack.pop();
  3420. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3421. if (it.async) {
  3422. out += ' throw new ValidationError([' + (__err) + ']); ';
  3423. } else {
  3424. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3425. }
  3426. } else {
  3427. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3428. }
  3429. out += ' } ';
  3430. if ($pgMax !== undefined) {
  3431. out += ' else ';
  3432. }
  3433. }
  3434. if ($pgMax !== undefined) {
  3435. var $limit = $pgMax,
  3436. $reason = 'maximum',
  3437. $moreOrLess = 'more';
  3438. out += ' ' + ($valid) + ' = pgPropCount' + ($lvl) + ' <= ' + ($pgMax) + '; ';
  3439. $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum';
  3440. out += ' if (!' + ($valid) + ') { ';
  3441. var $$outStack = $$outStack || [];
  3442. $$outStack.push(out);
  3443. out = ''; /* istanbul ignore else */
  3444. if (it.createErrors !== false) {
  3445. out += ' { keyword: \'' + ('patternGroups') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { reason: \'' + ($reason) + '\', limit: ' + ($limit) + ', pattern: \'' + (it.util.escapeQuotes($pgProperty)) + '\' } ';
  3446. if (it.opts.messages !== false) {
  3447. out += ' , message: \'should NOT have ' + ($moreOrLess) + ' than ' + ($limit) + ' properties matching pattern "' + (it.util.escapeQuotes($pgProperty)) + '"\' ';
  3448. }
  3449. if (it.opts.verbose) {
  3450. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3451. }
  3452. out += ' } ';
  3453. } else {
  3454. out += ' {} ';
  3455. }
  3456. var __err = out;
  3457. out = $$outStack.pop();
  3458. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3459. if (it.async) {
  3460. out += ' throw new ValidationError([' + (__err) + ']); ';
  3461. } else {
  3462. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3463. }
  3464. } else {
  3465. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3466. }
  3467. out += ' } ';
  3468. }
  3469. $errSchemaPath = $currErrSchemaPath;
  3470. if ($breakOnError) {
  3471. out += ' if (' + ($valid) + ') { ';
  3472. $closingBraces += '}';
  3473. }
  3474. }
  3475. }
  3476. }
  3477. }
  3478. }
  3479. if ($breakOnError) {
  3480. out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';
  3481. }
  3482. out = it.util.cleanUpCode(out);
  3483. return out;
  3484. }
  3485. },{}],32:[function(require,module,exports){
  3486. 'use strict';
  3487. module.exports = function generate_ref(it, $keyword) {
  3488. var out = ' ';
  3489. var $lvl = it.level;
  3490. var $dataLvl = it.dataLevel;
  3491. var $schema = it.schema[$keyword];
  3492. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3493. var $breakOnError = !it.opts.allErrors;
  3494. var $data = 'data' + ($dataLvl || '');
  3495. var $valid = 'valid' + $lvl;
  3496. var $async, $refCode;
  3497. if ($schema == '#' || $schema == '#/') {
  3498. if (it.isRoot) {
  3499. $async = it.async;
  3500. $refCode = 'validate';
  3501. } else {
  3502. $async = it.root.schema.$async === true;
  3503. $refCode = 'root.refVal[0]';
  3504. }
  3505. } else {
  3506. var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot);
  3507. if ($refVal === undefined) {
  3508. var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId;
  3509. if (it.opts.missingRefs == 'fail') {
  3510. console.log($message);
  3511. var $$outStack = $$outStack || [];
  3512. $$outStack.push(out);
  3513. out = ''; /* istanbul ignore else */
  3514. if (it.createErrors !== false) {
  3515. out += ' { keyword: \'' + ('$ref') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { ref: \'' + (it.util.escapeQuotes($schema)) + '\' } ';
  3516. if (it.opts.messages !== false) {
  3517. out += ' , message: \'can\\\'t resolve reference ' + (it.util.escapeQuotes($schema)) + '\' ';
  3518. }
  3519. if (it.opts.verbose) {
  3520. out += ' , schema: ' + (it.util.toQuotedString($schema)) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3521. }
  3522. out += ' } ';
  3523. } else {
  3524. out += ' {} ';
  3525. }
  3526. var __err = out;
  3527. out = $$outStack.pop();
  3528. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3529. if (it.async) {
  3530. out += ' throw new ValidationError([' + (__err) + ']); ';
  3531. } else {
  3532. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3533. }
  3534. } else {
  3535. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3536. }
  3537. if ($breakOnError) {
  3538. out += ' if (false) { ';
  3539. }
  3540. } else if (it.opts.missingRefs == 'ignore') {
  3541. console.log($message);
  3542. if ($breakOnError) {
  3543. out += ' if (true) { ';
  3544. }
  3545. } else {
  3546. var $error = new Error($message);
  3547. $error.missingRef = it.resolve.url(it.baseId, $schema);
  3548. $error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef));
  3549. throw $error;
  3550. }
  3551. } else if ($refVal.inline) {
  3552. var $it = it.util.copy(it);
  3553. $it.level++;
  3554. var $nextValid = 'valid' + $it.level;
  3555. $it.schema = $refVal.schema;
  3556. $it.schemaPath = '';
  3557. $it.errSchemaPath = $schema;
  3558. var $code = it.validate($it).replace(/validate\.schema/g, $refVal.code);
  3559. out += ' ' + ($code) + ' ';
  3560. if ($breakOnError) {
  3561. out += ' if (' + ($nextValid) + ') { ';
  3562. }
  3563. } else {
  3564. $async = $refVal.$async === true;
  3565. $refCode = $refVal.code;
  3566. }
  3567. }
  3568. if ($refCode) {
  3569. var $$outStack = $$outStack || [];
  3570. $$outStack.push(out);
  3571. out = '';
  3572. if (it.opts.passContext) {
  3573. out += ' ' + ($refCode) + '.call(this, ';
  3574. } else {
  3575. out += ' ' + ($refCode) + '( ';
  3576. }
  3577. out += ' ' + ($data) + ', (dataPath || \'\')';
  3578. if (it.errorPath != '""') {
  3579. out += ' + ' + (it.errorPath);
  3580. }
  3581. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  3582. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  3583. out += ' , ' + ($parentData) + ' , ' + ($parentDataProperty) + ', rootData) ';
  3584. var __callValidate = out;
  3585. out = $$outStack.pop();
  3586. if ($async) {
  3587. if (!it.async) throw new Error('async schema referenced by sync schema');
  3588. out += ' try { ';
  3589. if ($breakOnError) {
  3590. out += 'var ' + ($valid) + ' =';
  3591. }
  3592. out += ' ' + (it.yieldAwait) + ' ' + (__callValidate) + '; } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; } ';
  3593. if ($breakOnError) {
  3594. out += ' if (' + ($valid) + ') { ';
  3595. }
  3596. } else {
  3597. out += ' if (!' + (__callValidate) + ') { if (vErrors === null) vErrors = ' + ($refCode) + '.errors; else vErrors = vErrors.concat(' + ($refCode) + '.errors); errors = vErrors.length; } ';
  3598. if ($breakOnError) {
  3599. out += ' else { ';
  3600. }
  3601. }
  3602. }
  3603. return out;
  3604. }
  3605. },{}],33:[function(require,module,exports){
  3606. 'use strict';
  3607. module.exports = function generate_required(it, $keyword) {
  3608. var out = ' ';
  3609. var $lvl = it.level;
  3610. var $dataLvl = it.dataLevel;
  3611. var $schema = it.schema[$keyword];
  3612. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3613. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3614. var $breakOnError = !it.opts.allErrors;
  3615. var $data = 'data' + ($dataLvl || '');
  3616. var $valid = 'valid' + $lvl;
  3617. var $isData = it.opts.v5 && $schema && $schema.$data,
  3618. $schemaValue;
  3619. if ($isData) {
  3620. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  3621. $schemaValue = 'schema' + $lvl;
  3622. } else {
  3623. $schemaValue = $schema;
  3624. }
  3625. var $vSchema = 'schema' + $lvl;
  3626. if (!$isData) {
  3627. if ($schema.length < it.opts.loopRequired && it.schema.properties && Object.keys(it.schema.properties).length) {
  3628. var $required = [];
  3629. var arr1 = $schema;
  3630. if (arr1) {
  3631. var $property, i1 = -1,
  3632. l1 = arr1.length - 1;
  3633. while (i1 < l1) {
  3634. $property = arr1[i1 += 1];
  3635. var $propertySch = it.schema.properties[$property];
  3636. if (!($propertySch && it.util.schemaHasRules($propertySch, it.RULES.all))) {
  3637. $required[$required.length] = $property;
  3638. }
  3639. }
  3640. }
  3641. } else {
  3642. var $required = $schema;
  3643. }
  3644. }
  3645. if ($isData || $required.length) {
  3646. var $currentErrorPath = it.errorPath,
  3647. $loopRequired = $isData || $required.length >= it.opts.loopRequired;
  3648. if ($breakOnError) {
  3649. out += ' var missing' + ($lvl) + '; ';
  3650. if ($loopRequired) {
  3651. if (!$isData) {
  3652. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
  3653. }
  3654. var $i = 'i' + $lvl,
  3655. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  3656. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3657. if (it.opts._errorDataPathProperty) {
  3658. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  3659. }
  3660. out += ' var ' + ($valid) + ' = true; ';
  3661. if ($isData) {
  3662. out += ' if (schema' + ($lvl) + ' === undefined) ' + ($valid) + ' = true; else if (!Array.isArray(schema' + ($lvl) + ')) ' + ($valid) + ' = false; else {';
  3663. }
  3664. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { ' + ($valid) + ' = ' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] !== undefined; if (!' + ($valid) + ') break; } ';
  3665. if ($isData) {
  3666. out += ' } ';
  3667. }
  3668. out += ' if (!' + ($valid) + ') { ';
  3669. var $$outStack = $$outStack || [];
  3670. $$outStack.push(out);
  3671. out = ''; /* istanbul ignore else */
  3672. if (it.createErrors !== false) {
  3673. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3674. if (it.opts.messages !== false) {
  3675. out += ' , message: \'';
  3676. if (it.opts._errorDataPathProperty) {
  3677. out += 'is a required property';
  3678. } else {
  3679. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3680. }
  3681. out += '\' ';
  3682. }
  3683. if (it.opts.verbose) {
  3684. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3685. }
  3686. out += ' } ';
  3687. } else {
  3688. out += ' {} ';
  3689. }
  3690. var __err = out;
  3691. out = $$outStack.pop();
  3692. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3693. if (it.async) {
  3694. out += ' throw new ValidationError([' + (__err) + ']); ';
  3695. } else {
  3696. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3697. }
  3698. } else {
  3699. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3700. }
  3701. out += ' } else { ';
  3702. } else {
  3703. out += ' if ( ';
  3704. var arr2 = $required;
  3705. if (arr2) {
  3706. var _$property, $i = -1,
  3707. l2 = arr2.length - 1;
  3708. while ($i < l2) {
  3709. _$property = arr2[$i += 1];
  3710. if ($i) {
  3711. out += ' || ';
  3712. }
  3713. var $prop = it.util.getProperty(_$property);
  3714. out += ' ( ' + ($data) + ($prop) + ' === undefined && (missing' + ($lvl) + ' = ' + (it.util.toQuotedString(it.opts.jsonPointers ? _$property : $prop)) + ') ) ';
  3715. }
  3716. }
  3717. out += ') { ';
  3718. var $propertyPath = 'missing' + $lvl,
  3719. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3720. if (it.opts._errorDataPathProperty) {
  3721. it.errorPath = it.opts.jsonPointers ? it.util.getPathExpr($currentErrorPath, $propertyPath, true) : $currentErrorPath + ' + ' + $propertyPath;
  3722. }
  3723. var $$outStack = $$outStack || [];
  3724. $$outStack.push(out);
  3725. out = ''; /* istanbul ignore else */
  3726. if (it.createErrors !== false) {
  3727. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3728. if (it.opts.messages !== false) {
  3729. out += ' , message: \'';
  3730. if (it.opts._errorDataPathProperty) {
  3731. out += 'is a required property';
  3732. } else {
  3733. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3734. }
  3735. out += '\' ';
  3736. }
  3737. if (it.opts.verbose) {
  3738. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3739. }
  3740. out += ' } ';
  3741. } else {
  3742. out += ' {} ';
  3743. }
  3744. var __err = out;
  3745. out = $$outStack.pop();
  3746. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3747. if (it.async) {
  3748. out += ' throw new ValidationError([' + (__err) + ']); ';
  3749. } else {
  3750. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3751. }
  3752. } else {
  3753. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3754. }
  3755. out += ' } else { ';
  3756. }
  3757. } else {
  3758. if ($loopRequired) {
  3759. if (!$isData) {
  3760. out += ' var ' + ($vSchema) + ' = validate.schema' + ($schemaPath) + '; ';
  3761. }
  3762. var $i = 'i' + $lvl,
  3763. $propertyPath = 'schema' + $lvl + '[' + $i + ']',
  3764. $missingProperty = '\' + ' + $propertyPath + ' + \'';
  3765. if (it.opts._errorDataPathProperty) {
  3766. it.errorPath = it.util.getPathExpr($currentErrorPath, $propertyPath, it.opts.jsonPointers);
  3767. }
  3768. if ($isData) {
  3769. out += ' if (' + ($vSchema) + ' && !Array.isArray(' + ($vSchema) + ')) { var err = '; /* istanbul ignore else */
  3770. if (it.createErrors !== false) {
  3771. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3772. if (it.opts.messages !== false) {
  3773. out += ' , message: \'';
  3774. if (it.opts._errorDataPathProperty) {
  3775. out += 'is a required property';
  3776. } else {
  3777. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3778. }
  3779. out += '\' ';
  3780. }
  3781. if (it.opts.verbose) {
  3782. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3783. }
  3784. out += ' } ';
  3785. } else {
  3786. out += ' {} ';
  3787. }
  3788. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else if (' + ($vSchema) + ' !== undefined) { ';
  3789. }
  3790. out += ' for (var ' + ($i) + ' = 0; ' + ($i) + ' < ' + ($vSchema) + '.length; ' + ($i) + '++) { if (' + ($data) + '[' + ($vSchema) + '[' + ($i) + ']] === undefined) { var err = '; /* istanbul ignore else */
  3791. if (it.createErrors !== false) {
  3792. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3793. if (it.opts.messages !== false) {
  3794. out += ' , message: \'';
  3795. if (it.opts._errorDataPathProperty) {
  3796. out += 'is a required property';
  3797. } else {
  3798. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3799. }
  3800. out += '\' ';
  3801. }
  3802. if (it.opts.verbose) {
  3803. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3804. }
  3805. out += ' } ';
  3806. } else {
  3807. out += ' {} ';
  3808. }
  3809. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } ';
  3810. if ($isData) {
  3811. out += ' } ';
  3812. }
  3813. } else {
  3814. var arr3 = $required;
  3815. if (arr3) {
  3816. var $reqProperty, i3 = -1,
  3817. l3 = arr3.length - 1;
  3818. while (i3 < l3) {
  3819. $reqProperty = arr3[i3 += 1];
  3820. var $prop = it.util.getProperty($reqProperty),
  3821. $missingProperty = it.util.escapeQuotes($reqProperty);
  3822. if (it.opts._errorDataPathProperty) {
  3823. it.errorPath = it.util.getPath($currentErrorPath, $reqProperty, it.opts.jsonPointers);
  3824. }
  3825. out += ' if (' + ($data) + ($prop) + ' === undefined) { var err = '; /* istanbul ignore else */
  3826. if (it.createErrors !== false) {
  3827. out += ' { keyword: \'' + ('required') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingProperty: \'' + ($missingProperty) + '\' } ';
  3828. if (it.opts.messages !== false) {
  3829. out += ' , message: \'';
  3830. if (it.opts._errorDataPathProperty) {
  3831. out += 'is a required property';
  3832. } else {
  3833. out += 'should have required property \\\'' + ($missingProperty) + '\\\'';
  3834. }
  3835. out += '\' ';
  3836. }
  3837. if (it.opts.verbose) {
  3838. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3839. }
  3840. out += ' } ';
  3841. } else {
  3842. out += ' {} ';
  3843. }
  3844. out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
  3845. }
  3846. }
  3847. }
  3848. }
  3849. it.errorPath = $currentErrorPath;
  3850. } else if ($breakOnError) {
  3851. out += ' if (true) {';
  3852. }
  3853. return out;
  3854. }
  3855. },{}],34:[function(require,module,exports){
  3856. 'use strict';
  3857. module.exports = function generate_switch(it, $keyword) {
  3858. var out = ' ';
  3859. var $lvl = it.level;
  3860. var $dataLvl = it.dataLevel;
  3861. var $schema = it.schema[$keyword];
  3862. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3863. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3864. var $breakOnError = !it.opts.allErrors;
  3865. var $data = 'data' + ($dataLvl || '');
  3866. var $valid = 'valid' + $lvl;
  3867. var $errs = 'errs__' + $lvl;
  3868. var $it = it.util.copy(it);
  3869. var $closingBraces = '';
  3870. $it.level++;
  3871. var $nextValid = 'valid' + $it.level;
  3872. var $ifPassed = 'ifPassed' + it.level,
  3873. $currentBaseId = $it.baseId,
  3874. $shouldContinue;
  3875. out += 'var ' + ($ifPassed) + ';';
  3876. var arr1 = $schema;
  3877. if (arr1) {
  3878. var $sch, $caseIndex = -1,
  3879. l1 = arr1.length - 1;
  3880. while ($caseIndex < l1) {
  3881. $sch = arr1[$caseIndex += 1];
  3882. if ($caseIndex && !$shouldContinue) {
  3883. out += ' if (!' + ($ifPassed) + ') { ';
  3884. $closingBraces += '}';
  3885. }
  3886. if ($sch.if && it.util.schemaHasRules($sch.if, it.RULES.all)) {
  3887. out += ' var ' + ($errs) + ' = errors; ';
  3888. var $wasComposite = it.compositeRule;
  3889. it.compositeRule = $it.compositeRule = true;
  3890. $it.createErrors = false;
  3891. $it.schema = $sch.if;
  3892. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].if';
  3893. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/if';
  3894. out += ' ' + (it.validate($it)) + ' ';
  3895. $it.baseId = $currentBaseId;
  3896. $it.createErrors = true;
  3897. it.compositeRule = $it.compositeRule = $wasComposite;
  3898. out += ' ' + ($ifPassed) + ' = ' + ($nextValid) + '; if (' + ($ifPassed) + ') { ';
  3899. if (typeof $sch.then == 'boolean') {
  3900. if ($sch.then === false) {
  3901. var $$outStack = $$outStack || [];
  3902. $$outStack.push(out);
  3903. out = ''; /* istanbul ignore else */
  3904. if (it.createErrors !== false) {
  3905. out += ' { keyword: \'' + ('switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { caseIndex: ' + ($caseIndex) + ' } ';
  3906. if (it.opts.messages !== false) {
  3907. out += ' , message: \'should pass "switch" keyword validation\' ';
  3908. }
  3909. if (it.opts.verbose) {
  3910. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3911. }
  3912. out += ' } ';
  3913. } else {
  3914. out += ' {} ';
  3915. }
  3916. var __err = out;
  3917. out = $$outStack.pop();
  3918. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3919. if (it.async) {
  3920. out += ' throw new ValidationError([' + (__err) + ']); ';
  3921. } else {
  3922. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3923. }
  3924. } else {
  3925. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3926. }
  3927. }
  3928. out += ' var ' + ($nextValid) + ' = ' + ($sch.then) + '; ';
  3929. } else {
  3930. $it.schema = $sch.then;
  3931. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
  3932. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
  3933. out += ' ' + (it.validate($it)) + ' ';
  3934. $it.baseId = $currentBaseId;
  3935. }
  3936. out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } } ';
  3937. } else {
  3938. out += ' ' + ($ifPassed) + ' = true; ';
  3939. if (typeof $sch.then == 'boolean') {
  3940. if ($sch.then === false) {
  3941. var $$outStack = $$outStack || [];
  3942. $$outStack.push(out);
  3943. out = ''; /* istanbul ignore else */
  3944. if (it.createErrors !== false) {
  3945. out += ' { keyword: \'' + ('switch') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { caseIndex: ' + ($caseIndex) + ' } ';
  3946. if (it.opts.messages !== false) {
  3947. out += ' , message: \'should pass "switch" keyword validation\' ';
  3948. }
  3949. if (it.opts.verbose) {
  3950. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  3951. }
  3952. out += ' } ';
  3953. } else {
  3954. out += ' {} ';
  3955. }
  3956. var __err = out;
  3957. out = $$outStack.pop();
  3958. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  3959. if (it.async) {
  3960. out += ' throw new ValidationError([' + (__err) + ']); ';
  3961. } else {
  3962. out += ' validate.errors = [' + (__err) + ']; return false; ';
  3963. }
  3964. } else {
  3965. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  3966. }
  3967. }
  3968. out += ' var ' + ($nextValid) + ' = ' + ($sch.then) + '; ';
  3969. } else {
  3970. $it.schema = $sch.then;
  3971. $it.schemaPath = $schemaPath + '[' + $caseIndex + '].then';
  3972. $it.errSchemaPath = $errSchemaPath + '/' + $caseIndex + '/then';
  3973. out += ' ' + (it.validate($it)) + ' ';
  3974. $it.baseId = $currentBaseId;
  3975. }
  3976. }
  3977. $shouldContinue = $sch.continue
  3978. }
  3979. }
  3980. out += '' + ($closingBraces) + 'var ' + ($valid) + ' = ' + ($nextValid) + '; ';
  3981. out = it.util.cleanUpCode(out);
  3982. return out;
  3983. }
  3984. },{}],35:[function(require,module,exports){
  3985. 'use strict';
  3986. module.exports = function generate_uniqueItems(it, $keyword) {
  3987. var out = ' ';
  3988. var $lvl = it.level;
  3989. var $dataLvl = it.dataLevel;
  3990. var $schema = it.schema[$keyword];
  3991. var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
  3992. var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
  3993. var $breakOnError = !it.opts.allErrors;
  3994. var $data = 'data' + ($dataLvl || '');
  3995. var $valid = 'valid' + $lvl;
  3996. var $isData = it.opts.v5 && $schema && $schema.$data,
  3997. $schemaValue;
  3998. if ($isData) {
  3999. out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
  4000. $schemaValue = 'schema' + $lvl;
  4001. } else {
  4002. $schemaValue = $schema;
  4003. }
  4004. if (($schema || $isData) && it.opts.uniqueItems !== false) {
  4005. if ($isData) {
  4006. out += ' var ' + ($valid) + '; if (' + ($schemaValue) + ' === false || ' + ($schemaValue) + ' === undefined) ' + ($valid) + ' = true; else if (typeof ' + ($schemaValue) + ' != \'boolean\') ' + ($valid) + ' = false; else { ';
  4007. }
  4008. out += ' var ' + ($valid) + ' = true; if (' + ($data) + '.length > 1) { var i = ' + ($data) + '.length, j; outer: for (;i--;) { for (j = i; j--;) { if (equal(' + ($data) + '[i], ' + ($data) + '[j])) { ' + ($valid) + ' = false; break outer; } } } } ';
  4009. if ($isData) {
  4010. out += ' } ';
  4011. }
  4012. out += ' if (!' + ($valid) + ') { ';
  4013. var $$outStack = $$outStack || [];
  4014. $$outStack.push(out);
  4015. out = ''; /* istanbul ignore else */
  4016. if (it.createErrors !== false) {
  4017. out += ' { keyword: \'' + ('uniqueItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { i: i, j: j } ';
  4018. if (it.opts.messages !== false) {
  4019. out += ' , message: \'should NOT have duplicate items (items ## \' + j + \' and \' + i + \' are identical)\' ';
  4020. }
  4021. if (it.opts.verbose) {
  4022. out += ' , schema: ';
  4023. if ($isData) {
  4024. out += 'validate.schema' + ($schemaPath);
  4025. } else {
  4026. out += '' + ($schema);
  4027. }
  4028. out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4029. }
  4030. out += ' } ';
  4031. } else {
  4032. out += ' {} ';
  4033. }
  4034. var __err = out;
  4035. out = $$outStack.pop();
  4036. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4037. if (it.async) {
  4038. out += ' throw new ValidationError([' + (__err) + ']); ';
  4039. } else {
  4040. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4041. }
  4042. } else {
  4043. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4044. }
  4045. out += ' } ';
  4046. if ($breakOnError) {
  4047. out += ' else { ';
  4048. }
  4049. } else {
  4050. if ($breakOnError) {
  4051. out += ' if (true) { ';
  4052. }
  4053. }
  4054. return out;
  4055. }
  4056. },{}],36:[function(require,module,exports){
  4057. 'use strict';
  4058. module.exports = function generate_validate(it, $keyword) {
  4059. var out = '';
  4060. var $async = it.schema.$async === true;
  4061. if (it.isTop) {
  4062. var $top = it.isTop,
  4063. $lvl = it.level = 0,
  4064. $dataLvl = it.dataLevel = 0,
  4065. $data = 'data';
  4066. it.rootId = it.resolve.fullPath(it.root.schema.id);
  4067. it.baseId = it.baseId || it.rootId;
  4068. if ($async) {
  4069. it.async = true;
  4070. var $es7 = it.opts.async == 'es7';
  4071. it.yieldAwait = $es7 ? 'await' : 'yield';
  4072. }
  4073. delete it.isTop;
  4074. it.dataPathArr = [undefined];
  4075. out += ' var validate = ';
  4076. if ($async) {
  4077. if ($es7) {
  4078. out += ' (async function ';
  4079. } else {
  4080. if (it.opts.async == 'co*') {
  4081. out += 'co.wrap';
  4082. }
  4083. out += '(function* ';
  4084. }
  4085. } else {
  4086. out += ' (function ';
  4087. }
  4088. out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; var vErrors = null; ';
  4089. out += ' var errors = 0; ';
  4090. out += ' if (rootData === undefined) rootData = data;';
  4091. } else {
  4092. var $lvl = it.level,
  4093. $dataLvl = it.dataLevel,
  4094. $data = 'data' + ($dataLvl || '');
  4095. if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
  4096. if ($async && !it.async) throw new Error('async schema in sync schema');
  4097. out += ' var errs_' + ($lvl) + ' = errors;';
  4098. }
  4099. var $valid = 'valid' + $lvl,
  4100. $breakOnError = !it.opts.allErrors,
  4101. $closingBraces1 = '',
  4102. $closingBraces2 = '';
  4103. var $typeSchema = it.schema.type,
  4104. $typeIsArray = Array.isArray($typeSchema);
  4105. if ($typeSchema && it.opts.coerceTypes) {
  4106. var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
  4107. if ($coerceToTypes) {
  4108. var $schemaPath = it.schemaPath + '.type',
  4109. $errSchemaPath = it.errSchemaPath + '/type',
  4110. $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
  4111. out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
  4112. var $dataType = 'dataType' + $lvl,
  4113. $coerced = 'coerced' + $lvl;
  4114. out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; ';
  4115. if (it.opts.coerceTypes == 'array') {
  4116. out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; ';
  4117. }
  4118. out += ' var ' + ($coerced) + ' = undefined; ';
  4119. var $bracesCoercion = '';
  4120. var arr1 = $coerceToTypes;
  4121. if (arr1) {
  4122. var $type, $i = -1,
  4123. l1 = arr1.length - 1;
  4124. while ($i < l1) {
  4125. $type = arr1[$i += 1];
  4126. if ($i) {
  4127. out += ' if (' + ($coerced) + ' === undefined) { ';
  4128. $bracesCoercion += '}';
  4129. }
  4130. if (it.opts.coerceTypes == 'array' && $type != 'array') {
  4131. out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } ';
  4132. }
  4133. if ($type == 'string') {
  4134. out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
  4135. } else if ($type == 'number' || $type == 'integer') {
  4136. out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
  4137. if ($type == 'integer') {
  4138. out += ' && !(' + ($data) + ' % 1)';
  4139. }
  4140. out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
  4141. } else if ($type == 'boolean') {
  4142. out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
  4143. } else if ($type == 'null') {
  4144. out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
  4145. } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
  4146. out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
  4147. }
  4148. }
  4149. }
  4150. out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
  4151. var $$outStack = $$outStack || [];
  4152. $$outStack.push(out);
  4153. out = ''; /* istanbul ignore else */
  4154. if (it.createErrors !== false) {
  4155. out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4156. if ($typeIsArray) {
  4157. out += '' + ($typeSchema.join(","));
  4158. } else {
  4159. out += '' + ($typeSchema);
  4160. }
  4161. out += '\' } ';
  4162. if (it.opts.messages !== false) {
  4163. out += ' , message: \'should be ';
  4164. if ($typeIsArray) {
  4165. out += '' + ($typeSchema.join(","));
  4166. } else {
  4167. out += '' + ($typeSchema);
  4168. }
  4169. out += '\' ';
  4170. }
  4171. if (it.opts.verbose) {
  4172. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4173. }
  4174. out += ' } ';
  4175. } else {
  4176. out += ' {} ';
  4177. }
  4178. var __err = out;
  4179. out = $$outStack.pop();
  4180. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4181. if (it.async) {
  4182. out += ' throw new ValidationError([' + (__err) + ']); ';
  4183. } else {
  4184. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4185. }
  4186. } else {
  4187. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4188. }
  4189. out += ' } else { ';
  4190. var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
  4191. $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
  4192. out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
  4193. if (!$dataLvl) {
  4194. out += 'if (' + ($parentData) + ' !== undefined)';
  4195. }
  4196. out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } } ';
  4197. }
  4198. }
  4199. var $refKeywords;
  4200. if (it.schema.$ref && ($refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'))) {
  4201. if (it.opts.extendRefs == 'fail') {
  4202. throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '"');
  4203. } else if (it.opts.extendRefs == 'ignore') {
  4204. $refKeywords = false;
  4205. console.log('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
  4206. } else if (it.opts.extendRefs !== true) {
  4207. console.log('$ref: all keywords used in schema at path "' + it.errSchemaPath + '". It will change in the next major version, see issue #260. Use option { extendRefs: true } to keep current behaviour');
  4208. }
  4209. }
  4210. if (it.schema.$ref && !$refKeywords) {
  4211. out += ' ' + (it.RULES.all.$ref.code(it, '$ref')) + ' ';
  4212. if ($breakOnError) {
  4213. out += ' } if (errors === ';
  4214. if ($top) {
  4215. out += '0';
  4216. } else {
  4217. out += 'errs_' + ($lvl);
  4218. }
  4219. out += ') { ';
  4220. $closingBraces2 += '}';
  4221. }
  4222. } else {
  4223. var arr2 = it.RULES;
  4224. if (arr2) {
  4225. var $rulesGroup, i2 = -1,
  4226. l2 = arr2.length - 1;
  4227. while (i2 < l2) {
  4228. $rulesGroup = arr2[i2 += 1];
  4229. if ($shouldUseGroup($rulesGroup)) {
  4230. if ($rulesGroup.type) {
  4231. out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { ';
  4232. }
  4233. if (it.opts.useDefaults && !it.compositeRule) {
  4234. if ($rulesGroup.type == 'object' && it.schema.properties) {
  4235. var $schema = it.schema.properties,
  4236. $schemaKeys = Object.keys($schema);
  4237. var arr3 = $schemaKeys;
  4238. if (arr3) {
  4239. var $propertyKey, i3 = -1,
  4240. l3 = arr3.length - 1;
  4241. while (i3 < l3) {
  4242. $propertyKey = arr3[i3 += 1];
  4243. var $sch = $schema[$propertyKey];
  4244. if ($sch.default !== undefined) {
  4245. var $passData = $data + it.util.getProperty($propertyKey);
  4246. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  4247. if (it.opts.useDefaults == 'shared') {
  4248. out += ' ' + (it.useDefault($sch.default)) + ' ';
  4249. } else {
  4250. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  4251. }
  4252. out += '; ';
  4253. }
  4254. }
  4255. }
  4256. } else if ($rulesGroup.type == 'array' && Array.isArray(it.schema.items)) {
  4257. var arr4 = it.schema.items;
  4258. if (arr4) {
  4259. var $sch, $i = -1,
  4260. l4 = arr4.length - 1;
  4261. while ($i < l4) {
  4262. $sch = arr4[$i += 1];
  4263. if ($sch.default !== undefined) {
  4264. var $passData = $data + '[' + $i + ']';
  4265. out += ' if (' + ($passData) + ' === undefined) ' + ($passData) + ' = ';
  4266. if (it.opts.useDefaults == 'shared') {
  4267. out += ' ' + (it.useDefault($sch.default)) + ' ';
  4268. } else {
  4269. out += ' ' + (JSON.stringify($sch.default)) + ' ';
  4270. }
  4271. out += '; ';
  4272. }
  4273. }
  4274. }
  4275. }
  4276. }
  4277. var arr5 = $rulesGroup.rules;
  4278. if (arr5) {
  4279. var $rule, i5 = -1,
  4280. l5 = arr5.length - 1;
  4281. while (i5 < l5) {
  4282. $rule = arr5[i5 += 1];
  4283. if ($shouldUseRule($rule)) {
  4284. out += ' ' + ($rule.code(it, $rule.keyword)) + ' ';
  4285. if ($breakOnError) {
  4286. $closingBraces1 += '}';
  4287. }
  4288. }
  4289. }
  4290. }
  4291. if ($breakOnError) {
  4292. out += ' ' + ($closingBraces1) + ' ';
  4293. $closingBraces1 = '';
  4294. }
  4295. if ($rulesGroup.type) {
  4296. out += ' } ';
  4297. if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
  4298. var $typeChecked = true;
  4299. out += ' else { ';
  4300. var $schemaPath = it.schemaPath + '.type',
  4301. $errSchemaPath = it.errSchemaPath + '/type';
  4302. var $$outStack = $$outStack || [];
  4303. $$outStack.push(out);
  4304. out = ''; /* istanbul ignore else */
  4305. if (it.createErrors !== false) {
  4306. out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4307. if ($typeIsArray) {
  4308. out += '' + ($typeSchema.join(","));
  4309. } else {
  4310. out += '' + ($typeSchema);
  4311. }
  4312. out += '\' } ';
  4313. if (it.opts.messages !== false) {
  4314. out += ' , message: \'should be ';
  4315. if ($typeIsArray) {
  4316. out += '' + ($typeSchema.join(","));
  4317. } else {
  4318. out += '' + ($typeSchema);
  4319. }
  4320. out += '\' ';
  4321. }
  4322. if (it.opts.verbose) {
  4323. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4324. }
  4325. out += ' } ';
  4326. } else {
  4327. out += ' {} ';
  4328. }
  4329. var __err = out;
  4330. out = $$outStack.pop();
  4331. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4332. if (it.async) {
  4333. out += ' throw new ValidationError([' + (__err) + ']); ';
  4334. } else {
  4335. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4336. }
  4337. } else {
  4338. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4339. }
  4340. out += ' } ';
  4341. }
  4342. }
  4343. if ($breakOnError) {
  4344. out += ' if (errors === ';
  4345. if ($top) {
  4346. out += '0';
  4347. } else {
  4348. out += 'errs_' + ($lvl);
  4349. }
  4350. out += ') { ';
  4351. $closingBraces2 += '}';
  4352. }
  4353. }
  4354. }
  4355. }
  4356. }
  4357. if ($typeSchema && !$typeChecked && !$coerceToTypes) {
  4358. var $schemaPath = it.schemaPath + '.type',
  4359. $errSchemaPath = it.errSchemaPath + '/type',
  4360. $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
  4361. out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
  4362. var $$outStack = $$outStack || [];
  4363. $$outStack.push(out);
  4364. out = ''; /* istanbul ignore else */
  4365. if (it.createErrors !== false) {
  4366. out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
  4367. if ($typeIsArray) {
  4368. out += '' + ($typeSchema.join(","));
  4369. } else {
  4370. out += '' + ($typeSchema);
  4371. }
  4372. out += '\' } ';
  4373. if (it.opts.messages !== false) {
  4374. out += ' , message: \'should be ';
  4375. if ($typeIsArray) {
  4376. out += '' + ($typeSchema.join(","));
  4377. } else {
  4378. out += '' + ($typeSchema);
  4379. }
  4380. out += '\' ';
  4381. }
  4382. if (it.opts.verbose) {
  4383. out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
  4384. }
  4385. out += ' } ';
  4386. } else {
  4387. out += ' {} ';
  4388. }
  4389. var __err = out;
  4390. out = $$outStack.pop();
  4391. if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
  4392. if (it.async) {
  4393. out += ' throw new ValidationError([' + (__err) + ']); ';
  4394. } else {
  4395. out += ' validate.errors = [' + (__err) + ']; return false; ';
  4396. }
  4397. } else {
  4398. out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
  4399. }
  4400. out += ' }';
  4401. }
  4402. if ($breakOnError) {
  4403. out += ' ' + ($closingBraces2) + ' ';
  4404. }
  4405. if ($top) {
  4406. if ($async) {
  4407. out += ' if (errors === 0) return true; ';
  4408. out += ' else throw new ValidationError(vErrors); ';
  4409. } else {
  4410. out += ' validate.errors = vErrors; ';
  4411. out += ' return errors === 0; ';
  4412. }
  4413. out += ' }); return validate;';
  4414. } else {
  4415. out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
  4416. }
  4417. out = it.util.cleanUpCode(out);
  4418. if ($top && $breakOnError) {
  4419. out = it.util.cleanUpVarErrors(out, $async);
  4420. }
  4421. function $shouldUseGroup($rulesGroup) {
  4422. for (var i = 0; i < $rulesGroup.rules.length; i++)
  4423. if ($shouldUseRule($rulesGroup.rules[i])) return true;
  4424. }
  4425. function $shouldUseRule($rule) {
  4426. return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties === false || typeof it.schema.additionalProperties == 'object' || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length) || (it.opts.v5 && it.schema.patternGroups && Object.keys(it.schema.patternGroups).length)));
  4427. }
  4428. return out;
  4429. }
  4430. },{}],37:[function(require,module,exports){
  4431. 'use strict';
  4432. var IDENTIFIER = /^[a-z_$][a-z0-9_$\-]*$/i;
  4433. var customRuleCode = require('./dotjs/custom');
  4434. module.exports = {
  4435. add: addKeyword,
  4436. get: getKeyword,
  4437. remove: removeKeyword
  4438. };
  4439. /**
  4440. * Define custom keyword
  4441. * @this Ajv
  4442. * @param {String} keyword custom keyword, should be unique (including different from all standard, custom and macro keywords).
  4443. * @param {Object} definition keyword definition object with properties `type` (type(s) which the keyword applies to), `validate` or `compile`.
  4444. */
  4445. function addKeyword(keyword, definition) {
  4446. /* jshint validthis: true */
  4447. /* eslint no-shadow: 0 */
  4448. var RULES = this.RULES;
  4449. if (RULES.keywords[keyword])
  4450. throw new Error('Keyword ' + keyword + ' is already defined');
  4451. if (!IDENTIFIER.test(keyword))
  4452. throw new Error('Keyword ' + keyword + ' is not a valid identifier');
  4453. if (definition) {
  4454. if (definition.macro && definition.valid !== undefined)
  4455. throw new Error('"valid" option cannot be used with macro keywords');
  4456. var dataType = definition.type;
  4457. if (Array.isArray(dataType)) {
  4458. var i, len = dataType.length;
  4459. for (i=0; i<len; i++) checkDataType(dataType[i]);
  4460. for (i=0; i<len; i++) _addRule(keyword, dataType[i], definition);
  4461. } else {
  4462. if (dataType) checkDataType(dataType);
  4463. _addRule(keyword, dataType, definition);
  4464. }
  4465. var $data = definition.$data === true && this._opts.v5;
  4466. if ($data && !definition.validate)
  4467. throw new Error('$data support: "validate" function is not defined');
  4468. var metaSchema = definition.metaSchema;
  4469. if (metaSchema) {
  4470. if ($data) {
  4471. metaSchema = {
  4472. anyOf: [
  4473. metaSchema,
  4474. { '$ref': 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#/definitions/$data' }
  4475. ]
  4476. };
  4477. }
  4478. definition.validateSchema = this.compile(metaSchema, true);
  4479. }
  4480. }
  4481. RULES.keywords[keyword] = RULES.all[keyword] = true;
  4482. function _addRule(keyword, dataType, definition) {
  4483. var ruleGroup;
  4484. for (var i=0; i<RULES.length; i++) {
  4485. var rg = RULES[i];
  4486. if (rg.type == dataType) {
  4487. ruleGroup = rg;
  4488. break;
  4489. }
  4490. }
  4491. if (!ruleGroup) {
  4492. ruleGroup = { type: dataType, rules: [] };
  4493. RULES.push(ruleGroup);
  4494. }
  4495. var rule = {
  4496. keyword: keyword,
  4497. definition: definition,
  4498. custom: true,
  4499. code: customRuleCode
  4500. };
  4501. ruleGroup.rules.push(rule);
  4502. RULES.custom[keyword] = rule;
  4503. }
  4504. function checkDataType(dataType) {
  4505. if (!RULES.types[dataType]) throw new Error('Unknown type ' + dataType);
  4506. }
  4507. }
  4508. /**
  4509. * Get keyword
  4510. * @this Ajv
  4511. * @param {String} keyword pre-defined or custom keyword.
  4512. * @return {Object|Boolean} custom keyword definition, `true` if it is a predefined keyword, `false` otherwise.
  4513. */
  4514. function getKeyword(keyword) {
  4515. /* jshint validthis: true */
  4516. var rule = this.RULES.custom[keyword];
  4517. return rule ? rule.definition : this.RULES.keywords[keyword] || false;
  4518. }
  4519. /**
  4520. * Remove keyword
  4521. * @this Ajv
  4522. * @param {String} keyword pre-defined or custom keyword.
  4523. */
  4524. function removeKeyword(keyword) {
  4525. /* jshint validthis: true */
  4526. var RULES = this.RULES;
  4527. delete RULES.keywords[keyword];
  4528. delete RULES.all[keyword];
  4529. delete RULES.custom[keyword];
  4530. for (var i=0; i<RULES.length; i++) {
  4531. var rules = RULES[i].rules;
  4532. for (var j=0; j<rules.length; j++) {
  4533. if (rules[j].keyword == keyword) {
  4534. rules.splice(j, 1);
  4535. break;
  4536. }
  4537. }
  4538. }
  4539. }
  4540. },{"./dotjs/custom":21}],38:[function(require,module,exports){
  4541. module.exports={
  4542. "id": "http://json-schema.org/draft-04/schema#",
  4543. "$schema": "http://json-schema.org/draft-04/schema#",
  4544. "description": "Core schema meta-schema",
  4545. "definitions": {
  4546. "schemaArray": {
  4547. "type": "array",
  4548. "minItems": 1,
  4549. "items": { "$ref": "#" }
  4550. },
  4551. "positiveInteger": {
  4552. "type": "integer",
  4553. "minimum": 0
  4554. },
  4555. "positiveIntegerDefault0": {
  4556. "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
  4557. },
  4558. "simpleTypes": {
  4559. "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
  4560. },
  4561. "stringArray": {
  4562. "type": "array",
  4563. "items": { "type": "string" },
  4564. "minItems": 1,
  4565. "uniqueItems": true
  4566. }
  4567. },
  4568. "type": "object",
  4569. "properties": {
  4570. "id": {
  4571. "type": "string",
  4572. "format": "uri"
  4573. },
  4574. "$schema": {
  4575. "type": "string",
  4576. "format": "uri"
  4577. },
  4578. "title": {
  4579. "type": "string"
  4580. },
  4581. "description": {
  4582. "type": "string"
  4583. },
  4584. "default": {},
  4585. "multipleOf": {
  4586. "type": "number",
  4587. "minimum": 0,
  4588. "exclusiveMinimum": true
  4589. },
  4590. "maximum": {
  4591. "type": "number"
  4592. },
  4593. "exclusiveMaximum": {
  4594. "type": "boolean",
  4595. "default": false
  4596. },
  4597. "minimum": {
  4598. "type": "number"
  4599. },
  4600. "exclusiveMinimum": {
  4601. "type": "boolean",
  4602. "default": false
  4603. },
  4604. "maxLength": { "$ref": "#/definitions/positiveInteger" },
  4605. "minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
  4606. "pattern": {
  4607. "type": "string",
  4608. "format": "regex"
  4609. },
  4610. "additionalItems": {
  4611. "anyOf": [
  4612. { "type": "boolean" },
  4613. { "$ref": "#" }
  4614. ],
  4615. "default": {}
  4616. },
  4617. "items": {
  4618. "anyOf": [
  4619. { "$ref": "#" },
  4620. { "$ref": "#/definitions/schemaArray" }
  4621. ],
  4622. "default": {}
  4623. },
  4624. "maxItems": { "$ref": "#/definitions/positiveInteger" },
  4625. "minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
  4626. "uniqueItems": {
  4627. "type": "boolean",
  4628. "default": false
  4629. },
  4630. "maxProperties": { "$ref": "#/definitions/positiveInteger" },
  4631. "minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
  4632. "required": { "$ref": "#/definitions/stringArray" },
  4633. "additionalProperties": {
  4634. "anyOf": [
  4635. { "type": "boolean" },
  4636. { "$ref": "#" }
  4637. ],
  4638. "default": {}
  4639. },
  4640. "definitions": {
  4641. "type": "object",
  4642. "additionalProperties": { "$ref": "#" },
  4643. "default": {}
  4644. },
  4645. "properties": {
  4646. "type": "object",
  4647. "additionalProperties": { "$ref": "#" },
  4648. "default": {}
  4649. },
  4650. "patternProperties": {
  4651. "type": "object",
  4652. "additionalProperties": { "$ref": "#" },
  4653. "default": {}
  4654. },
  4655. "dependencies": {
  4656. "type": "object",
  4657. "additionalProperties": {
  4658. "anyOf": [
  4659. { "$ref": "#" },
  4660. { "$ref": "#/definitions/stringArray" }
  4661. ]
  4662. }
  4663. },
  4664. "enum": {
  4665. "type": "array",
  4666. "minItems": 1,
  4667. "uniqueItems": true
  4668. },
  4669. "type": {
  4670. "anyOf": [
  4671. { "$ref": "#/definitions/simpleTypes" },
  4672. {
  4673. "type": "array",
  4674. "items": { "$ref": "#/definitions/simpleTypes" },
  4675. "minItems": 1,
  4676. "uniqueItems": true
  4677. }
  4678. ]
  4679. },
  4680. "allOf": { "$ref": "#/definitions/schemaArray" },
  4681. "anyOf": { "$ref": "#/definitions/schemaArray" },
  4682. "oneOf": { "$ref": "#/definitions/schemaArray" },
  4683. "not": { "$ref": "#" }
  4684. },
  4685. "dependencies": {
  4686. "exclusiveMaximum": [ "maximum" ],
  4687. "exclusiveMinimum": [ "minimum" ]
  4688. },
  4689. "default": {}
  4690. }
  4691. },{}],39:[function(require,module,exports){
  4692. module.exports={
  4693. "id": "https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json#",
  4694. "$schema": "http://json-schema.org/draft-04/schema#",
  4695. "description": "Core schema meta-schema (v5 proposals)",
  4696. "definitions": {
  4697. "schemaArray": {
  4698. "type": "array",
  4699. "minItems": 1,
  4700. "items": { "$ref": "#" }
  4701. },
  4702. "positiveInteger": {
  4703. "type": "integer",
  4704. "minimum": 0
  4705. },
  4706. "positiveIntegerDefault0": {
  4707. "allOf": [ { "$ref": "#/definitions/positiveInteger" }, { "default": 0 } ]
  4708. },
  4709. "simpleTypes": {
  4710. "enum": [ "array", "boolean", "integer", "null", "number", "object", "string" ]
  4711. },
  4712. "stringArray": {
  4713. "type": "array",
  4714. "items": { "type": "string" },
  4715. "minItems": 1,
  4716. "uniqueItems": true
  4717. },
  4718. "$data": {
  4719. "type": "object",
  4720. "required": [ "$data" ],
  4721. "properties": {
  4722. "$data": {
  4723. "type": "string",
  4724. "anyOf": [
  4725. { "format": "relative-json-pointer" },
  4726. { "format": "json-pointer" }
  4727. ]
  4728. }
  4729. },
  4730. "additionalProperties": false
  4731. }
  4732. },
  4733. "type": "object",
  4734. "properties": {
  4735. "id": {
  4736. "type": "string",
  4737. "format": "uri"
  4738. },
  4739. "$schema": {
  4740. "type": "string",
  4741. "format": "uri"
  4742. },
  4743. "title": {
  4744. "type": "string"
  4745. },
  4746. "description": {
  4747. "type": "string"
  4748. },
  4749. "default": {},
  4750. "multipleOf": {
  4751. "anyOf": [
  4752. {
  4753. "type": "number",
  4754. "minimum": 0,
  4755. "exclusiveMinimum": true
  4756. },
  4757. { "$ref": "#/definitions/$data" }
  4758. ]
  4759. },
  4760. "maximum": {
  4761. "anyOf": [
  4762. { "type": "number" },
  4763. { "$ref": "#/definitions/$data" }
  4764. ]
  4765. },
  4766. "exclusiveMaximum": {
  4767. "anyOf": [
  4768. {
  4769. "type": "boolean",
  4770. "default": false
  4771. },
  4772. { "$ref": "#/definitions/$data" }
  4773. ]
  4774. },
  4775. "minimum": {
  4776. "anyOf": [
  4777. { "type": "number" },
  4778. { "$ref": "#/definitions/$data" }
  4779. ]
  4780. },
  4781. "exclusiveMinimum": {
  4782. "anyOf": [
  4783. {
  4784. "type": "boolean",
  4785. "default": false
  4786. },
  4787. { "$ref": "#/definitions/$data" }
  4788. ]
  4789. },
  4790. "maxLength": {
  4791. "anyOf": [
  4792. { "$ref": "#/definitions/positiveInteger" },
  4793. { "$ref": "#/definitions/$data" }
  4794. ]
  4795. },
  4796. "minLength": {
  4797. "anyOf": [
  4798. { "$ref": "#/definitions/positiveIntegerDefault0" },
  4799. { "$ref": "#/definitions/$data" }
  4800. ]
  4801. },
  4802. "pattern": {
  4803. "anyOf": [
  4804. {
  4805. "type": "string",
  4806. "format": "regex"
  4807. },
  4808. { "$ref": "#/definitions/$data" }
  4809. ]
  4810. },
  4811. "additionalItems": {
  4812. "anyOf": [
  4813. { "type": "boolean" },
  4814. { "$ref": "#" },
  4815. { "$ref": "#/definitions/$data" }
  4816. ],
  4817. "default": {}
  4818. },
  4819. "items": {
  4820. "anyOf": [
  4821. { "$ref": "#" },
  4822. { "$ref": "#/definitions/schemaArray" }
  4823. ],
  4824. "default": {}
  4825. },
  4826. "maxItems": {
  4827. "anyOf": [
  4828. { "$ref": "#/definitions/positiveInteger" },
  4829. { "$ref": "#/definitions/$data" }
  4830. ]
  4831. },
  4832. "minItems": {
  4833. "anyOf": [
  4834. { "$ref": "#/definitions/positiveIntegerDefault0" },
  4835. { "$ref": "#/definitions/$data" }
  4836. ]
  4837. },
  4838. "uniqueItems": {
  4839. "anyOf": [
  4840. {
  4841. "type": "boolean",
  4842. "default": false
  4843. },
  4844. { "$ref": "#/definitions/$data" }
  4845. ]
  4846. },
  4847. "maxProperties": {
  4848. "anyOf": [
  4849. { "$ref": "#/definitions/positiveInteger" },
  4850. { "$ref": "#/definitions/$data" }
  4851. ]
  4852. },
  4853. "minProperties": {
  4854. "anyOf": [
  4855. { "$ref": "#/definitions/positiveIntegerDefault0" },
  4856. { "$ref": "#/definitions/$data" }
  4857. ]
  4858. },
  4859. "required": {
  4860. "anyOf": [
  4861. { "$ref": "#/definitions/stringArray" },
  4862. { "$ref": "#/definitions/$data" }
  4863. ]
  4864. },
  4865. "additionalProperties": {
  4866. "anyOf": [
  4867. { "type": "boolean" },
  4868. { "$ref": "#" },
  4869. { "$ref": "#/definitions/$data" }
  4870. ],
  4871. "default": {}
  4872. },
  4873. "definitions": {
  4874. "type": "object",
  4875. "additionalProperties": { "$ref": "#" },
  4876. "default": {}
  4877. },
  4878. "properties": {
  4879. "type": "object",
  4880. "additionalProperties": { "$ref": "#" },
  4881. "default": {}
  4882. },
  4883. "patternProperties": {
  4884. "type": "object",
  4885. "additionalProperties": { "$ref": "#" },
  4886. "default": {}
  4887. },
  4888. "dependencies": {
  4889. "type": "object",
  4890. "additionalProperties": {
  4891. "anyOf": [
  4892. { "$ref": "#" },
  4893. { "$ref": "#/definitions/stringArray" }
  4894. ]
  4895. }
  4896. },
  4897. "enum": {
  4898. "anyOf": [
  4899. {
  4900. "type": "array",
  4901. "minItems": 1,
  4902. "uniqueItems": true
  4903. },
  4904. { "$ref": "#/definitions/$data" }
  4905. ]
  4906. },
  4907. "type": {
  4908. "anyOf": [
  4909. { "$ref": "#/definitions/simpleTypes" },
  4910. {
  4911. "type": "array",
  4912. "items": { "$ref": "#/definitions/simpleTypes" },
  4913. "minItems": 1,
  4914. "uniqueItems": true
  4915. }
  4916. ]
  4917. },
  4918. "allOf": { "$ref": "#/definitions/schemaArray" },
  4919. "anyOf": { "$ref": "#/definitions/schemaArray" },
  4920. "oneOf": { "$ref": "#/definitions/schemaArray" },
  4921. "not": { "$ref": "#" },
  4922. "format": {
  4923. "anyOf": [
  4924. { "type": "string" },
  4925. { "$ref": "#/definitions/$data" }
  4926. ]
  4927. },
  4928. "formatMaximum": {
  4929. "anyOf": [
  4930. { "type": "string" },
  4931. { "$ref": "#/definitions/$data" }
  4932. ]
  4933. },
  4934. "formatMinimum": {
  4935. "anyOf": [
  4936. { "type": "string" },
  4937. { "$ref": "#/definitions/$data" }
  4938. ]
  4939. },
  4940. "formatExclusiveMaximum": {
  4941. "anyOf": [
  4942. {
  4943. "type": "boolean",
  4944. "default": false
  4945. },
  4946. { "$ref": "#/definitions/$data" }
  4947. ]
  4948. },
  4949. "formatExclusiveMinimum": {
  4950. "anyOf": [
  4951. {
  4952. "type": "boolean",
  4953. "default": false
  4954. },
  4955. { "$ref": "#/definitions/$data" }
  4956. ]
  4957. },
  4958. "constant": {
  4959. "anyOf": [
  4960. {},
  4961. { "$ref": "#/definitions/$data" }
  4962. ]
  4963. },
  4964. "contains": { "$ref": "#" },
  4965. "patternGroups": {
  4966. "type": "object",
  4967. "additionalProperties": {
  4968. "type": "object",
  4969. "required": [ "schema" ],
  4970. "properties": {
  4971. "maximum": {
  4972. "anyOf": [
  4973. { "$ref": "#/definitions/positiveInteger" },
  4974. { "$ref": "#/definitions/$data" }
  4975. ]
  4976. },
  4977. "minimum": {
  4978. "anyOf": [
  4979. { "$ref": "#/definitions/positiveIntegerDefault0" },
  4980. { "$ref": "#/definitions/$data" }
  4981. ]
  4982. },
  4983. "schema": { "$ref": "#" }
  4984. },
  4985. "additionalProperties": false
  4986. },
  4987. "default": {}
  4988. },
  4989. "switch": {
  4990. "type": "array",
  4991. "items": {
  4992. "required": [ "then" ],
  4993. "properties": {
  4994. "if": { "$ref": "#" },
  4995. "then": {
  4996. "anyOf": [
  4997. { "type": "boolean" },
  4998. { "$ref": "#" }
  4999. ]
  5000. },
  5001. "continue": { "type": "boolean" }
  5002. },
  5003. "additionalProperties": false,
  5004. "dependencies": {
  5005. "continue": [ "if" ]
  5006. }
  5007. }
  5008. }
  5009. },
  5010. "dependencies": {
  5011. "exclusiveMaximum": [ "maximum" ],
  5012. "exclusiveMinimum": [ "minimum" ],
  5013. "formatMaximum": [ "format" ],
  5014. "formatMinimum": [ "format" ],
  5015. "formatExclusiveMaximum": [ "formatMaximum" ],
  5016. "formatExclusiveMinimum": [ "formatMinimum" ]
  5017. },
  5018. "default": {}
  5019. }
  5020. },{}],40:[function(require,module,exports){
  5021. 'use strict';
  5022. var META_SCHEMA_ID = 'https://raw.githubusercontent.com/epoberezkin/ajv/master/lib/refs/json-schema-v5.json';
  5023. module.exports = {
  5024. enable: enableV5,
  5025. META_SCHEMA_ID: META_SCHEMA_ID
  5026. };
  5027. function enableV5(ajv) {
  5028. var inlineFunctions = {
  5029. 'switch': require('./dotjs/switch'),
  5030. 'constant': require('./dotjs/constant'),
  5031. '_formatLimit': require('./dotjs/_formatLimit'),
  5032. 'patternRequired': require('./dotjs/patternRequired')
  5033. };
  5034. if (ajv._opts.meta !== false) {
  5035. var metaSchema = require('./refs/json-schema-v5.json');
  5036. ajv.addMetaSchema(metaSchema, META_SCHEMA_ID);
  5037. }
  5038. _addKeyword('constant');
  5039. ajv.addKeyword('contains', { type: 'array', macro: containsMacro });
  5040. _addKeyword('formatMaximum', 'string', inlineFunctions._formatLimit);
  5041. _addKeyword('formatMinimum', 'string', inlineFunctions._formatLimit);
  5042. ajv.addKeyword('formatExclusiveMaximum');
  5043. ajv.addKeyword('formatExclusiveMinimum');
  5044. ajv.addKeyword('patternGroups'); // implemented in properties.jst
  5045. _addKeyword('patternRequired', 'object');
  5046. _addKeyword('switch');
  5047. function _addKeyword(keyword, types, inlineFunc) {
  5048. var definition = {
  5049. inline: inlineFunc || inlineFunctions[keyword],
  5050. statements: true,
  5051. errors: 'full'
  5052. };
  5053. if (types) definition.type = types;
  5054. ajv.addKeyword(keyword, definition);
  5055. }
  5056. }
  5057. function containsMacro(schema) {
  5058. return {
  5059. not: { items: { not: schema } }
  5060. };
  5061. }
  5062. },{"./dotjs/_formatLimit":13,"./dotjs/constant":20,"./dotjs/patternRequired":30,"./dotjs/switch":34,"./refs/json-schema-v5.json":39}],41:[function(require,module,exports){
  5063. /**
  5064. * slice() reference.
  5065. */
  5066. var slice = Array.prototype.slice;
  5067. /**
  5068. * Expose `co`.
  5069. */
  5070. module.exports = co['default'] = co.co = co;
  5071. /**
  5072. * Wrap the given generator `fn` into a
  5073. * function that returns a promise.
  5074. * This is a separate function so that
  5075. * every `co()` call doesn't create a new,
  5076. * unnecessary closure.
  5077. *
  5078. * @param {GeneratorFunction} fn
  5079. * @return {Function}
  5080. * @api public
  5081. */
  5082. co.wrap = function (fn) {
  5083. createPromise.__generatorFunction__ = fn;
  5084. return createPromise;
  5085. function createPromise() {
  5086. return co.call(this, fn.apply(this, arguments));
  5087. }
  5088. };
  5089. /**
  5090. * Execute the generator function or a generator
  5091. * and return a promise.
  5092. *
  5093. * @param {Function} fn
  5094. * @return {Promise}
  5095. * @api public
  5096. */
  5097. function co(gen) {
  5098. var ctx = this;
  5099. var args = slice.call(arguments, 1)
  5100. // we wrap everything in a promise to avoid promise chaining,
  5101. // which leads to memory leak errors.
  5102. // see https://github.com/tj/co/issues/180
  5103. return new Promise(function(resolve, reject) {
  5104. if (typeof gen === 'function') gen = gen.apply(ctx, args);
  5105. if (!gen || typeof gen.next !== 'function') return resolve(gen);
  5106. onFulfilled();
  5107. /**
  5108. * @param {Mixed} res
  5109. * @return {Promise}
  5110. * @api private
  5111. */
  5112. function onFulfilled(res) {
  5113. var ret;
  5114. try {
  5115. ret = gen.next(res);
  5116. } catch (e) {
  5117. return reject(e);
  5118. }
  5119. next(ret);
  5120. }
  5121. /**
  5122. * @param {Error} err
  5123. * @return {Promise}
  5124. * @api private
  5125. */
  5126. function onRejected(err) {
  5127. var ret;
  5128. try {
  5129. ret = gen.throw(err);
  5130. } catch (e) {
  5131. return reject(e);
  5132. }
  5133. next(ret);
  5134. }
  5135. /**
  5136. * Get the next value in the generator,
  5137. * return a promise.
  5138. *
  5139. * @param {Object} ret
  5140. * @return {Promise}
  5141. * @api private
  5142. */
  5143. function next(ret) {
  5144. if (ret.done) return resolve(ret.value);
  5145. var value = toPromise.call(ctx, ret.value);
  5146. if (value && isPromise(value)) return value.then(onFulfilled, onRejected);
  5147. return onRejected(new TypeError('You may only yield a function, promise, generator, array, or object, '
  5148. + 'but the following object was passed: "' + String(ret.value) + '"'));
  5149. }
  5150. });
  5151. }
  5152. /**
  5153. * Convert a `yield`ed value into a promise.
  5154. *
  5155. * @param {Mixed} obj
  5156. * @return {Promise}
  5157. * @api private
  5158. */
  5159. function toPromise(obj) {
  5160. if (!obj) return obj;
  5161. if (isPromise(obj)) return obj;
  5162. if (isGeneratorFunction(obj) || isGenerator(obj)) return co.call(this, obj);
  5163. if ('function' == typeof obj) return thunkToPromise.call(this, obj);
  5164. if (Array.isArray(obj)) return arrayToPromise.call(this, obj);
  5165. if (isObject(obj)) return objectToPromise.call(this, obj);
  5166. return obj;
  5167. }
  5168. /**
  5169. * Convert a thunk to a promise.
  5170. *
  5171. * @param {Function}
  5172. * @return {Promise}
  5173. * @api private
  5174. */
  5175. function thunkToPromise(fn) {
  5176. var ctx = this;
  5177. return new Promise(function (resolve, reject) {
  5178. fn.call(ctx, function (err, res) {
  5179. if (err) return reject(err);
  5180. if (arguments.length > 2) res = slice.call(arguments, 1);
  5181. resolve(res);
  5182. });
  5183. });
  5184. }
  5185. /**
  5186. * Convert an array of "yieldables" to a promise.
  5187. * Uses `Promise.all()` internally.
  5188. *
  5189. * @param {Array} obj
  5190. * @return {Promise}
  5191. * @api private
  5192. */
  5193. function arrayToPromise(obj) {
  5194. return Promise.all(obj.map(toPromise, this));
  5195. }
  5196. /**
  5197. * Convert an object of "yieldables" to a promise.
  5198. * Uses `Promise.all()` internally.
  5199. *
  5200. * @param {Object} obj
  5201. * @return {Promise}
  5202. * @api private
  5203. */
  5204. function objectToPromise(obj){
  5205. var results = new obj.constructor();
  5206. var keys = Object.keys(obj);
  5207. var promises = [];
  5208. for (var i = 0; i < keys.length; i++) {
  5209. var key = keys[i];
  5210. var promise = toPromise.call(this, obj[key]);
  5211. if (promise && isPromise(promise)) defer(promise, key);
  5212. else results[key] = obj[key];
  5213. }
  5214. return Promise.all(promises).then(function () {
  5215. return results;
  5216. });
  5217. function defer(promise, key) {
  5218. // predefine the key in the result
  5219. results[key] = undefined;
  5220. promises.push(promise.then(function (res) {
  5221. results[key] = res;
  5222. }));
  5223. }
  5224. }
  5225. /**
  5226. * Check if `obj` is a promise.
  5227. *
  5228. * @param {Object} obj
  5229. * @return {Boolean}
  5230. * @api private
  5231. */
  5232. function isPromise(obj) {
  5233. return 'function' == typeof obj.then;
  5234. }
  5235. /**
  5236. * Check if `obj` is a generator.
  5237. *
  5238. * @param {Mixed} obj
  5239. * @return {Boolean}
  5240. * @api private
  5241. */
  5242. function isGenerator(obj) {
  5243. return 'function' == typeof obj.next && 'function' == typeof obj.throw;
  5244. }
  5245. /**
  5246. * Check if `obj` is a generator function.
  5247. *
  5248. * @param {Mixed} obj
  5249. * @return {Boolean}
  5250. * @api private
  5251. */
  5252. function isGeneratorFunction(obj) {
  5253. var constructor = obj.constructor;
  5254. if (!constructor) return false;
  5255. if ('GeneratorFunction' === constructor.name || 'GeneratorFunction' === constructor.displayName) return true;
  5256. return isGenerator(constructor.prototype);
  5257. }
  5258. /**
  5259. * Check for plain object.
  5260. *
  5261. * @param {Mixed} val
  5262. * @return {Boolean}
  5263. * @api private
  5264. */
  5265. function isObject(val) {
  5266. return Object == val.constructor;
  5267. }
  5268. },{}],42:[function(require,module,exports){
  5269. var json = typeof JSON !== 'undefined' ? JSON : require('jsonify');
  5270. module.exports = function (obj, opts) {
  5271. if (!opts) opts = {};
  5272. if (typeof opts === 'function') opts = { cmp: opts };
  5273. var space = opts.space || '';
  5274. if (typeof space === 'number') space = Array(space+1).join(' ');
  5275. var cycles = (typeof opts.cycles === 'boolean') ? opts.cycles : false;
  5276. var replacer = opts.replacer || function(key, value) { return value; };
  5277. var cmp = opts.cmp && (function (f) {
  5278. return function (node) {
  5279. return function (a, b) {
  5280. var aobj = { key: a, value: node[a] };
  5281. var bobj = { key: b, value: node[b] };
  5282. return f(aobj, bobj);
  5283. };
  5284. };
  5285. })(opts.cmp);
  5286. var seen = [];
  5287. return (function stringify (parent, key, node, level) {
  5288. var indent = space ? ('\n' + new Array(level + 1).join(space)) : '';
  5289. var colonSeparator = space ? ': ' : ':';
  5290. if (node && node.toJSON && typeof node.toJSON === 'function') {
  5291. node = node.toJSON();
  5292. }
  5293. node = replacer.call(parent, key, node);
  5294. if (node === undefined) {
  5295. return;
  5296. }
  5297. if (typeof node !== 'object' || node === null) {
  5298. return json.stringify(node);
  5299. }
  5300. if (isArray(node)) {
  5301. var out = [];
  5302. for (var i = 0; i < node.length; i++) {
  5303. var item = stringify(node, i, node[i], level+1) || json.stringify(null);
  5304. out.push(indent + space + item);
  5305. }
  5306. return '[' + out.join(',') + indent + ']';
  5307. }
  5308. else {
  5309. if (seen.indexOf(node) !== -1) {
  5310. if (cycles) return json.stringify('__cycle__');
  5311. throw new TypeError('Converting circular structure to JSON');
  5312. }
  5313. else seen.push(node);
  5314. var keys = objectKeys(node).sort(cmp && cmp(node));
  5315. var out = [];
  5316. for (var i = 0; i < keys.length; i++) {
  5317. var key = keys[i];
  5318. var value = stringify(node, key, node[key], level+1);
  5319. if(!value) continue;
  5320. var keyValue = json.stringify(key)
  5321. + colonSeparator
  5322. + value;
  5323. ;
  5324. out.push(indent + space + keyValue);
  5325. }
  5326. seen.splice(seen.indexOf(node), 1);
  5327. return '{' + out.join(',') + indent + '}';
  5328. }
  5329. })({ '': obj }, '', obj, 0);
  5330. };
  5331. var isArray = Array.isArray || function (x) {
  5332. return {}.toString.call(x) === '[object Array]';
  5333. };
  5334. var objectKeys = Object.keys || function (obj) {
  5335. var has = Object.prototype.hasOwnProperty || function () { return true };
  5336. var keys = [];
  5337. for (var key in obj) {
  5338. if (has.call(obj, key)) keys.push(key);
  5339. }
  5340. return keys;
  5341. };
  5342. },{"jsonify":43}],43:[function(require,module,exports){
  5343. exports.parse = require('./lib/parse');
  5344. exports.stringify = require('./lib/stringify');
  5345. },{"./lib/parse":44,"./lib/stringify":45}],44:[function(require,module,exports){
  5346. var at, // The index of the current character
  5347. ch, // The current character
  5348. escapee = {
  5349. '"': '"',
  5350. '\\': '\\',
  5351. '/': '/',
  5352. b: '\b',
  5353. f: '\f',
  5354. n: '\n',
  5355. r: '\r',
  5356. t: '\t'
  5357. },
  5358. text,
  5359. error = function (m) {
  5360. // Call error when something is wrong.
  5361. throw {
  5362. name: 'SyntaxError',
  5363. message: m,
  5364. at: at,
  5365. text: text
  5366. };
  5367. },
  5368. next = function (c) {
  5369. // If a c parameter is provided, verify that it matches the current character.
  5370. if (c && c !== ch) {
  5371. error("Expected '" + c + "' instead of '" + ch + "'");
  5372. }
  5373. // Get the next character. When there are no more characters,
  5374. // return the empty string.
  5375. ch = text.charAt(at);
  5376. at += 1;
  5377. return ch;
  5378. },
  5379. number = function () {
  5380. // Parse a number value.
  5381. var number,
  5382. string = '';
  5383. if (ch === '-') {
  5384. string = '-';
  5385. next('-');
  5386. }
  5387. while (ch >= '0' && ch <= '9') {
  5388. string += ch;
  5389. next();
  5390. }
  5391. if (ch === '.') {
  5392. string += '.';
  5393. while (next() && ch >= '0' && ch <= '9') {
  5394. string += ch;
  5395. }
  5396. }
  5397. if (ch === 'e' || ch === 'E') {
  5398. string += ch;
  5399. next();
  5400. if (ch === '-' || ch === '+') {
  5401. string += ch;
  5402. next();
  5403. }
  5404. while (ch >= '0' && ch <= '9') {
  5405. string += ch;
  5406. next();
  5407. }
  5408. }
  5409. number = +string;
  5410. if (!isFinite(number)) {
  5411. error("Bad number");
  5412. } else {
  5413. return number;
  5414. }
  5415. },
  5416. string = function () {
  5417. // Parse a string value.
  5418. var hex,
  5419. i,
  5420. string = '',
  5421. uffff;
  5422. // When parsing for string values, we must look for " and \ characters.
  5423. if (ch === '"') {
  5424. while (next()) {
  5425. if (ch === '"') {
  5426. next();
  5427. return string;
  5428. } else if (ch === '\\') {
  5429. next();
  5430. if (ch === 'u') {
  5431. uffff = 0;
  5432. for (i = 0; i < 4; i += 1) {
  5433. hex = parseInt(next(), 16);
  5434. if (!isFinite(hex)) {
  5435. break;
  5436. }
  5437. uffff = uffff * 16 + hex;
  5438. }
  5439. string += String.fromCharCode(uffff);
  5440. } else if (typeof escapee[ch] === 'string') {
  5441. string += escapee[ch];
  5442. } else {
  5443. break;
  5444. }
  5445. } else {
  5446. string += ch;
  5447. }
  5448. }
  5449. }
  5450. error("Bad string");
  5451. },
  5452. white = function () {
  5453. // Skip whitespace.
  5454. while (ch && ch <= ' ') {
  5455. next();
  5456. }
  5457. },
  5458. word = function () {
  5459. // true, false, or null.
  5460. switch (ch) {
  5461. case 't':
  5462. next('t');
  5463. next('r');
  5464. next('u');
  5465. next('e');
  5466. return true;
  5467. case 'f':
  5468. next('f');
  5469. next('a');
  5470. next('l');
  5471. next('s');
  5472. next('e');
  5473. return false;
  5474. case 'n':
  5475. next('n');
  5476. next('u');
  5477. next('l');
  5478. next('l');
  5479. return null;
  5480. }
  5481. error("Unexpected '" + ch + "'");
  5482. },
  5483. value, // Place holder for the value function.
  5484. array = function () {
  5485. // Parse an array value.
  5486. var array = [];
  5487. if (ch === '[') {
  5488. next('[');
  5489. white();
  5490. if (ch === ']') {
  5491. next(']');
  5492. return array; // empty array
  5493. }
  5494. while (ch) {
  5495. array.push(value());
  5496. white();
  5497. if (ch === ']') {
  5498. next(']');
  5499. return array;
  5500. }
  5501. next(',');
  5502. white();
  5503. }
  5504. }
  5505. error("Bad array");
  5506. },
  5507. object = function () {
  5508. // Parse an object value.
  5509. var key,
  5510. object = {};
  5511. if (ch === '{') {
  5512. next('{');
  5513. white();
  5514. if (ch === '}') {
  5515. next('}');
  5516. return object; // empty object
  5517. }
  5518. while (ch) {
  5519. key = string();
  5520. white();
  5521. next(':');
  5522. if (Object.hasOwnProperty.call(object, key)) {
  5523. error('Duplicate key "' + key + '"');
  5524. }
  5525. object[key] = value();
  5526. white();
  5527. if (ch === '}') {
  5528. next('}');
  5529. return object;
  5530. }
  5531. next(',');
  5532. white();
  5533. }
  5534. }
  5535. error("Bad object");
  5536. };
  5537. value = function () {
  5538. // Parse a JSON value. It could be an object, an array, a string, a number,
  5539. // or a word.
  5540. white();
  5541. switch (ch) {
  5542. case '{':
  5543. return object();
  5544. case '[':
  5545. return array();
  5546. case '"':
  5547. return string();
  5548. case '-':
  5549. return number();
  5550. default:
  5551. return ch >= '0' && ch <= '9' ? number() : word();
  5552. }
  5553. };
  5554. // Return the json_parse function. It will have access to all of the above
  5555. // functions and variables.
  5556. module.exports = function (source, reviver) {
  5557. var result;
  5558. text = source;
  5559. at = 0;
  5560. ch = ' ';
  5561. result = value();
  5562. white();
  5563. if (ch) {
  5564. error("Syntax error");
  5565. }
  5566. // If there is a reviver function, we recursively walk the new structure,
  5567. // passing each name/value pair to the reviver function for possible
  5568. // transformation, starting with a temporary root object that holds the result
  5569. // in an empty key. If there is not a reviver function, we simply return the
  5570. // result.
  5571. return typeof reviver === 'function' ? (function walk(holder, key) {
  5572. var k, v, value = holder[key];
  5573. if (value && typeof value === 'object') {
  5574. for (k in value) {
  5575. if (Object.prototype.hasOwnProperty.call(value, k)) {
  5576. v = walk(value, k);
  5577. if (v !== undefined) {
  5578. value[k] = v;
  5579. } else {
  5580. delete value[k];
  5581. }
  5582. }
  5583. }
  5584. }
  5585. return reviver.call(holder, key, value);
  5586. }({'': result}, '')) : result;
  5587. };
  5588. },{}],45:[function(require,module,exports){
  5589. var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  5590. escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,
  5591. gap,
  5592. indent,
  5593. meta = { // table of character substitutions
  5594. '\b': '\\b',
  5595. '\t': '\\t',
  5596. '\n': '\\n',
  5597. '\f': '\\f',
  5598. '\r': '\\r',
  5599. '"' : '\\"',
  5600. '\\': '\\\\'
  5601. },
  5602. rep;
  5603. function quote(string) {
  5604. // If the string contains no control characters, no quote characters, and no
  5605. // backslash characters, then we can safely slap some quotes around it.
  5606. // Otherwise we must also replace the offending characters with safe escape
  5607. // sequences.
  5608. escapable.lastIndex = 0;
  5609. return escapable.test(string) ? '"' + string.replace(escapable, function (a) {
  5610. var c = meta[a];
  5611. return typeof c === 'string' ? c :
  5612. '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
  5613. }) + '"' : '"' + string + '"';
  5614. }
  5615. function str(key, holder) {
  5616. // Produce a string from holder[key].
  5617. var i, // The loop counter.
  5618. k, // The member key.
  5619. v, // The member value.
  5620. length,
  5621. mind = gap,
  5622. partial,
  5623. value = holder[key];
  5624. // If the value has a toJSON method, call it to obtain a replacement value.
  5625. if (value && typeof value === 'object' &&
  5626. typeof value.toJSON === 'function') {
  5627. value = value.toJSON(key);
  5628. }
  5629. // If we were called with a replacer function, then call the replacer to
  5630. // obtain a replacement value.
  5631. if (typeof rep === 'function') {
  5632. value = rep.call(holder, key, value);
  5633. }
  5634. // What happens next depends on the value's type.
  5635. switch (typeof value) {
  5636. case 'string':
  5637. return quote(value);
  5638. case 'number':
  5639. // JSON numbers must be finite. Encode non-finite numbers as null.
  5640. return isFinite(value) ? String(value) : 'null';
  5641. case 'boolean':
  5642. case 'null':
  5643. // If the value is a boolean or null, convert it to a string. Note:
  5644. // typeof null does not produce 'null'. The case is included here in
  5645. // the remote chance that this gets fixed someday.
  5646. return String(value);
  5647. case 'object':
  5648. if (!value) return 'null';
  5649. gap += indent;
  5650. partial = [];
  5651. // Array.isArray
  5652. if (Object.prototype.toString.apply(value) === '[object Array]') {
  5653. length = value.length;
  5654. for (i = 0; i < length; i += 1) {
  5655. partial[i] = str(i, value) || 'null';
  5656. }
  5657. // Join all of the elements together, separated with commas, and
  5658. // wrap them in brackets.
  5659. v = partial.length === 0 ? '[]' : gap ?
  5660. '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' :
  5661. '[' + partial.join(',') + ']';
  5662. gap = mind;
  5663. return v;
  5664. }
  5665. // If the replacer is an array, use it to select the members to be
  5666. // stringified.
  5667. if (rep && typeof rep === 'object') {
  5668. length = rep.length;
  5669. for (i = 0; i < length; i += 1) {
  5670. k = rep[i];
  5671. if (typeof k === 'string') {
  5672. v = str(k, value);
  5673. if (v) {
  5674. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  5675. }
  5676. }
  5677. }
  5678. }
  5679. else {
  5680. // Otherwise, iterate through all of the keys in the object.
  5681. for (k in value) {
  5682. if (Object.prototype.hasOwnProperty.call(value, k)) {
  5683. v = str(k, value);
  5684. if (v) {
  5685. partial.push(quote(k) + (gap ? ': ' : ':') + v);
  5686. }
  5687. }
  5688. }
  5689. }
  5690. // Join all of the member texts together, separated with commas,
  5691. // and wrap them in braces.
  5692. v = partial.length === 0 ? '{}' : gap ?
  5693. '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' :
  5694. '{' + partial.join(',') + '}';
  5695. gap = mind;
  5696. return v;
  5697. }
  5698. }
  5699. module.exports = function (value, replacer, space) {
  5700. var i;
  5701. gap = '';
  5702. indent = '';
  5703. // If the space parameter is a number, make an indent string containing that
  5704. // many spaces.
  5705. if (typeof space === 'number') {
  5706. for (i = 0; i < space; i += 1) {
  5707. indent += ' ';
  5708. }
  5709. }
  5710. // If the space parameter is a string, it will be used as the indent string.
  5711. else if (typeof space === 'string') {
  5712. indent = space;
  5713. }
  5714. // If there is a replacer, it must be a function or an array.
  5715. // Otherwise, throw an error.
  5716. rep = replacer;
  5717. if (replacer && typeof replacer !== 'function'
  5718. && (typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
  5719. throw new Error('JSON.stringify');
  5720. }
  5721. // Make a fake root object containing our value under the key of ''.
  5722. // Return the result of stringifying the value.
  5723. return str('', {'': value});
  5724. };
  5725. },{}],46:[function(require,module,exports){
  5726. (function (global){
  5727. /*! https://mths.be/punycode v1.4.1 by @mathias */
  5728. ;(function(root) {
  5729. /** Detect free variables */
  5730. var freeExports = typeof exports == 'object' && exports &&
  5731. !exports.nodeType && exports;
  5732. var freeModule = typeof module == 'object' && module &&
  5733. !module.nodeType && module;
  5734. var freeGlobal = typeof global == 'object' && global;
  5735. if (
  5736. freeGlobal.global === freeGlobal ||
  5737. freeGlobal.window === freeGlobal ||
  5738. freeGlobal.self === freeGlobal
  5739. ) {
  5740. root = freeGlobal;
  5741. }
  5742. /**
  5743. * The `punycode` object.
  5744. * @name punycode
  5745. * @type Object
  5746. */
  5747. var punycode,
  5748. /** Highest positive signed 32-bit float value */
  5749. maxInt = 2147483647, // aka. 0x7FFFFFFF or 2^31-1
  5750. /** Bootstring parameters */
  5751. base = 36,
  5752. tMin = 1,
  5753. tMax = 26,
  5754. skew = 38,
  5755. damp = 700,
  5756. initialBias = 72,
  5757. initialN = 128, // 0x80
  5758. delimiter = '-', // '\x2D'
  5759. /** Regular expressions */
  5760. regexPunycode = /^xn--/,
  5761. regexNonASCII = /[^\x20-\x7E]/, // unprintable ASCII chars + non-ASCII chars
  5762. regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g, // RFC 3490 separators
  5763. /** Error messages */
  5764. errors = {
  5765. 'overflow': 'Overflow: input needs wider integers to process',
  5766. 'not-basic': 'Illegal input >= 0x80 (not a basic code point)',
  5767. 'invalid-input': 'Invalid input'
  5768. },
  5769. /** Convenience shortcuts */
  5770. baseMinusTMin = base - tMin,
  5771. floor = Math.floor,
  5772. stringFromCharCode = String.fromCharCode,
  5773. /** Temporary variable */
  5774. key;
  5775. /*--------------------------------------------------------------------------*/
  5776. /**
  5777. * A generic error utility function.
  5778. * @private
  5779. * @param {String} type The error type.
  5780. * @returns {Error} Throws a `RangeError` with the applicable error message.
  5781. */
  5782. function error(type) {
  5783. throw new RangeError(errors[type]);
  5784. }
  5785. /**
  5786. * A generic `Array#map` utility function.
  5787. * @private
  5788. * @param {Array} array The array to iterate over.
  5789. * @param {Function} callback The function that gets called for every array
  5790. * item.
  5791. * @returns {Array} A new array of values returned by the callback function.
  5792. */
  5793. function map(array, fn) {
  5794. var length = array.length;
  5795. var result = [];
  5796. while (length--) {
  5797. result[length] = fn(array[length]);
  5798. }
  5799. return result;
  5800. }
  5801. /**
  5802. * A simple `Array#map`-like wrapper to work with domain name strings or email
  5803. * addresses.
  5804. * @private
  5805. * @param {String} domain The domain name or email address.
  5806. * @param {Function} callback The function that gets called for every
  5807. * character.
  5808. * @returns {Array} A new string of characters returned by the callback
  5809. * function.
  5810. */
  5811. function mapDomain(string, fn) {
  5812. var parts = string.split('@');
  5813. var result = '';
  5814. if (parts.length > 1) {
  5815. // In email addresses, only the domain name should be punycoded. Leave
  5816. // the local part (i.e. everything up to `@`) intact.
  5817. result = parts[0] + '@';
  5818. string = parts[1];
  5819. }
  5820. // Avoid `split(regex)` for IE8 compatibility. See #17.
  5821. string = string.replace(regexSeparators, '\x2E');
  5822. var labels = string.split('.');
  5823. var encoded = map(labels, fn).join('.');
  5824. return result + encoded;
  5825. }
  5826. /**
  5827. * Creates an array containing the numeric code points of each Unicode
  5828. * character in the string. While JavaScript uses UCS-2 internally,
  5829. * this function will convert a pair of surrogate halves (each of which
  5830. * UCS-2 exposes as separate characters) into a single code point,
  5831. * matching UTF-16.
  5832. * @see `punycode.ucs2.encode`
  5833. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  5834. * @memberOf punycode.ucs2
  5835. * @name decode
  5836. * @param {String} string The Unicode input string (UCS-2).
  5837. * @returns {Array} The new array of code points.
  5838. */
  5839. function ucs2decode(string) {
  5840. var output = [],
  5841. counter = 0,
  5842. length = string.length,
  5843. value,
  5844. extra;
  5845. while (counter < length) {
  5846. value = string.charCodeAt(counter++);
  5847. if (value >= 0xD800 && value <= 0xDBFF && counter < length) {
  5848. // high surrogate, and there is a next character
  5849. extra = string.charCodeAt(counter++);
  5850. if ((extra & 0xFC00) == 0xDC00) { // low surrogate
  5851. output.push(((value & 0x3FF) << 10) + (extra & 0x3FF) + 0x10000);
  5852. } else {
  5853. // unmatched surrogate; only append this code unit, in case the next
  5854. // code unit is the high surrogate of a surrogate pair
  5855. output.push(value);
  5856. counter--;
  5857. }
  5858. } else {
  5859. output.push(value);
  5860. }
  5861. }
  5862. return output;
  5863. }
  5864. /**
  5865. * Creates a string based on an array of numeric code points.
  5866. * @see `punycode.ucs2.decode`
  5867. * @memberOf punycode.ucs2
  5868. * @name encode
  5869. * @param {Array} codePoints The array of numeric code points.
  5870. * @returns {String} The new Unicode string (UCS-2).
  5871. */
  5872. function ucs2encode(array) {
  5873. return map(array, function(value) {
  5874. var output = '';
  5875. if (value > 0xFFFF) {
  5876. value -= 0x10000;
  5877. output += stringFromCharCode(value >>> 10 & 0x3FF | 0xD800);
  5878. value = 0xDC00 | value & 0x3FF;
  5879. }
  5880. output += stringFromCharCode(value);
  5881. return output;
  5882. }).join('');
  5883. }
  5884. /**
  5885. * Converts a basic code point into a digit/integer.
  5886. * @see `digitToBasic()`
  5887. * @private
  5888. * @param {Number} codePoint The basic numeric code point value.
  5889. * @returns {Number} The numeric value of a basic code point (for use in
  5890. * representing integers) in the range `0` to `base - 1`, or `base` if
  5891. * the code point does not represent a value.
  5892. */
  5893. function basicToDigit(codePoint) {
  5894. if (codePoint - 48 < 10) {
  5895. return codePoint - 22;
  5896. }
  5897. if (codePoint - 65 < 26) {
  5898. return codePoint - 65;
  5899. }
  5900. if (codePoint - 97 < 26) {
  5901. return codePoint - 97;
  5902. }
  5903. return base;
  5904. }
  5905. /**
  5906. * Converts a digit/integer into a basic code point.
  5907. * @see `basicToDigit()`
  5908. * @private
  5909. * @param {Number} digit The numeric value of a basic code point.
  5910. * @returns {Number} The basic code point whose value (when used for
  5911. * representing integers) is `digit`, which needs to be in the range
  5912. * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is
  5913. * used; else, the lowercase form is used. The behavior is undefined
  5914. * if `flag` is non-zero and `digit` has no uppercase form.
  5915. */
  5916. function digitToBasic(digit, flag) {
  5917. // 0..25 map to ASCII a..z or A..Z
  5918. // 26..35 map to ASCII 0..9
  5919. return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
  5920. }
  5921. /**
  5922. * Bias adaptation function as per section 3.4 of RFC 3492.
  5923. * https://tools.ietf.org/html/rfc3492#section-3.4
  5924. * @private
  5925. */
  5926. function adapt(delta, numPoints, firstTime) {
  5927. var k = 0;
  5928. delta = firstTime ? floor(delta / damp) : delta >> 1;
  5929. delta += floor(delta / numPoints);
  5930. for (/* no initialization */; delta > baseMinusTMin * tMax >> 1; k += base) {
  5931. delta = floor(delta / baseMinusTMin);
  5932. }
  5933. return floor(k + (baseMinusTMin + 1) * delta / (delta + skew));
  5934. }
  5935. /**
  5936. * Converts a Punycode string of ASCII-only symbols to a string of Unicode
  5937. * symbols.
  5938. * @memberOf punycode
  5939. * @param {String} input The Punycode string of ASCII-only symbols.
  5940. * @returns {String} The resulting string of Unicode symbols.
  5941. */
  5942. function decode(input) {
  5943. // Don't use UCS-2
  5944. var output = [],
  5945. inputLength = input.length,
  5946. out,
  5947. i = 0,
  5948. n = initialN,
  5949. bias = initialBias,
  5950. basic,
  5951. j,
  5952. index,
  5953. oldi,
  5954. w,
  5955. k,
  5956. digit,
  5957. t,
  5958. /** Cached calculation results */
  5959. baseMinusT;
  5960. // Handle the basic code points: let `basic` be the number of input code
  5961. // points before the last delimiter, or `0` if there is none, then copy
  5962. // the first basic code points to the output.
  5963. basic = input.lastIndexOf(delimiter);
  5964. if (basic < 0) {
  5965. basic = 0;
  5966. }
  5967. for (j = 0; j < basic; ++j) {
  5968. // if it's not a basic code point
  5969. if (input.charCodeAt(j) >= 0x80) {
  5970. error('not-basic');
  5971. }
  5972. output.push(input.charCodeAt(j));
  5973. }
  5974. // Main decoding loop: start just after the last delimiter if any basic code
  5975. // points were copied; start at the beginning otherwise.
  5976. for (index = basic > 0 ? basic + 1 : 0; index < inputLength; /* no final expression */) {
  5977. // `index` is the index of the next character to be consumed.
  5978. // Decode a generalized variable-length integer into `delta`,
  5979. // which gets added to `i`. The overflow checking is easier
  5980. // if we increase `i` as we go, then subtract off its starting
  5981. // value at the end to obtain `delta`.
  5982. for (oldi = i, w = 1, k = base; /* no condition */; k += base) {
  5983. if (index >= inputLength) {
  5984. error('invalid-input');
  5985. }
  5986. digit = basicToDigit(input.charCodeAt(index++));
  5987. if (digit >= base || digit > floor((maxInt - i) / w)) {
  5988. error('overflow');
  5989. }
  5990. i += digit * w;
  5991. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  5992. if (digit < t) {
  5993. break;
  5994. }
  5995. baseMinusT = base - t;
  5996. if (w > floor(maxInt / baseMinusT)) {
  5997. error('overflow');
  5998. }
  5999. w *= baseMinusT;
  6000. }
  6001. out = output.length + 1;
  6002. bias = adapt(i - oldi, out, oldi == 0);
  6003. // `i` was supposed to wrap around from `out` to `0`,
  6004. // incrementing `n` each time, so we'll fix that now:
  6005. if (floor(i / out) > maxInt - n) {
  6006. error('overflow');
  6007. }
  6008. n += floor(i / out);
  6009. i %= out;
  6010. // Insert `n` at position `i` of the output
  6011. output.splice(i++, 0, n);
  6012. }
  6013. return ucs2encode(output);
  6014. }
  6015. /**
  6016. * Converts a string of Unicode symbols (e.g. a domain name label) to a
  6017. * Punycode string of ASCII-only symbols.
  6018. * @memberOf punycode
  6019. * @param {String} input The string of Unicode symbols.
  6020. * @returns {String} The resulting Punycode string of ASCII-only symbols.
  6021. */
  6022. function encode(input) {
  6023. var n,
  6024. delta,
  6025. handledCPCount,
  6026. basicLength,
  6027. bias,
  6028. j,
  6029. m,
  6030. q,
  6031. k,
  6032. t,
  6033. currentValue,
  6034. output = [],
  6035. /** `inputLength` will hold the number of code points in `input`. */
  6036. inputLength,
  6037. /** Cached calculation results */
  6038. handledCPCountPlusOne,
  6039. baseMinusT,
  6040. qMinusT;
  6041. // Convert the input in UCS-2 to Unicode
  6042. input = ucs2decode(input);
  6043. // Cache the length
  6044. inputLength = input.length;
  6045. // Initialize the state
  6046. n = initialN;
  6047. delta = 0;
  6048. bias = initialBias;
  6049. // Handle the basic code points
  6050. for (j = 0; j < inputLength; ++j) {
  6051. currentValue = input[j];
  6052. if (currentValue < 0x80) {
  6053. output.push(stringFromCharCode(currentValue));
  6054. }
  6055. }
  6056. handledCPCount = basicLength = output.length;
  6057. // `handledCPCount` is the number of code points that have been handled;
  6058. // `basicLength` is the number of basic code points.
  6059. // Finish the basic string - if it is not empty - with a delimiter
  6060. if (basicLength) {
  6061. output.push(delimiter);
  6062. }
  6063. // Main encoding loop:
  6064. while (handledCPCount < inputLength) {
  6065. // All non-basic code points < n have been handled already. Find the next
  6066. // larger one:
  6067. for (m = maxInt, j = 0; j < inputLength; ++j) {
  6068. currentValue = input[j];
  6069. if (currentValue >= n && currentValue < m) {
  6070. m = currentValue;
  6071. }
  6072. }
  6073. // Increase `delta` enough to advance the decoder's <n,i> state to <m,0>,
  6074. // but guard against overflow
  6075. handledCPCountPlusOne = handledCPCount + 1;
  6076. if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) {
  6077. error('overflow');
  6078. }
  6079. delta += (m - n) * handledCPCountPlusOne;
  6080. n = m;
  6081. for (j = 0; j < inputLength; ++j) {
  6082. currentValue = input[j];
  6083. if (currentValue < n && ++delta > maxInt) {
  6084. error('overflow');
  6085. }
  6086. if (currentValue == n) {
  6087. // Represent delta as a generalized variable-length integer
  6088. for (q = delta, k = base; /* no condition */; k += base) {
  6089. t = k <= bias ? tMin : (k >= bias + tMax ? tMax : k - bias);
  6090. if (q < t) {
  6091. break;
  6092. }
  6093. qMinusT = q - t;
  6094. baseMinusT = base - t;
  6095. output.push(
  6096. stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))
  6097. );
  6098. q = floor(qMinusT / baseMinusT);
  6099. }
  6100. output.push(stringFromCharCode(digitToBasic(q, 0)));
  6101. bias = adapt(delta, handledCPCountPlusOne, handledCPCount == basicLength);
  6102. delta = 0;
  6103. ++handledCPCount;
  6104. }
  6105. }
  6106. ++delta;
  6107. ++n;
  6108. }
  6109. return output.join('');
  6110. }
  6111. /**
  6112. * Converts a Punycode string representing a domain name or an email address
  6113. * to Unicode. Only the Punycoded parts of the input will be converted, i.e.
  6114. * it doesn't matter if you call it on a string that has already been
  6115. * converted to Unicode.
  6116. * @memberOf punycode
  6117. * @param {String} input The Punycoded domain name or email address to
  6118. * convert to Unicode.
  6119. * @returns {String} The Unicode representation of the given Punycode
  6120. * string.
  6121. */
  6122. function toUnicode(input) {
  6123. return mapDomain(input, function(string) {
  6124. return regexPunycode.test(string)
  6125. ? decode(string.slice(4).toLowerCase())
  6126. : string;
  6127. });
  6128. }
  6129. /**
  6130. * Converts a Unicode string representing a domain name or an email address to
  6131. * Punycode. Only the non-ASCII parts of the domain name will be converted,
  6132. * i.e. it doesn't matter if you call it with a domain that's already in
  6133. * ASCII.
  6134. * @memberOf punycode
  6135. * @param {String} input The domain name or email address to convert, as a
  6136. * Unicode string.
  6137. * @returns {String} The Punycode representation of the given domain name or
  6138. * email address.
  6139. */
  6140. function toASCII(input) {
  6141. return mapDomain(input, function(string) {
  6142. return regexNonASCII.test(string)
  6143. ? 'xn--' + encode(string)
  6144. : string;
  6145. });
  6146. }
  6147. /*--------------------------------------------------------------------------*/
  6148. /** Define the public API */
  6149. punycode = {
  6150. /**
  6151. * A string representing the current Punycode.js version number.
  6152. * @memberOf punycode
  6153. * @type String
  6154. */
  6155. 'version': '1.4.1',
  6156. /**
  6157. * An object of methods to convert from JavaScript's internal character
  6158. * representation (UCS-2) to Unicode code points, and back.
  6159. * @see <https://mathiasbynens.be/notes/javascript-encoding>
  6160. * @memberOf punycode
  6161. * @type Object
  6162. */
  6163. 'ucs2': {
  6164. 'decode': ucs2decode,
  6165. 'encode': ucs2encode
  6166. },
  6167. 'decode': decode,
  6168. 'encode': encode,
  6169. 'toASCII': toASCII,
  6170. 'toUnicode': toUnicode
  6171. };
  6172. /** Expose `punycode` */
  6173. // Some AMD build optimizers, like r.js, check for specific condition patterns
  6174. // like the following:
  6175. if (
  6176. typeof define == 'function' &&
  6177. typeof define.amd == 'object' &&
  6178. define.amd
  6179. ) {
  6180. define('punycode', function() {
  6181. return punycode;
  6182. });
  6183. } else if (freeExports && freeModule) {
  6184. if (module.exports == freeExports) {
  6185. // in Node.js, io.js, or RingoJS v0.8.0+
  6186. freeModule.exports = punycode;
  6187. } else {
  6188. // in Narwhal or RingoJS v0.7.0-
  6189. for (key in punycode) {
  6190. punycode.hasOwnProperty(key) && (freeExports[key] = punycode[key]);
  6191. }
  6192. }
  6193. } else {
  6194. // in Rhino or a web browser
  6195. root.punycode = punycode;
  6196. }
  6197. }(this));
  6198. }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
  6199. },{}],47:[function(require,module,exports){
  6200. // Copyright Joyent, Inc. and other Node contributors.
  6201. //
  6202. // Permission is hereby granted, free of charge, to any person obtaining a
  6203. // copy of this software and associated documentation files (the
  6204. // "Software"), to deal in the Software without restriction, including
  6205. // without limitation the rights to use, copy, modify, merge, publish,
  6206. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6207. // persons to whom the Software is furnished to do so, subject to the
  6208. // following conditions:
  6209. //
  6210. // The above copyright notice and this permission notice shall be included
  6211. // in all copies or substantial portions of the Software.
  6212. //
  6213. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6214. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6215. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6216. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6217. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6218. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6219. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6220. 'use strict';
  6221. // If obj.hasOwnProperty has been overridden, then calling
  6222. // obj.hasOwnProperty(prop) will break.
  6223. // See: https://github.com/joyent/node/issues/1707
  6224. function hasOwnProperty(obj, prop) {
  6225. return Object.prototype.hasOwnProperty.call(obj, prop);
  6226. }
  6227. module.exports = function(qs, sep, eq, options) {
  6228. sep = sep || '&';
  6229. eq = eq || '=';
  6230. var obj = {};
  6231. if (typeof qs !== 'string' || qs.length === 0) {
  6232. return obj;
  6233. }
  6234. var regexp = /\+/g;
  6235. qs = qs.split(sep);
  6236. var maxKeys = 1000;
  6237. if (options && typeof options.maxKeys === 'number') {
  6238. maxKeys = options.maxKeys;
  6239. }
  6240. var len = qs.length;
  6241. // maxKeys <= 0 means that we should not limit keys count
  6242. if (maxKeys > 0 && len > maxKeys) {
  6243. len = maxKeys;
  6244. }
  6245. for (var i = 0; i < len; ++i) {
  6246. var x = qs[i].replace(regexp, '%20'),
  6247. idx = x.indexOf(eq),
  6248. kstr, vstr, k, v;
  6249. if (idx >= 0) {
  6250. kstr = x.substr(0, idx);
  6251. vstr = x.substr(idx + 1);
  6252. } else {
  6253. kstr = x;
  6254. vstr = '';
  6255. }
  6256. k = decodeURIComponent(kstr);
  6257. v = decodeURIComponent(vstr);
  6258. if (!hasOwnProperty(obj, k)) {
  6259. obj[k] = v;
  6260. } else if (isArray(obj[k])) {
  6261. obj[k].push(v);
  6262. } else {
  6263. obj[k] = [obj[k], v];
  6264. }
  6265. }
  6266. return obj;
  6267. };
  6268. var isArray = Array.isArray || function (xs) {
  6269. return Object.prototype.toString.call(xs) === '[object Array]';
  6270. };
  6271. },{}],48:[function(require,module,exports){
  6272. // Copyright Joyent, Inc. and other Node contributors.
  6273. //
  6274. // Permission is hereby granted, free of charge, to any person obtaining a
  6275. // copy of this software and associated documentation files (the
  6276. // "Software"), to deal in the Software without restriction, including
  6277. // without limitation the rights to use, copy, modify, merge, publish,
  6278. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6279. // persons to whom the Software is furnished to do so, subject to the
  6280. // following conditions:
  6281. //
  6282. // The above copyright notice and this permission notice shall be included
  6283. // in all copies or substantial portions of the Software.
  6284. //
  6285. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6286. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6287. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6288. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6289. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6290. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6291. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6292. 'use strict';
  6293. var stringifyPrimitive = function(v) {
  6294. switch (typeof v) {
  6295. case 'string':
  6296. return v;
  6297. case 'boolean':
  6298. return v ? 'true' : 'false';
  6299. case 'number':
  6300. return isFinite(v) ? v : '';
  6301. default:
  6302. return '';
  6303. }
  6304. };
  6305. module.exports = function(obj, sep, eq, name) {
  6306. sep = sep || '&';
  6307. eq = eq || '=';
  6308. if (obj === null) {
  6309. obj = undefined;
  6310. }
  6311. if (typeof obj === 'object') {
  6312. return map(objectKeys(obj), function(k) {
  6313. var ks = encodeURIComponent(stringifyPrimitive(k)) + eq;
  6314. if (isArray(obj[k])) {
  6315. return map(obj[k], function(v) {
  6316. return ks + encodeURIComponent(stringifyPrimitive(v));
  6317. }).join(sep);
  6318. } else {
  6319. return ks + encodeURIComponent(stringifyPrimitive(obj[k]));
  6320. }
  6321. }).join(sep);
  6322. }
  6323. if (!name) return '';
  6324. return encodeURIComponent(stringifyPrimitive(name)) + eq +
  6325. encodeURIComponent(stringifyPrimitive(obj));
  6326. };
  6327. var isArray = Array.isArray || function (xs) {
  6328. return Object.prototype.toString.call(xs) === '[object Array]';
  6329. };
  6330. function map (xs, f) {
  6331. if (xs.map) return xs.map(f);
  6332. var res = [];
  6333. for (var i = 0; i < xs.length; i++) {
  6334. res.push(f(xs[i], i));
  6335. }
  6336. return res;
  6337. }
  6338. var objectKeys = Object.keys || function (obj) {
  6339. var res = [];
  6340. for (var key in obj) {
  6341. if (Object.prototype.hasOwnProperty.call(obj, key)) res.push(key);
  6342. }
  6343. return res;
  6344. };
  6345. },{}],49:[function(require,module,exports){
  6346. 'use strict';
  6347. exports.decode = exports.parse = require('./decode');
  6348. exports.encode = exports.stringify = require('./encode');
  6349. },{"./decode":47,"./encode":48}],50:[function(require,module,exports){
  6350. // Copyright Joyent, Inc. and other Node contributors.
  6351. //
  6352. // Permission is hereby granted, free of charge, to any person obtaining a
  6353. // copy of this software and associated documentation files (the
  6354. // "Software"), to deal in the Software without restriction, including
  6355. // without limitation the rights to use, copy, modify, merge, publish,
  6356. // distribute, sublicense, and/or sell copies of the Software, and to permit
  6357. // persons to whom the Software is furnished to do so, subject to the
  6358. // following conditions:
  6359. //
  6360. // The above copyright notice and this permission notice shall be included
  6361. // in all copies or substantial portions of the Software.
  6362. //
  6363. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  6364. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  6365. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  6366. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  6367. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  6368. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  6369. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  6370. 'use strict';
  6371. var punycode = require('punycode');
  6372. var util = require('./util');
  6373. exports.parse = urlParse;
  6374. exports.resolve = urlResolve;
  6375. exports.resolveObject = urlResolveObject;
  6376. exports.format = urlFormat;
  6377. exports.Url = Url;
  6378. function Url() {
  6379. this.protocol = null;
  6380. this.slashes = null;
  6381. this.auth = null;
  6382. this.host = null;
  6383. this.port = null;
  6384. this.hostname = null;
  6385. this.hash = null;
  6386. this.search = null;
  6387. this.query = null;
  6388. this.pathname = null;
  6389. this.path = null;
  6390. this.href = null;
  6391. }
  6392. // Reference: RFC 3986, RFC 1808, RFC 2396
  6393. // define these here so at least they only have to be
  6394. // compiled once on the first module load.
  6395. var protocolPattern = /^([a-z0-9.+-]+:)/i,
  6396. portPattern = /:[0-9]*$/,
  6397. // Special case for a simple path URL
  6398. simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,
  6399. // RFC 2396: characters reserved for delimiting URLs.
  6400. // We actually just auto-escape these.
  6401. delims = ['<', '>', '"', '`', ' ', '\r', '\n', '\t'],
  6402. // RFC 2396: characters not allowed for various reasons.
  6403. unwise = ['{', '}', '|', '\\', '^', '`'].concat(delims),
  6404. // Allowed by RFCs, but cause of XSS attacks. Always escape these.
  6405. autoEscape = ['\''].concat(unwise),
  6406. // Characters that are never ever allowed in a hostname.
  6407. // Note that any invalid chars are also handled, but these
  6408. // are the ones that are *expected* to be seen, so we fast-path
  6409. // them.
  6410. nonHostChars = ['%', '/', '?', ';', '#'].concat(autoEscape),
  6411. hostEndingChars = ['/', '?', '#'],
  6412. hostnameMaxLen = 255,
  6413. hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/,
  6414. hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/,
  6415. // protocols that can allow "unsafe" and "unwise" chars.
  6416. unsafeProtocol = {
  6417. 'javascript': true,
  6418. 'javascript:': true
  6419. },
  6420. // protocols that never have a hostname.
  6421. hostlessProtocol = {
  6422. 'javascript': true,
  6423. 'javascript:': true
  6424. },
  6425. // protocols that always contain a // bit.
  6426. slashedProtocol = {
  6427. 'http': true,
  6428. 'https': true,
  6429. 'ftp': true,
  6430. 'gopher': true,
  6431. 'file': true,
  6432. 'http:': true,
  6433. 'https:': true,
  6434. 'ftp:': true,
  6435. 'gopher:': true,
  6436. 'file:': true
  6437. },
  6438. querystring = require('querystring');
  6439. function urlParse(url, parseQueryString, slashesDenoteHost) {
  6440. if (url && util.isObject(url) && url instanceof Url) return url;
  6441. var u = new Url;
  6442. u.parse(url, parseQueryString, slashesDenoteHost);
  6443. return u;
  6444. }
  6445. Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) {
  6446. if (!util.isString(url)) {
  6447. throw new TypeError("Parameter 'url' must be a string, not " + typeof url);
  6448. }
  6449. // Copy chrome, IE, opera backslash-handling behavior.
  6450. // Back slashes before the query string get converted to forward slashes
  6451. // See: https://code.google.com/p/chromium/issues/detail?id=25916
  6452. var queryIndex = url.indexOf('?'),
  6453. splitter =
  6454. (queryIndex !== -1 && queryIndex < url.indexOf('#')) ? '?' : '#',
  6455. uSplit = url.split(splitter),
  6456. slashRegex = /\\/g;
  6457. uSplit[0] = uSplit[0].replace(slashRegex, '/');
  6458. url = uSplit.join(splitter);
  6459. var rest = url;
  6460. // trim before proceeding.
  6461. // This is to support parse stuff like " http://foo.com \n"
  6462. rest = rest.trim();
  6463. if (!slashesDenoteHost && url.split('#').length === 1) {
  6464. // Try fast path regexp
  6465. var simplePath = simplePathPattern.exec(rest);
  6466. if (simplePath) {
  6467. this.path = rest;
  6468. this.href = rest;
  6469. this.pathname = simplePath[1];
  6470. if (simplePath[2]) {
  6471. this.search = simplePath[2];
  6472. if (parseQueryString) {
  6473. this.query = querystring.parse(this.search.substr(1));
  6474. } else {
  6475. this.query = this.search.substr(1);
  6476. }
  6477. } else if (parseQueryString) {
  6478. this.search = '';
  6479. this.query = {};
  6480. }
  6481. return this;
  6482. }
  6483. }
  6484. var proto = protocolPattern.exec(rest);
  6485. if (proto) {
  6486. proto = proto[0];
  6487. var lowerProto = proto.toLowerCase();
  6488. this.protocol = lowerProto;
  6489. rest = rest.substr(proto.length);
  6490. }
  6491. // figure out if it's got a host
  6492. // user@server is *always* interpreted as a hostname, and url
  6493. // resolution will treat //foo/bar as host=foo,path=bar because that's
  6494. // how the browser resolves relative URLs.
  6495. if (slashesDenoteHost || proto || rest.match(/^\/\/[^@\/]+@[^@\/]+/)) {
  6496. var slashes = rest.substr(0, 2) === '//';
  6497. if (slashes && !(proto && hostlessProtocol[proto])) {
  6498. rest = rest.substr(2);
  6499. this.slashes = true;
  6500. }
  6501. }
  6502. if (!hostlessProtocol[proto] &&
  6503. (slashes || (proto && !slashedProtocol[proto]))) {
  6504. // there's a hostname.
  6505. // the first instance of /, ?, ;, or # ends the host.
  6506. //
  6507. // If there is an @ in the hostname, then non-host chars *are* allowed
  6508. // to the left of the last @ sign, unless some host-ending character
  6509. // comes *before* the @-sign.
  6510. // URLs are obnoxious.
  6511. //
  6512. // ex:
  6513. // http://a@b@c/ => user:a@b host:c
  6514. // http://a@b?@c => user:a host:c path:/?@c
  6515. // v0.12 TODO(isaacs): This is not quite how Chrome does things.
  6516. // Review our test case against browsers more comprehensively.
  6517. // find the first instance of any hostEndingChars
  6518. var hostEnd = -1;
  6519. for (var i = 0; i < hostEndingChars.length; i++) {
  6520. var hec = rest.indexOf(hostEndingChars[i]);
  6521. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  6522. hostEnd = hec;
  6523. }
  6524. // at this point, either we have an explicit point where the
  6525. // auth portion cannot go past, or the last @ char is the decider.
  6526. var auth, atSign;
  6527. if (hostEnd === -1) {
  6528. // atSign can be anywhere.
  6529. atSign = rest.lastIndexOf('@');
  6530. } else {
  6531. // atSign must be in auth portion.
  6532. // http://a@b/c@d => host:b auth:a path:/c@d
  6533. atSign = rest.lastIndexOf('@', hostEnd);
  6534. }
  6535. // Now we have a portion which is definitely the auth.
  6536. // Pull that off.
  6537. if (atSign !== -1) {
  6538. auth = rest.slice(0, atSign);
  6539. rest = rest.slice(atSign + 1);
  6540. this.auth = decodeURIComponent(auth);
  6541. }
  6542. // the host is the remaining to the left of the first non-host char
  6543. hostEnd = -1;
  6544. for (var i = 0; i < nonHostChars.length; i++) {
  6545. var hec = rest.indexOf(nonHostChars[i]);
  6546. if (hec !== -1 && (hostEnd === -1 || hec < hostEnd))
  6547. hostEnd = hec;
  6548. }
  6549. // if we still have not hit it, then the entire thing is a host.
  6550. if (hostEnd === -1)
  6551. hostEnd = rest.length;
  6552. this.host = rest.slice(0, hostEnd);
  6553. rest = rest.slice(hostEnd);
  6554. // pull out port.
  6555. this.parseHost();
  6556. // we've indicated that there is a hostname,
  6557. // so even if it's empty, it has to be present.
  6558. this.hostname = this.hostname || '';
  6559. // if hostname begins with [ and ends with ]
  6560. // assume that it's an IPv6 address.
  6561. var ipv6Hostname = this.hostname[0] === '[' &&
  6562. this.hostname[this.hostname.length - 1] === ']';
  6563. // validate a little.
  6564. if (!ipv6Hostname) {
  6565. var hostparts = this.hostname.split(/\./);
  6566. for (var i = 0, l = hostparts.length; i < l; i++) {
  6567. var part = hostparts[i];
  6568. if (!part) continue;
  6569. if (!part.match(hostnamePartPattern)) {
  6570. var newpart = '';
  6571. for (var j = 0, k = part.length; j < k; j++) {
  6572. if (part.charCodeAt(j) > 127) {
  6573. // we replace non-ASCII char with a temporary placeholder
  6574. // we need this to make sure size of hostname is not
  6575. // broken by replacing non-ASCII by nothing
  6576. newpart += 'x';
  6577. } else {
  6578. newpart += part[j];
  6579. }
  6580. }
  6581. // we test again with ASCII char only
  6582. if (!newpart.match(hostnamePartPattern)) {
  6583. var validParts = hostparts.slice(0, i);
  6584. var notHost = hostparts.slice(i + 1);
  6585. var bit = part.match(hostnamePartStart);
  6586. if (bit) {
  6587. validParts.push(bit[1]);
  6588. notHost.unshift(bit[2]);
  6589. }
  6590. if (notHost.length) {
  6591. rest = '/' + notHost.join('.') + rest;
  6592. }
  6593. this.hostname = validParts.join('.');
  6594. break;
  6595. }
  6596. }
  6597. }
  6598. }
  6599. if (this.hostname.length > hostnameMaxLen) {
  6600. this.hostname = '';
  6601. } else {
  6602. // hostnames are always lower case.
  6603. this.hostname = this.hostname.toLowerCase();
  6604. }
  6605. if (!ipv6Hostname) {
  6606. // IDNA Support: Returns a punycoded representation of "domain".
  6607. // It only converts parts of the domain name that
  6608. // have non-ASCII characters, i.e. it doesn't matter if
  6609. // you call it with a domain that already is ASCII-only.
  6610. this.hostname = punycode.toASCII(this.hostname);
  6611. }
  6612. var p = this.port ? ':' + this.port : '';
  6613. var h = this.hostname || '';
  6614. this.host = h + p;
  6615. this.href += this.host;
  6616. // strip [ and ] from the hostname
  6617. // the host field still retains them, though
  6618. if (ipv6Hostname) {
  6619. this.hostname = this.hostname.substr(1, this.hostname.length - 2);
  6620. if (rest[0] !== '/') {
  6621. rest = '/' + rest;
  6622. }
  6623. }
  6624. }
  6625. // now rest is set to the post-host stuff.
  6626. // chop off any delim chars.
  6627. if (!unsafeProtocol[lowerProto]) {
  6628. // First, make 100% sure that any "autoEscape" chars get
  6629. // escaped, even if encodeURIComponent doesn't think they
  6630. // need to be.
  6631. for (var i = 0, l = autoEscape.length; i < l; i++) {
  6632. var ae = autoEscape[i];
  6633. if (rest.indexOf(ae) === -1)
  6634. continue;
  6635. var esc = encodeURIComponent(ae);
  6636. if (esc === ae) {
  6637. esc = escape(ae);
  6638. }
  6639. rest = rest.split(ae).join(esc);
  6640. }
  6641. }
  6642. // chop off from the tail first.
  6643. var hash = rest.indexOf('#');
  6644. if (hash !== -1) {
  6645. // got a fragment string.
  6646. this.hash = rest.substr(hash);
  6647. rest = rest.slice(0, hash);
  6648. }
  6649. var qm = rest.indexOf('?');
  6650. if (qm !== -1) {
  6651. this.search = rest.substr(qm);
  6652. this.query = rest.substr(qm + 1);
  6653. if (parseQueryString) {
  6654. this.query = querystring.parse(this.query);
  6655. }
  6656. rest = rest.slice(0, qm);
  6657. } else if (parseQueryString) {
  6658. // no query string, but parseQueryString still requested
  6659. this.search = '';
  6660. this.query = {};
  6661. }
  6662. if (rest) this.pathname = rest;
  6663. if (slashedProtocol[lowerProto] &&
  6664. this.hostname && !this.pathname) {
  6665. this.pathname = '/';
  6666. }
  6667. //to support http.request
  6668. if (this.pathname || this.search) {
  6669. var p = this.pathname || '';
  6670. var s = this.search || '';
  6671. this.path = p + s;
  6672. }
  6673. // finally, reconstruct the href based on what has been validated.
  6674. this.href = this.format();
  6675. return this;
  6676. };
  6677. // format a parsed object into a url string
  6678. function urlFormat(obj) {
  6679. // ensure it's an object, and not a string url.
  6680. // If it's an obj, this is a no-op.
  6681. // this way, you can call url_format() on strings
  6682. // to clean up potentially wonky urls.
  6683. if (util.isString(obj)) obj = urlParse(obj);
  6684. if (!(obj instanceof Url)) return Url.prototype.format.call(obj);
  6685. return obj.format();
  6686. }
  6687. Url.prototype.format = function() {
  6688. var auth = this.auth || '';
  6689. if (auth) {
  6690. auth = encodeURIComponent(auth);
  6691. auth = auth.replace(/%3A/i, ':');
  6692. auth += '@';
  6693. }
  6694. var protocol = this.protocol || '',
  6695. pathname = this.pathname || '',
  6696. hash = this.hash || '',
  6697. host = false,
  6698. query = '';
  6699. if (this.host) {
  6700. host = auth + this.host;
  6701. } else if (this.hostname) {
  6702. host = auth + (this.hostname.indexOf(':') === -1 ?
  6703. this.hostname :
  6704. '[' + this.hostname + ']');
  6705. if (this.port) {
  6706. host += ':' + this.port;
  6707. }
  6708. }
  6709. if (this.query &&
  6710. util.isObject(this.query) &&
  6711. Object.keys(this.query).length) {
  6712. query = querystring.stringify(this.query);
  6713. }
  6714. var search = this.search || (query && ('?' + query)) || '';
  6715. if (protocol && protocol.substr(-1) !== ':') protocol += ':';
  6716. // only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
  6717. // unless they had them to begin with.
  6718. if (this.slashes ||
  6719. (!protocol || slashedProtocol[protocol]) && host !== false) {
  6720. host = '//' + (host || '');
  6721. if (pathname && pathname.charAt(0) !== '/') pathname = '/' + pathname;
  6722. } else if (!host) {
  6723. host = '';
  6724. }
  6725. if (hash && hash.charAt(0) !== '#') hash = '#' + hash;
  6726. if (search && search.charAt(0) !== '?') search = '?' + search;
  6727. pathname = pathname.replace(/[?#]/g, function(match) {
  6728. return encodeURIComponent(match);
  6729. });
  6730. search = search.replace('#', '%23');
  6731. return protocol + host + pathname + search + hash;
  6732. };
  6733. function urlResolve(source, relative) {
  6734. return urlParse(source, false, true).resolve(relative);
  6735. }
  6736. Url.prototype.resolve = function(relative) {
  6737. return this.resolveObject(urlParse(relative, false, true)).format();
  6738. };
  6739. function urlResolveObject(source, relative) {
  6740. if (!source) return relative;
  6741. return urlParse(source, false, true).resolveObject(relative);
  6742. }
  6743. Url.prototype.resolveObject = function(relative) {
  6744. if (util.isString(relative)) {
  6745. var rel = new Url();
  6746. rel.parse(relative, false, true);
  6747. relative = rel;
  6748. }
  6749. var result = new Url();
  6750. var tkeys = Object.keys(this);
  6751. for (var tk = 0; tk < tkeys.length; tk++) {
  6752. var tkey = tkeys[tk];
  6753. result[tkey] = this[tkey];
  6754. }
  6755. // hash is always overridden, no matter what.
  6756. // even href="" will remove it.
  6757. result.hash = relative.hash;
  6758. // if the relative url is empty, then there's nothing left to do here.
  6759. if (relative.href === '') {
  6760. result.href = result.format();
  6761. return result;
  6762. }
  6763. // hrefs like //foo/bar always cut to the protocol.
  6764. if (relative.slashes && !relative.protocol) {
  6765. // take everything except the protocol from relative
  6766. var rkeys = Object.keys(relative);
  6767. for (var rk = 0; rk < rkeys.length; rk++) {
  6768. var rkey = rkeys[rk];
  6769. if (rkey !== 'protocol')
  6770. result[rkey] = relative[rkey];
  6771. }
  6772. //urlParse appends trailing / to urls like http://www.example.com
  6773. if (slashedProtocol[result.protocol] &&
  6774. result.hostname && !result.pathname) {
  6775. result.path = result.pathname = '/';
  6776. }
  6777. result.href = result.format();
  6778. return result;
  6779. }
  6780. if (relative.protocol && relative.protocol !== result.protocol) {
  6781. // if it's a known url protocol, then changing
  6782. // the protocol does weird things
  6783. // first, if it's not file:, then we MUST have a host,
  6784. // and if there was a path
  6785. // to begin with, then we MUST have a path.
  6786. // if it is file:, then the host is dropped,
  6787. // because that's known to be hostless.
  6788. // anything else is assumed to be absolute.
  6789. if (!slashedProtocol[relative.protocol]) {
  6790. var keys = Object.keys(relative);
  6791. for (var v = 0; v < keys.length; v++) {
  6792. var k = keys[v];
  6793. result[k] = relative[k];
  6794. }
  6795. result.href = result.format();
  6796. return result;
  6797. }
  6798. result.protocol = relative.protocol;
  6799. if (!relative.host && !hostlessProtocol[relative.protocol]) {
  6800. var relPath = (relative.pathname || '').split('/');
  6801. while (relPath.length && !(relative.host = relPath.shift()));
  6802. if (!relative.host) relative.host = '';
  6803. if (!relative.hostname) relative.hostname = '';
  6804. if (relPath[0] !== '') relPath.unshift('');
  6805. if (relPath.length < 2) relPath.unshift('');
  6806. result.pathname = relPath.join('/');
  6807. } else {
  6808. result.pathname = relative.pathname;
  6809. }
  6810. result.search = relative.search;
  6811. result.query = relative.query;
  6812. result.host = relative.host || '';
  6813. result.auth = relative.auth;
  6814. result.hostname = relative.hostname || relative.host;
  6815. result.port = relative.port;
  6816. // to support http.request
  6817. if (result.pathname || result.search) {
  6818. var p = result.pathname || '';
  6819. var s = result.search || '';
  6820. result.path = p + s;
  6821. }
  6822. result.slashes = result.slashes || relative.slashes;
  6823. result.href = result.format();
  6824. return result;
  6825. }
  6826. var isSourceAbs = (result.pathname && result.pathname.charAt(0) === '/'),
  6827. isRelAbs = (
  6828. relative.host ||
  6829. relative.pathname && relative.pathname.charAt(0) === '/'
  6830. ),
  6831. mustEndAbs = (isRelAbs || isSourceAbs ||
  6832. (result.host && relative.pathname)),
  6833. removeAllDots = mustEndAbs,
  6834. srcPath = result.pathname && result.pathname.split('/') || [],
  6835. relPath = relative.pathname && relative.pathname.split('/') || [],
  6836. psychotic = result.protocol && !slashedProtocol[result.protocol];
  6837. // if the url is a non-slashed url, then relative
  6838. // links like ../.. should be able
  6839. // to crawl up to the hostname, as well. This is strange.
  6840. // result.protocol has already been set by now.
  6841. // Later on, put the first path part into the host field.
  6842. if (psychotic) {
  6843. result.hostname = '';
  6844. result.port = null;
  6845. if (result.host) {
  6846. if (srcPath[0] === '') srcPath[0] = result.host;
  6847. else srcPath.unshift(result.host);
  6848. }
  6849. result.host = '';
  6850. if (relative.protocol) {
  6851. relative.hostname = null;
  6852. relative.port = null;
  6853. if (relative.host) {
  6854. if (relPath[0] === '') relPath[0] = relative.host;
  6855. else relPath.unshift(relative.host);
  6856. }
  6857. relative.host = null;
  6858. }
  6859. mustEndAbs = mustEndAbs && (relPath[0] === '' || srcPath[0] === '');
  6860. }
  6861. if (isRelAbs) {
  6862. // it's absolute.
  6863. result.host = (relative.host || relative.host === '') ?
  6864. relative.host : result.host;
  6865. result.hostname = (relative.hostname || relative.hostname === '') ?
  6866. relative.hostname : result.hostname;
  6867. result.search = relative.search;
  6868. result.query = relative.query;
  6869. srcPath = relPath;
  6870. // fall through to the dot-handling below.
  6871. } else if (relPath.length) {
  6872. // it's relative
  6873. // throw away the existing file, and take the new path instead.
  6874. if (!srcPath) srcPath = [];
  6875. srcPath.pop();
  6876. srcPath = srcPath.concat(relPath);
  6877. result.search = relative.search;
  6878. result.query = relative.query;
  6879. } else if (!util.isNullOrUndefined(relative.search)) {
  6880. // just pull out the search.
  6881. // like href='?foo'.
  6882. // Put this after the other two cases because it simplifies the booleans
  6883. if (psychotic) {
  6884. result.hostname = result.host = srcPath.shift();
  6885. //occationaly the auth can get stuck only in host
  6886. //this especially happens in cases like
  6887. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  6888. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  6889. result.host.split('@') : false;
  6890. if (authInHost) {
  6891. result.auth = authInHost.shift();
  6892. result.host = result.hostname = authInHost.shift();
  6893. }
  6894. }
  6895. result.search = relative.search;
  6896. result.query = relative.query;
  6897. //to support http.request
  6898. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  6899. result.path = (result.pathname ? result.pathname : '') +
  6900. (result.search ? result.search : '');
  6901. }
  6902. result.href = result.format();
  6903. return result;
  6904. }
  6905. if (!srcPath.length) {
  6906. // no path at all. easy.
  6907. // we've already handled the other stuff above.
  6908. result.pathname = null;
  6909. //to support http.request
  6910. if (result.search) {
  6911. result.path = '/' + result.search;
  6912. } else {
  6913. result.path = null;
  6914. }
  6915. result.href = result.format();
  6916. return result;
  6917. }
  6918. // if a url ENDs in . or .., then it must get a trailing slash.
  6919. // however, if it ends in anything else non-slashy,
  6920. // then it must NOT get a trailing slash.
  6921. var last = srcPath.slice(-1)[0];
  6922. var hasTrailingSlash = (
  6923. (result.host || relative.host || srcPath.length > 1) &&
  6924. (last === '.' || last === '..') || last === '');
  6925. // strip single dots, resolve double dots to parent dir
  6926. // if the path tries to go above the root, `up` ends up > 0
  6927. var up = 0;
  6928. for (var i = srcPath.length; i >= 0; i--) {
  6929. last = srcPath[i];
  6930. if (last === '.') {
  6931. srcPath.splice(i, 1);
  6932. } else if (last === '..') {
  6933. srcPath.splice(i, 1);
  6934. up++;
  6935. } else if (up) {
  6936. srcPath.splice(i, 1);
  6937. up--;
  6938. }
  6939. }
  6940. // if the path is allowed to go above the root, restore leading ..s
  6941. if (!mustEndAbs && !removeAllDots) {
  6942. for (; up--; up) {
  6943. srcPath.unshift('..');
  6944. }
  6945. }
  6946. if (mustEndAbs && srcPath[0] !== '' &&
  6947. (!srcPath[0] || srcPath[0].charAt(0) !== '/')) {
  6948. srcPath.unshift('');
  6949. }
  6950. if (hasTrailingSlash && (srcPath.join('/').substr(-1) !== '/')) {
  6951. srcPath.push('');
  6952. }
  6953. var isAbsolute = srcPath[0] === '' ||
  6954. (srcPath[0] && srcPath[0].charAt(0) === '/');
  6955. // put the host back
  6956. if (psychotic) {
  6957. result.hostname = result.host = isAbsolute ? '' :
  6958. srcPath.length ? srcPath.shift() : '';
  6959. //occationaly the auth can get stuck only in host
  6960. //this especially happens in cases like
  6961. //url.resolveObject('mailto:local1@domain1', 'local2@domain2')
  6962. var authInHost = result.host && result.host.indexOf('@') > 0 ?
  6963. result.host.split('@') : false;
  6964. if (authInHost) {
  6965. result.auth = authInHost.shift();
  6966. result.host = result.hostname = authInHost.shift();
  6967. }
  6968. }
  6969. mustEndAbs = mustEndAbs || (result.host && srcPath.length);
  6970. if (mustEndAbs && !isAbsolute) {
  6971. srcPath.unshift('');
  6972. }
  6973. if (!srcPath.length) {
  6974. result.pathname = null;
  6975. result.path = null;
  6976. } else {
  6977. result.pathname = srcPath.join('/');
  6978. }
  6979. //to support request.http
  6980. if (!util.isNull(result.pathname) || !util.isNull(result.search)) {
  6981. result.path = (result.pathname ? result.pathname : '') +
  6982. (result.search ? result.search : '');
  6983. }
  6984. result.auth = relative.auth || result.auth;
  6985. result.slashes = result.slashes || relative.slashes;
  6986. result.href = result.format();
  6987. return result;
  6988. };
  6989. Url.prototype.parseHost = function() {
  6990. var host = this.host;
  6991. var port = portPattern.exec(host);
  6992. if (port) {
  6993. port = port[0];
  6994. if (port !== ':') {
  6995. this.port = port.substr(1);
  6996. }
  6997. host = host.substr(0, host.length - port.length);
  6998. }
  6999. if (host) this.hostname = host;
  7000. };
  7001. },{"./util":51,"punycode":46,"querystring":49}],51:[function(require,module,exports){
  7002. 'use strict';
  7003. module.exports = {
  7004. isString: function(arg) {
  7005. return typeof(arg) === 'string';
  7006. },
  7007. isObject: function(arg) {
  7008. return typeof(arg) === 'object' && arg !== null;
  7009. },
  7010. isNull: function(arg) {
  7011. return arg === null;
  7012. },
  7013. isNullOrUndefined: function(arg) {
  7014. return arg == null;
  7015. }
  7016. };
  7017. },{}],"ajv":[function(require,module,exports){
  7018. 'use strict';
  7019. var compileSchema = require('./compile')
  7020. , resolve = require('./compile/resolve')
  7021. , Cache = require('./cache')
  7022. , SchemaObject = require('./compile/schema_obj')
  7023. , stableStringify = require('json-stable-stringify')
  7024. , formats = require('./compile/formats')
  7025. , rules = require('./compile/rules')
  7026. , v5 = require('./v5')
  7027. , util = require('./compile/util')
  7028. , async = require('./async')
  7029. , co = require('co');
  7030. module.exports = Ajv;
  7031. Ajv.prototype.compileAsync = async.compile;
  7032. var customKeyword = require('./keyword');
  7033. Ajv.prototype.addKeyword = customKeyword.add;
  7034. Ajv.prototype.getKeyword = customKeyword.get;
  7035. Ajv.prototype.removeKeyword = customKeyword.remove;
  7036. Ajv.ValidationError = require('./compile/validation_error');
  7037. var META_SCHEMA_ID = 'http://json-schema.org/draft-04/schema';
  7038. var SCHEMA_URI_FORMAT = /^(?:(?:[a-z][a-z0-9+-.]*:)?\/\/)?[^\s]*$/i;
  7039. function SCHEMA_URI_FORMAT_FUNC(str) {
  7040. return SCHEMA_URI_FORMAT.test(str);
  7041. }
  7042. var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ];
  7043. /**
  7044. * Creates validator instance.
  7045. * Usage: `Ajv(opts)`
  7046. * @param {Object} opts optional options
  7047. * @return {Object} ajv instance
  7048. */
  7049. function Ajv(opts) {
  7050. if (!(this instanceof Ajv)) return new Ajv(opts);
  7051. var self = this;
  7052. opts = this._opts = util.copy(opts) || {};
  7053. this._schemas = {};
  7054. this._refs = {};
  7055. this._fragments = {};
  7056. this._formats = formats(opts.format);
  7057. this._cache = opts.cache || new Cache;
  7058. this._loadingSchemas = {};
  7059. this._compilations = [];
  7060. this.RULES = rules();
  7061. // this is done on purpose, so that methods are bound to the instance
  7062. // (without using bind) so that they can be used without the instance
  7063. this.validate = validate;
  7064. this.compile = compile;
  7065. this.addSchema = addSchema;
  7066. this.addMetaSchema = addMetaSchema;
  7067. this.validateSchema = validateSchema;
  7068. this.getSchema = getSchema;
  7069. this.removeSchema = removeSchema;
  7070. this.addFormat = addFormat;
  7071. this.errorsText = errorsText;
  7072. this._addSchema = _addSchema;
  7073. this._compile = _compile;
  7074. opts.loopRequired = opts.loopRequired || Infinity;
  7075. if (opts.async || opts.transpile) async.setup(opts);
  7076. if (opts.beautify === true) opts.beautify = { indent_size: 2 };
  7077. if (opts.errorDataPath == 'property') opts._errorDataPathProperty = true;
  7078. this._metaOpts = getMetaSchemaOptions();
  7079. if (opts.formats) addInitialFormats();
  7080. addDraft4MetaSchema();
  7081. if (opts.v5) v5.enable(this);
  7082. if (typeof opts.meta == 'object') addMetaSchema(opts.meta);
  7083. addInitialSchemas();
  7084. /**
  7085. * Validate data using schema
  7086. * Schema will be compiled and cached (using serialized JSON as key. [json-stable-stringify](https://github.com/substack/json-stable-stringify) is used to serialize.
  7087. * @param {String|Object} schemaKeyRef key, ref or schema object
  7088. * @param {Any} data to be validated
  7089. * @return {Boolean} validation result. Errors from the last validation will be available in `ajv.errors` (and also in compiled schema: `schema.errors`).
  7090. */
  7091. function validate(schemaKeyRef, data) {
  7092. var v;
  7093. if (typeof schemaKeyRef == 'string') {
  7094. v = getSchema(schemaKeyRef);
  7095. if (!v) throw new Error('no schema with key or ref "' + schemaKeyRef + '"');
  7096. } else {
  7097. var schemaObj = _addSchema(schemaKeyRef);
  7098. v = schemaObj.validate || _compile(schemaObj);
  7099. }
  7100. var valid = v(data);
  7101. if (v.$async === true)
  7102. return self._opts.async == '*' ? co(valid) : valid;
  7103. self.errors = v.errors;
  7104. return valid;
  7105. }
  7106. /**
  7107. * Create validating function for passed schema.
  7108. * @param {Object} schema schema object
  7109. * @param {Boolean} _meta true if schema is a meta-schema. Used internally to compile meta schemas of custom keywords.
  7110. * @return {Function} validating function
  7111. */
  7112. function compile(schema, _meta) {
  7113. var schemaObj = _addSchema(schema, undefined, _meta);
  7114. return schemaObj.validate || _compile(schemaObj);
  7115. }
  7116. /**
  7117. * Adds schema to the instance.
  7118. * @param {Object|Array} schema schema or array of schemas. If array is passed, `key` and other parameters will be ignored.
  7119. * @param {String} key Optional schema key. Can be passed to `validate` method instead of schema object or id/ref. One schema per instance can have empty `id` and `key`.
  7120. * @param {Boolean} _skipValidation true to skip schema validation. Used internally, option validateSchema should be used instead.
  7121. * @param {Boolean} _meta true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
  7122. */
  7123. function addSchema(schema, key, _skipValidation, _meta) {
  7124. if (Array.isArray(schema)){
  7125. for (var i=0; i<schema.length; i++) addSchema(schema[i], undefined, _skipValidation, _meta);
  7126. return;
  7127. }
  7128. // can key/id have # inside?
  7129. key = resolve.normalizeId(key || schema.id);
  7130. checkUnique(key);
  7131. self._schemas[key] = _addSchema(schema, _skipValidation, _meta, true);
  7132. }
  7133. /**
  7134. * Add schema that will be used to validate other schemas
  7135. * options in META_IGNORE_OPTIONS are alway set to false
  7136. * @param {Object} schema schema object
  7137. * @param {String} key optional schema key
  7138. * @param {Boolean} skipValidation true to skip schema validation, can be used to override validateSchema option for meta-schema
  7139. */
  7140. function addMetaSchema(schema, key, skipValidation) {
  7141. addSchema(schema, key, skipValidation, true);
  7142. }
  7143. /**
  7144. * Validate schema
  7145. * @param {Object} schema schema to validate
  7146. * @param {Boolean} throwOrLogError pass true to throw (or log) an error if invalid
  7147. * @return {Boolean} true if schema is valid
  7148. */
  7149. function validateSchema(schema, throwOrLogError) {
  7150. var $schema = schema.$schema || self._opts.defaultMeta || defaultMeta();
  7151. var currentUriFormat = self._formats.uri;
  7152. self._formats.uri = typeof currentUriFormat == 'function'
  7153. ? SCHEMA_URI_FORMAT_FUNC
  7154. : SCHEMA_URI_FORMAT;
  7155. var valid;
  7156. try { valid = validate($schema, schema); }
  7157. finally { self._formats.uri = currentUriFormat; }
  7158. if (!valid && throwOrLogError) {
  7159. var message = 'schema is invalid: ' + errorsText();
  7160. if (self._opts.validateSchema == 'log') console.error(message);
  7161. else throw new Error(message);
  7162. }
  7163. return valid;
  7164. }
  7165. function defaultMeta() {
  7166. var meta = self._opts.meta;
  7167. self._opts.defaultMeta = typeof meta == 'object'
  7168. ? meta.id || meta
  7169. : self._opts.v5
  7170. ? v5.META_SCHEMA_ID
  7171. : META_SCHEMA_ID;
  7172. return self._opts.defaultMeta;
  7173. }
  7174. /**
  7175. * Get compiled schema from the instance by `key` or `ref`.
  7176. * @param {String} keyRef `key` that was passed to `addSchema` or full schema reference (`schema.id` or resolved id).
  7177. * @return {Function} schema validating function (with property `schema`).
  7178. */
  7179. function getSchema(keyRef) {
  7180. var schemaObj = _getSchemaObj(keyRef);
  7181. switch (typeof schemaObj) {
  7182. case 'object': return schemaObj.validate || _compile(schemaObj);
  7183. case 'string': return getSchema(schemaObj);
  7184. case 'undefined': return _getSchemaFragment(keyRef);
  7185. }
  7186. }
  7187. function _getSchemaFragment(ref) {
  7188. var res = resolve.schema.call(self, { schema: {} }, ref);
  7189. if (res) {
  7190. var schema = res.schema
  7191. , root = res.root
  7192. , baseId = res.baseId;
  7193. var v = compileSchema.call(self, schema, root, undefined, baseId);
  7194. self._fragments[ref] = new SchemaObject({
  7195. ref: ref,
  7196. fragment: true,
  7197. schema: schema,
  7198. root: root,
  7199. baseId: baseId,
  7200. validate: v
  7201. });
  7202. return v;
  7203. }
  7204. }
  7205. function _getSchemaObj(keyRef) {
  7206. keyRef = resolve.normalizeId(keyRef);
  7207. return self._schemas[keyRef] || self._refs[keyRef] || self._fragments[keyRef];
  7208. }
  7209. /**
  7210. * Remove cached schema(s).
  7211. * If no parameter is passed all schemas but meta-schemas are removed.
  7212. * If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
  7213. * Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
  7214. * @param {String|Object|RegExp} schemaKeyRef key, ref, pattern to match key/ref or schema object
  7215. */
  7216. function removeSchema(schemaKeyRef) {
  7217. if (schemaKeyRef instanceof RegExp) {
  7218. _removeAllSchemas(self._schemas, schemaKeyRef);
  7219. _removeAllSchemas(self._refs, schemaKeyRef);
  7220. return;
  7221. }
  7222. switch (typeof schemaKeyRef) {
  7223. case 'undefined':
  7224. _removeAllSchemas(self._schemas);
  7225. _removeAllSchemas(self._refs);
  7226. self._cache.clear();
  7227. return;
  7228. case 'string':
  7229. var schemaObj = _getSchemaObj(schemaKeyRef);
  7230. if (schemaObj) self._cache.del(schemaObj.jsonStr);
  7231. delete self._schemas[schemaKeyRef];
  7232. delete self._refs[schemaKeyRef];
  7233. return;
  7234. case 'object':
  7235. var jsonStr = stableStringify(schemaKeyRef);
  7236. self._cache.del(jsonStr);
  7237. var id = schemaKeyRef.id;
  7238. if (id) {
  7239. id = resolve.normalizeId(id);
  7240. delete self._schemas[id];
  7241. delete self._refs[id];
  7242. }
  7243. }
  7244. }
  7245. function _removeAllSchemas(schemas, regex) {
  7246. for (var keyRef in schemas) {
  7247. var schemaObj = schemas[keyRef];
  7248. if (!schemaObj.meta && (!regex || regex.test(keyRef))) {
  7249. self._cache.del(schemaObj.jsonStr);
  7250. delete schemas[keyRef];
  7251. }
  7252. }
  7253. }
  7254. function _addSchema(schema, skipValidation, meta, shouldAddSchema) {
  7255. if (typeof schema != 'object') throw new Error('schema should be object');
  7256. var jsonStr = stableStringify(schema);
  7257. var cached = self._cache.get(jsonStr);
  7258. if (cached) return cached;
  7259. shouldAddSchema = shouldAddSchema || self._opts.addUsedSchema !== false;
  7260. var id = resolve.normalizeId(schema.id);
  7261. if (id && shouldAddSchema) checkUnique(id);
  7262. var willValidate = self._opts.validateSchema !== false && !skipValidation;
  7263. var recursiveMeta;
  7264. if (willValidate && !(recursiveMeta = schema.id && schema.id == schema.$schema))
  7265. validateSchema(schema, true);
  7266. var localRefs = resolve.ids.call(self, schema);
  7267. var schemaObj = new SchemaObject({
  7268. id: id,
  7269. schema: schema,
  7270. localRefs: localRefs,
  7271. jsonStr: jsonStr,
  7272. meta: meta
  7273. });
  7274. if (id[0] != '#' && shouldAddSchema) self._refs[id] = schemaObj;
  7275. self._cache.put(jsonStr, schemaObj);
  7276. if (willValidate && recursiveMeta) validateSchema(schema, true);
  7277. return schemaObj;
  7278. }
  7279. function _compile(schemaObj, root) {
  7280. if (schemaObj.compiling) {
  7281. schemaObj.validate = callValidate;
  7282. callValidate.schema = schemaObj.schema;
  7283. callValidate.errors = null;
  7284. callValidate.root = root ? root : callValidate;
  7285. if (schemaObj.schema.$async === true)
  7286. callValidate.$async = true;
  7287. return callValidate;
  7288. }
  7289. schemaObj.compiling = true;
  7290. var currentOpts;
  7291. if (schemaObj.meta) {
  7292. currentOpts = self._opts;
  7293. self._opts = self._metaOpts;
  7294. }
  7295. var v;
  7296. try { v = compileSchema.call(self, schemaObj.schema, root, schemaObj.localRefs); }
  7297. finally {
  7298. schemaObj.compiling = false;
  7299. if (schemaObj.meta) self._opts = currentOpts;
  7300. }
  7301. schemaObj.validate = v;
  7302. schemaObj.refs = v.refs;
  7303. schemaObj.refVal = v.refVal;
  7304. schemaObj.root = v.root;
  7305. return v;
  7306. function callValidate() {
  7307. var _validate = schemaObj.validate;
  7308. var result = _validate.apply(null, arguments);
  7309. callValidate.errors = _validate.errors;
  7310. return result;
  7311. }
  7312. }
  7313. /**
  7314. * Convert array of error message objects to string
  7315. * @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
  7316. * @param {Object} options optional options with properties `separator` and `dataVar`.
  7317. * @return {String} human readable string with all errors descriptions
  7318. */
  7319. function errorsText(errors, options) {
  7320. errors = errors || self.errors;
  7321. if (!errors) return 'No errors';
  7322. options = options || {};
  7323. var separator = options.separator === undefined ? ', ' : options.separator;
  7324. var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
  7325. var text = '';
  7326. for (var i=0; i<errors.length; i++) {
  7327. var e = errors[i];
  7328. if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
  7329. }
  7330. return text.slice(0, -separator.length);
  7331. }
  7332. /**
  7333. * Add custom format
  7334. * @param {String} name format name
  7335. * @param {String|RegExp|Function} format string is converted to RegExp; function should return boolean (true when valid)
  7336. */
  7337. function addFormat(name, format) {
  7338. if (typeof format == 'string') format = new RegExp(format);
  7339. self._formats[name] = format;
  7340. }
  7341. function addDraft4MetaSchema() {
  7342. if (self._opts.meta !== false) {
  7343. var metaSchema = require('./refs/json-schema-draft-04.json');
  7344. addMetaSchema(metaSchema, META_SCHEMA_ID, true);
  7345. self._refs['http://json-schema.org/schema'] = META_SCHEMA_ID;
  7346. }
  7347. }
  7348. function addInitialSchemas() {
  7349. var optsSchemas = self._opts.schemas;
  7350. if (!optsSchemas) return;
  7351. if (Array.isArray(optsSchemas)) addSchema(optsSchemas);
  7352. else for (var key in optsSchemas) addSchema(optsSchemas[key], key);
  7353. }
  7354. function addInitialFormats() {
  7355. for (var name in self._opts.formats) {
  7356. var format = self._opts.formats[name];
  7357. addFormat(name, format);
  7358. }
  7359. }
  7360. function checkUnique(id) {
  7361. if (self._schemas[id] || self._refs[id])
  7362. throw new Error('schema with key or id "' + id + '" already exists');
  7363. }
  7364. function getMetaSchemaOptions() {
  7365. var metaOpts = util.copy(self._opts);
  7366. for (var i=0; i<META_IGNORE_OPTIONS.length; i++)
  7367. delete metaOpts[META_IGNORE_OPTIONS[i]];
  7368. return metaOpts;
  7369. }
  7370. }
  7371. },{"./async":1,"./cache":2,"./compile":6,"./compile/formats":5,"./compile/resolve":7,"./compile/rules":8,"./compile/schema_obj":9,"./compile/util":11,"./compile/validation_error":12,"./keyword":37,"./refs/json-schema-draft-04.json":38,"./v5":40,"co":41,"json-stable-stringify":42}]},{},[])("ajv")
  7372. });