Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ajv.bundle.js 259KB

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