Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

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