a zip code crypto-currency system good for red ONLY

ajv.bundle.js 255KB

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