index.js 200 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1609944441816, function(require, module, exports) {
  8. Object.defineProperty(exports, "__esModule", { value: true });
  9. exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
  10. const context_1 = require("./compile/context");
  11. exports.KeywordCxt = context_1.default;
  12. var codegen_1 = require("./compile/codegen");
  13. Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
  14. Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
  15. Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
  16. Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
  17. Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
  18. Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
  19. const core_1 = require("./core");
  20. const draft7_1 = require("./vocabularies/draft7");
  21. const draft7MetaSchema = require("./refs/json-schema-draft-07.json");
  22. const META_SUPPORT_DATA = ["/properties"];
  23. const META_SCHEMA_ID = "http://json-schema.org/draft-07/schema";
  24. class Ajv extends core_1.default {
  25. _addVocabularies() {
  26. super._addVocabularies();
  27. draft7_1.default.forEach((v) => this.addVocabulary(v));
  28. }
  29. _addDefaultMetaSchema() {
  30. super._addDefaultMetaSchema();
  31. const { $data, meta } = this.opts;
  32. if (!meta)
  33. return;
  34. const metaSchema = $data
  35. ? this.$dataMetaSchema(draft7MetaSchema, META_SUPPORT_DATA)
  36. : draft7MetaSchema;
  37. this.addMetaSchema(metaSchema, META_SCHEMA_ID, false);
  38. this.refs["http://json-schema.org/schema"] = META_SCHEMA_ID;
  39. }
  40. defaultMeta() {
  41. return (this.opts.defaultMeta =
  42. super.defaultMeta() || (this.getSchema(META_SCHEMA_ID) ? META_SCHEMA_ID : undefined));
  43. }
  44. }
  45. exports.default = Ajv;
  46. //# sourceMappingURL=ajv.js.map
  47. }, function(modId) {var map = {"./compile/context":1609944441817,"./compile/codegen":1609944441822,"./core":1609944441835,"./vocabularies/draft7":1609944441839,"./refs/json-schema-draft-07.json":1609944441873}; return __REQUIRE__(map[modId], modId); })
  48. __DEFINE__(1609944441817, function(require, module, exports) {
  49. Object.defineProperty(exports, "__esModule", { value: true });
  50. exports.getData = void 0;
  51. const dataType_1 = require("./validate/dataType");
  52. const util_1 = require("./util");
  53. const errors_1 = require("./errors");
  54. const codegen_1 = require("./codegen");
  55. const names_1 = require("./names");
  56. const subschema_1 = require("./subschema");
  57. class KeywordCxt {
  58. constructor(it, def, keyword) {
  59. validateKeywordUsage(it, def, keyword);
  60. this.gen = it.gen;
  61. this.allErrors = it.allErrors;
  62. this.keyword = keyword;
  63. this.data = it.data;
  64. this.schema = it.schema[keyword];
  65. this.$data = def.$data && it.opts.$data && this.schema && this.schema.$data;
  66. this.schemaValue = util_1.schemaRefOrVal(it, this.schema, keyword, this.$data);
  67. this.schemaType = def.schemaType;
  68. this.parentSchema = it.schema;
  69. this.params = {};
  70. this.it = it;
  71. this.def = def;
  72. if (this.$data) {
  73. this.schemaCode = it.gen.const("vSchema", getData(this.$data, it));
  74. }
  75. else {
  76. this.schemaCode = this.schemaValue;
  77. if (!validSchemaType(this.schema, def.schemaType, def.allowUndefined)) {
  78. throw new Error(`${keyword} value must be ${JSON.stringify(def.schemaType)}`);
  79. }
  80. }
  81. if ("code" in def ? def.trackErrors : def.errors !== false) {
  82. this.errsCount = it.gen.const("_errs", names_1.default.errors);
  83. }
  84. }
  85. result(condition, successAction, failAction) {
  86. this.gen.if(codegen_1.not(condition));
  87. if (failAction)
  88. failAction();
  89. else
  90. this.error();
  91. if (successAction) {
  92. this.gen.else();
  93. successAction();
  94. if (this.allErrors)
  95. this.gen.endIf();
  96. }
  97. else {
  98. if (this.allErrors)
  99. this.gen.endIf();
  100. else
  101. this.gen.else();
  102. }
  103. }
  104. pass(condition, failAction) {
  105. this.result(condition, undefined, failAction);
  106. }
  107. fail(condition) {
  108. if (condition === undefined) {
  109. this.error();
  110. if (!this.allErrors)
  111. this.gen.if(false); // this branch will be removed by gen.optimize
  112. return;
  113. }
  114. this.gen.if(condition);
  115. this.error();
  116. if (this.allErrors)
  117. this.gen.endIf();
  118. else
  119. this.gen.else();
  120. }
  121. fail$data(condition) {
  122. if (!this.$data)
  123. return this.fail(condition);
  124. const { schemaCode } = this;
  125. this.fail(codegen_1._ `${schemaCode} !== undefined && (${codegen_1.or(this.invalid$data(), condition)})`);
  126. }
  127. error(append) {
  128. ;
  129. (append ? errors_1.reportExtraError : errors_1.reportError)(this, this.def.error || errors_1.keywordError);
  130. }
  131. $dataError() {
  132. errors_1.reportError(this, this.def.$dataError || errors_1.keyword$DataError);
  133. }
  134. reset() {
  135. if (this.errsCount === undefined)
  136. throw new Error('add "trackErrors" to keyword definition');
  137. errors_1.resetErrorsCount(this.gen, this.errsCount);
  138. }
  139. ok(cond) {
  140. if (!this.allErrors)
  141. this.gen.if(cond);
  142. }
  143. setParams(obj, assign) {
  144. if (assign)
  145. Object.assign(this.params, obj);
  146. else
  147. this.params = obj;
  148. }
  149. block$data(valid, codeBlock, $dataValid = codegen_1.nil) {
  150. this.gen.block(() => {
  151. this.check$data(valid, $dataValid);
  152. codeBlock();
  153. });
  154. }
  155. check$data(valid = codegen_1.nil, $dataValid = codegen_1.nil) {
  156. if (!this.$data)
  157. return;
  158. const { gen, schemaCode, schemaType, def } = this;
  159. gen.if(codegen_1.or(codegen_1._ `${schemaCode} === undefined`, $dataValid));
  160. if (valid !== codegen_1.nil)
  161. gen.assign(valid, true);
  162. if (schemaType.length || def.validateSchema) {
  163. gen.elseIf(this.invalid$data());
  164. this.$dataError();
  165. if (valid !== codegen_1.nil)
  166. gen.assign(valid, false);
  167. }
  168. gen.else();
  169. }
  170. invalid$data() {
  171. const { gen, schemaCode, schemaType, def, it } = this;
  172. return codegen_1.or(wrong$DataType(), invalid$DataSchema());
  173. function wrong$DataType() {
  174. if (schemaType.length) {
  175. /* istanbul ignore if */
  176. if (!(schemaCode instanceof codegen_1.Name))
  177. throw new Error("ajv implementation error");
  178. const st = Array.isArray(schemaType) ? schemaType : [schemaType];
  179. return codegen_1._ `${dataType_1.checkDataTypes(st, schemaCode, it.opts.strict, dataType_1.DataType.Wrong)}`;
  180. }
  181. return codegen_1.nil;
  182. }
  183. function invalid$DataSchema() {
  184. if (def.validateSchema) {
  185. const validateSchemaRef = gen.scopeValue("validate$data", { ref: def.validateSchema }); // TODO value.code for standalone
  186. return codegen_1._ `!${validateSchemaRef}(${schemaCode})`;
  187. }
  188. return codegen_1.nil;
  189. }
  190. }
  191. subschema(appl, valid) {
  192. return subschema_1.applySubschema(this.it, appl, valid);
  193. }
  194. mergeEvaluated(schemaCxt, toName) {
  195. const { it, gen } = this;
  196. if (!it.opts.unevaluated)
  197. return;
  198. if (it.props !== true && schemaCxt.props !== undefined) {
  199. it.props = util_1.mergeEvaluated.props(gen, schemaCxt.props, it.props, toName);
  200. }
  201. if (it.items !== true && schemaCxt.items !== undefined) {
  202. it.items = util_1.mergeEvaluated.items(gen, schemaCxt.items, it.items, toName);
  203. }
  204. }
  205. mergeValidEvaluated(schemaCxt, valid) {
  206. const { it, gen } = this;
  207. if (it.opts.unevaluated && (it.props !== true || it.items !== true)) {
  208. gen.if(valid, () => this.mergeEvaluated(schemaCxt, codegen_1.Name));
  209. return true;
  210. }
  211. }
  212. }
  213. exports.default = KeywordCxt;
  214. function validSchemaType(schema, schemaType, allowUndefined = false) {
  215. // TODO add tests
  216. return (!schemaType.length ||
  217. schemaType.some((st) => st === "array"
  218. ? Array.isArray(schema)
  219. : st === "object"
  220. ? schema && typeof schema == "object" && !Array.isArray(schema)
  221. : typeof schema == st || (allowUndefined && typeof schema == "undefined")));
  222. }
  223. function validateKeywordUsage({ schema, opts, self }, def, keyword) {
  224. /* istanbul ignore if */
  225. if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) {
  226. throw new Error("ajv implementation error");
  227. }
  228. const deps = def.dependencies;
  229. if (deps === null || deps === void 0 ? void 0 : deps.some((kwd) => !Object.prototype.hasOwnProperty.call(schema, kwd))) {
  230. throw new Error(`parent schema must have dependencies of ${keyword}: ${deps.join(",")}`);
  231. }
  232. if (def.validateSchema) {
  233. const valid = def.validateSchema(schema[keyword]);
  234. if (!valid) {
  235. const msg = "keyword value is invalid: " + self.errorsText(def.validateSchema.errors);
  236. if (opts.validateSchema === "log")
  237. self.logger.error(msg);
  238. else
  239. throw new Error(msg);
  240. }
  241. }
  242. }
  243. const JSON_POINTER = /^\/(?:[^~]|~0|~1)*$/;
  244. const RELATIVE_JSON_POINTER = /^([0-9]+)(#|\/(?:[^~]|~0|~1)*)?$/;
  245. function getData($data, { dataLevel, dataNames, dataPathArr }) {
  246. let jsonPointer;
  247. let data;
  248. if ($data === "")
  249. return names_1.default.rootData;
  250. if ($data[0] === "/") {
  251. if (!JSON_POINTER.test($data))
  252. throw new Error(`Invalid JSON-pointer: ${$data}`);
  253. jsonPointer = $data;
  254. data = names_1.default.rootData;
  255. }
  256. else {
  257. const matches = RELATIVE_JSON_POINTER.exec($data);
  258. if (!matches)
  259. throw new Error(`Invalid JSON-pointer: ${$data}`);
  260. const up = +matches[1];
  261. jsonPointer = matches[2];
  262. if (jsonPointer === "#") {
  263. if (up >= dataLevel)
  264. throw new Error(errorMsg("property/index", up));
  265. return dataPathArr[dataLevel - up];
  266. }
  267. if (up > dataLevel)
  268. throw new Error(errorMsg("data", up));
  269. data = dataNames[dataLevel - up];
  270. if (!jsonPointer)
  271. return data;
  272. }
  273. let expr = data;
  274. const segments = jsonPointer.split("/");
  275. for (const segment of segments) {
  276. if (segment) {
  277. data = codegen_1._ `${data}${codegen_1.getProperty(util_1.unescapeJsonPointer(segment))}`;
  278. expr = codegen_1._ `${expr} && ${data}`;
  279. }
  280. }
  281. return expr;
  282. function errorMsg(pointerType, up) {
  283. return `Cannot access ${pointerType} ${up} levels up, current level is ${dataLevel}`;
  284. }
  285. }
  286. exports.getData = getData;
  287. //# sourceMappingURL=context.js.map
  288. }, function(modId) { var map = {"./validate/dataType":1609944441818,"./util":1609944441826,"./errors":1609944441821,"./codegen":1609944441822,"./names":1609944441825,"./subschema":1609944441834}; return __REQUIRE__(map[modId], modId); })
  289. __DEFINE__(1609944441818, function(require, module, exports) {
  290. Object.defineProperty(exports, "__esModule", { value: true });
  291. exports.reportTypeError = exports.checkDataTypes = exports.checkDataType = exports.coerceAndCheckDataType = exports.getJSONTypes = exports.getSchemaTypes = exports.DataType = void 0;
  292. const rules_1 = require("../rules");
  293. const applicability_1 = require("./applicability");
  294. const errors_1 = require("../errors");
  295. const codegen_1 = require("../codegen");
  296. const util_1 = require("../util");
  297. var DataType;
  298. (function (DataType) {
  299. DataType[DataType["Correct"] = 0] = "Correct";
  300. DataType[DataType["Wrong"] = 1] = "Wrong";
  301. })(DataType = exports.DataType || (exports.DataType = {}));
  302. function getSchemaTypes(schema) {
  303. const types = getJSONTypes(schema.type);
  304. const hasNull = types.includes("null");
  305. if (hasNull) {
  306. if (schema.nullable === false)
  307. throw new Error("type: null contradicts nullable: false");
  308. }
  309. else {
  310. if (!types.length && schema.nullable !== undefined) {
  311. throw new Error('"nullable" cannot be used without "type"');
  312. }
  313. if (schema.nullable === true)
  314. types.push("null");
  315. }
  316. return types;
  317. }
  318. exports.getSchemaTypes = getSchemaTypes;
  319. function getJSONTypes(ts) {
  320. const types = Array.isArray(ts) ? ts : ts ? [ts] : [];
  321. if (types.every(rules_1.isJSONType))
  322. return types;
  323. throw new Error("type must be JSONType or JSONType[]: " + types.join(","));
  324. }
  325. exports.getJSONTypes = getJSONTypes;
  326. function coerceAndCheckDataType(it, types) {
  327. const { gen, data, opts } = it;
  328. const coerceTo = coerceToTypes(types, opts.coerceTypes);
  329. const checkTypes = types.length > 0 &&
  330. !(coerceTo.length === 0 && types.length === 1 && applicability_1.schemaHasRulesForType(it, types[0]));
  331. if (checkTypes) {
  332. const wrongType = checkDataTypes(types, data, opts.strict, DataType.Wrong);
  333. gen.if(wrongType, () => {
  334. if (coerceTo.length)
  335. coerceData(it, types, coerceTo);
  336. else
  337. reportTypeError(it);
  338. });
  339. }
  340. return checkTypes;
  341. }
  342. exports.coerceAndCheckDataType = coerceAndCheckDataType;
  343. const COERCIBLE = new Set(["string", "number", "integer", "boolean", "null"]);
  344. function coerceToTypes(types, coerceTypes) {
  345. return coerceTypes
  346. ? types.filter((t) => COERCIBLE.has(t) || (coerceTypes === "array" && t === "array"))
  347. : [];
  348. }
  349. function coerceData(it, types, coerceTo) {
  350. const { gen, data, opts } = it;
  351. const dataType = gen.let("dataType", codegen_1._ `typeof ${data}`);
  352. const coerced = gen.let("coerced", codegen_1._ `undefined`);
  353. if (opts.coerceTypes === "array") {
  354. gen.if(codegen_1._ `${dataType} == 'object' && Array.isArray(${data}) && ${data}.length == 1`, () => gen
  355. .assign(data, codegen_1._ `${data}[0]`)
  356. .assign(dataType, codegen_1._ `typeof ${data}`)
  357. .if(checkDataTypes(types, data, opts.strict), () => gen.assign(coerced, data)));
  358. }
  359. gen.if(codegen_1._ `${coerced} !== undefined`);
  360. for (const t of coerceTo) {
  361. if (COERCIBLE.has(t) || (t === "array" && opts.coerceTypes === "array")) {
  362. coerceSpecificType(t);
  363. }
  364. }
  365. gen.else();
  366. reportTypeError(it);
  367. gen.endIf();
  368. gen.if(codegen_1._ `${coerced} !== undefined`, () => {
  369. gen.assign(data, coerced);
  370. assignParentData(it, coerced);
  371. });
  372. function coerceSpecificType(t) {
  373. switch (t) {
  374. case "string":
  375. gen
  376. .elseIf(codegen_1._ `${dataType} == "number" || ${dataType} == "boolean"`)
  377. .assign(coerced, codegen_1._ `"" + ${data}`)
  378. .elseIf(codegen_1._ `${data} === null`)
  379. .assign(coerced, codegen_1._ `""`);
  380. return;
  381. case "number":
  382. gen
  383. .elseIf(codegen_1._ `${dataType} == "boolean" || ${data} === null
  384. || (${dataType} == "string" && ${data} && ${data} == +${data})`)
  385. .assign(coerced, codegen_1._ `+${data}`);
  386. return;
  387. case "integer":
  388. gen
  389. .elseIf(codegen_1._ `${dataType} === "boolean" || ${data} === null
  390. || (${dataType} === "string" && ${data} && ${data} == +${data} && !(${data} % 1))`)
  391. .assign(coerced, codegen_1._ `+${data}`);
  392. return;
  393. case "boolean":
  394. gen
  395. .elseIf(codegen_1._ `${data} === "false" || ${data} === 0 || ${data} === null`)
  396. .assign(coerced, false)
  397. .elseIf(codegen_1._ `${data} === "true" || ${data} === 1`)
  398. .assign(coerced, true);
  399. return;
  400. case "null":
  401. gen.elseIf(codegen_1._ `${data} === "" || ${data} === 0 || ${data} === false`);
  402. gen.assign(coerced, null);
  403. return;
  404. case "array":
  405. gen
  406. .elseIf(codegen_1._ `${dataType} === "string" || ${dataType} === "number"
  407. || ${dataType} === "boolean" || ${data} === null`)
  408. .assign(coerced, codegen_1._ `[${data}]`);
  409. }
  410. }
  411. }
  412. function assignParentData({ gen, parentData, parentDataProperty }, expr) {
  413. // TODO use gen.property
  414. gen.if(codegen_1._ `${parentData} !== undefined`, () => gen.assign(codegen_1._ `${parentData}[${parentDataProperty}]`, expr));
  415. }
  416. function checkDataType(dataType, data, strictNums, correct = DataType.Correct) {
  417. const EQ = correct === DataType.Correct ? codegen_1.operators.EQ : codegen_1.operators.NEQ;
  418. let cond;
  419. switch (dataType) {
  420. case "null":
  421. return codegen_1._ `${data} ${EQ} null`;
  422. case "array":
  423. cond = codegen_1._ `Array.isArray(${data})`;
  424. break;
  425. case "object":
  426. cond = codegen_1._ `${data} && typeof ${data} == "object" && !Array.isArray(${data})`;
  427. break;
  428. case "integer":
  429. cond = numCond(codegen_1._ `!(${data} % 1) && !isNaN(${data})`);
  430. break;
  431. case "number":
  432. cond = numCond();
  433. break;
  434. default:
  435. return codegen_1._ `typeof ${data} ${EQ} ${dataType}`;
  436. }
  437. return correct === DataType.Correct ? cond : codegen_1.not(cond);
  438. function numCond(_cond = codegen_1.nil) {
  439. return codegen_1.and(codegen_1._ `typeof ${data} == "number"`, _cond, strictNums ? codegen_1._ `isFinite(${data})` : codegen_1.nil);
  440. }
  441. }
  442. exports.checkDataType = checkDataType;
  443. function checkDataTypes(dataTypes, data, strictNums, correct) {
  444. if (dataTypes.length === 1) {
  445. return checkDataType(dataTypes[0], data, strictNums, correct);
  446. }
  447. let cond;
  448. const types = util_1.toHash(dataTypes);
  449. if (types.array && types.object) {
  450. const notObj = codegen_1._ `typeof ${data} != "object"`;
  451. cond = types.null ? notObj : codegen_1._ `!${data} || ${notObj}`;
  452. delete types.null;
  453. delete types.array;
  454. delete types.object;
  455. }
  456. else {
  457. cond = codegen_1.nil;
  458. }
  459. if (types.number)
  460. delete types.integer;
  461. for (const t in types)
  462. cond = codegen_1.and(cond, checkDataType(t, data, strictNums, correct));
  463. return cond;
  464. }
  465. exports.checkDataTypes = checkDataTypes;
  466. const typeError = {
  467. message: ({ schema }) => codegen_1.str `should be ${schema}`,
  468. params: ({ schema, schemaValue }) => typeof schema == "string" ? codegen_1._ `{type: ${schema}}` : codegen_1._ `{type: ${schemaValue}}`,
  469. };
  470. function reportTypeError(it) {
  471. const cxt = getTypeErrorContext(it);
  472. errors_1.reportError(cxt, typeError);
  473. }
  474. exports.reportTypeError = reportTypeError;
  475. function getTypeErrorContext(it) {
  476. const { gen, data, schema } = it;
  477. const schemaCode = util_1.schemaRefOrVal(it, schema, "type");
  478. return {
  479. gen,
  480. keyword: "type",
  481. data,
  482. schema: schema.type,
  483. schemaCode,
  484. schemaValue: schemaCode,
  485. parentSchema: schema,
  486. params: {},
  487. it,
  488. };
  489. }
  490. //# sourceMappingURL=dataType.js.map
  491. }, function(modId) { var map = {"../rules":1609944441819,"./applicability":1609944441820,"../errors":1609944441821,"../codegen":1609944441822,"../util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  492. __DEFINE__(1609944441819, function(require, module, exports) {
  493. Object.defineProperty(exports, "__esModule", { value: true });
  494. exports.getRules = exports.isJSONType = void 0;
  495. const _jsonTypes = ["string", "number", "integer", "boolean", "null", "object", "array"];
  496. const jsonTypes = new Set(_jsonTypes);
  497. function isJSONType(x) {
  498. return typeof x == "string" && jsonTypes.has(x);
  499. }
  500. exports.isJSONType = isJSONType;
  501. function getRules() {
  502. const groups = {
  503. number: { type: "number", rules: [] },
  504. string: { type: "string", rules: [] },
  505. array: { type: "array", rules: [] },
  506. object: { type: "object", rules: [] },
  507. };
  508. return {
  509. types: { ...groups, integer: true, boolean: true, null: true },
  510. rules: [{ rules: [] }, groups.number, groups.string, groups.array, groups.object],
  511. post: { rules: [] },
  512. all: { type: true, $comment: true },
  513. keywords: { type: true, $comment: true },
  514. };
  515. }
  516. exports.getRules = getRules;
  517. //# sourceMappingURL=rules.js.map
  518. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  519. __DEFINE__(1609944441820, function(require, module, exports) {
  520. Object.defineProperty(exports, "__esModule", { value: true });
  521. exports.shouldUseRule = exports.shouldUseGroup = exports.schemaHasRulesForType = void 0;
  522. function schemaHasRulesForType({ schema, self }, type) {
  523. const group = self.RULES.types[type];
  524. return group && group !== true && shouldUseGroup(schema, group);
  525. }
  526. exports.schemaHasRulesForType = schemaHasRulesForType;
  527. function shouldUseGroup(schema, group) {
  528. return group.rules.some((rule) => shouldUseRule(schema, rule));
  529. }
  530. exports.shouldUseGroup = shouldUseGroup;
  531. function shouldUseRule(schema, rule) {
  532. var _a;
  533. return (schema[rule.keyword] !== undefined || ((_a = rule.definition.implements) === null || _a === void 0 ? void 0 : _a.some((kwd) => schema[kwd] !== undefined)));
  534. }
  535. exports.shouldUseRule = shouldUseRule;
  536. //# sourceMappingURL=applicability.js.map
  537. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  538. __DEFINE__(1609944441821, function(require, module, exports) {
  539. Object.defineProperty(exports, "__esModule", { value: true });
  540. exports.extendErrors = exports.resetErrorsCount = exports.reportExtraError = exports.reportError = exports.keyword$DataError = exports.keywordError = void 0;
  541. const codegen_1 = require("./codegen");
  542. const names_1 = require("./names");
  543. exports.keywordError = {
  544. message: ({ keyword }) => codegen_1.str `should pass "${keyword}" keyword validation`,
  545. };
  546. exports.keyword$DataError = {
  547. message: ({ keyword, schemaType }) => schemaType
  548. ? codegen_1.str `"${keyword}" keyword must be ${schemaType} ($data)`
  549. : codegen_1.str `"${keyword}" keyword is invalid ($data)`,
  550. };
  551. function reportError(cxt, error, overrideAllErrors) {
  552. const { it } = cxt;
  553. const { gen, compositeRule, allErrors } = it;
  554. const errObj = errorObjectCode(cxt, error);
  555. if (overrideAllErrors !== null && overrideAllErrors !== void 0 ? overrideAllErrors : (compositeRule || allErrors)) {
  556. addError(gen, errObj);
  557. }
  558. else {
  559. returnErrors(it, codegen_1._ `[${errObj}]`);
  560. }
  561. }
  562. exports.reportError = reportError;
  563. function reportExtraError(cxt, error) {
  564. const { it } = cxt;
  565. const { gen, compositeRule, allErrors } = it;
  566. const errObj = errorObjectCode(cxt, error);
  567. addError(gen, errObj);
  568. if (!(compositeRule || allErrors)) {
  569. returnErrors(it, names_1.default.vErrors);
  570. }
  571. }
  572. exports.reportExtraError = reportExtraError;
  573. function resetErrorsCount(gen, errsCount) {
  574. gen.assign(names_1.default.errors, errsCount);
  575. gen.if(codegen_1._ `${names_1.default.vErrors} !== null`, () => gen.if(errsCount, () => gen.assign(codegen_1._ `${names_1.default.vErrors}.length`, errsCount), () => gen.assign(names_1.default.vErrors, null)));
  576. }
  577. exports.resetErrorsCount = resetErrorsCount;
  578. function extendErrors({ gen, keyword, schemaValue, data, errsCount, it, }) {
  579. /* istanbul ignore if */
  580. if (errsCount === undefined)
  581. throw new Error("ajv implementation error");
  582. const err = gen.name("err");
  583. gen.forRange("i", errsCount, names_1.default.errors, (i) => {
  584. gen.const(err, codegen_1._ `${names_1.default.vErrors}[${i}]`);
  585. gen.if(codegen_1._ `${err}.dataPath === undefined`, () => gen.assign(codegen_1._ `${err}.dataPath`, codegen_1.strConcat(names_1.default.dataPath, it.errorPath)));
  586. gen.assign(codegen_1._ `${err}.schemaPath`, codegen_1.str `${it.errSchemaPath}/${keyword}`);
  587. if (it.opts.verbose) {
  588. gen.assign(codegen_1._ `${err}.schema`, schemaValue);
  589. gen.assign(codegen_1._ `${err}.data`, data);
  590. }
  591. });
  592. }
  593. exports.extendErrors = extendErrors;
  594. function addError(gen, errObj) {
  595. const err = gen.const("err", errObj);
  596. gen.if(codegen_1._ `${names_1.default.vErrors} === null`, () => gen.assign(names_1.default.vErrors, codegen_1._ `[${err}]`), codegen_1._ `${names_1.default.vErrors}.push(${err})`);
  597. gen.code(codegen_1._ `${names_1.default.errors}++`);
  598. }
  599. function returnErrors(it, errs) {
  600. const { gen, validateName, schemaEnv } = it;
  601. if (schemaEnv.$async) {
  602. gen.throw(codegen_1._ `new ${it.ValidationError}(${errs})`);
  603. }
  604. else {
  605. gen.assign(codegen_1._ `${validateName}.errors`, errs);
  606. gen.return(false);
  607. }
  608. }
  609. const E = {
  610. keyword: new codegen_1.Name("keyword"),
  611. schemaPath: new codegen_1.Name("schemaPath"),
  612. params: new codegen_1.Name("params"),
  613. propertyName: new codegen_1.Name("propertyName"),
  614. message: new codegen_1.Name("message"),
  615. schema: new codegen_1.Name("schema"),
  616. parentSchema: new codegen_1.Name("parentSchema"),
  617. };
  618. function errorObjectCode(cxt, error) {
  619. const { keyword, data, schemaValue, it: { gen, createErrors, topSchemaRef, schemaPath, errorPath, errSchemaPath, propertyName, opts }, } = cxt;
  620. if (createErrors === false)
  621. return codegen_1._ `{}`;
  622. const { params, message } = error;
  623. const keyValues = [
  624. [E.keyword, keyword],
  625. [names_1.default.dataPath, codegen_1.strConcat(names_1.default.dataPath, errorPath)],
  626. [E.schemaPath, codegen_1.str `${errSchemaPath}/${keyword}`],
  627. [E.params, typeof params == "function" ? params(cxt) : params || codegen_1._ `{}`],
  628. ];
  629. if (propertyName)
  630. keyValues.push([E.propertyName, propertyName]);
  631. if (opts.messages !== false) {
  632. const msg = typeof message == "function" ? message(cxt) : message;
  633. keyValues.push([E.message, msg]);
  634. }
  635. if (opts.verbose) {
  636. keyValues.push([E.schema, schemaValue], [E.parentSchema, codegen_1._ `${topSchemaRef}${schemaPath}`], [names_1.default.data, data]);
  637. }
  638. return gen.object(...keyValues);
  639. }
  640. //# sourceMappingURL=errors.js.map
  641. }, function(modId) { var map = {"./codegen":1609944441822,"./names":1609944441825}; return __REQUIRE__(map[modId], modId); })
  642. __DEFINE__(1609944441822, function(require, module, exports) {
  643. Object.defineProperty(exports, "__esModule", { value: true });
  644. exports.or = exports.and = exports.not = exports.CodeGen = exports.operators = exports.varKinds = exports.ValueScopeName = exports.ValueScope = exports.Scope = exports.Name = exports.stringify = exports.getProperty = exports.nil = exports.strConcat = exports.str = exports._ = void 0;
  645. const code_1 = require("./code");
  646. const scope_1 = require("./scope");
  647. var code_2 = require("./code");
  648. Object.defineProperty(exports, "_", { enumerable: true, get: function () { return code_2._; } });
  649. Object.defineProperty(exports, "str", { enumerable: true, get: function () { return code_2.str; } });
  650. Object.defineProperty(exports, "strConcat", { enumerable: true, get: function () { return code_2.strConcat; } });
  651. Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return code_2.nil; } });
  652. Object.defineProperty(exports, "getProperty", { enumerable: true, get: function () { return code_2.getProperty; } });
  653. Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return code_2.stringify; } });
  654. Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return code_2.Name; } });
  655. var scope_2 = require("./scope");
  656. Object.defineProperty(exports, "Scope", { enumerable: true, get: function () { return scope_2.Scope; } });
  657. Object.defineProperty(exports, "ValueScope", { enumerable: true, get: function () { return scope_2.ValueScope; } });
  658. Object.defineProperty(exports, "ValueScopeName", { enumerable: true, get: function () { return scope_2.ValueScopeName; } });
  659. Object.defineProperty(exports, "varKinds", { enumerable: true, get: function () { return scope_2.varKinds; } });
  660. exports.operators = {
  661. GT: new code_1._Code(">"),
  662. GTE: new code_1._Code(">="),
  663. LT: new code_1._Code("<"),
  664. LTE: new code_1._Code("<="),
  665. EQ: new code_1._Code("==="),
  666. NEQ: new code_1._Code("!=="),
  667. NOT: new code_1._Code("!"),
  668. OR: new code_1._Code("||"),
  669. AND: new code_1._Code("&&"),
  670. };
  671. class Node {
  672. optimizeNodes() {
  673. return this;
  674. }
  675. optimizeNames(_names, _constants) {
  676. return this;
  677. }
  678. }
  679. class Def extends Node {
  680. constructor(varKind, name, rhs) {
  681. super();
  682. this.varKind = varKind;
  683. this.name = name;
  684. this.rhs = rhs;
  685. }
  686. render({ es5, _n }) {
  687. const varKind = es5 ? scope_1.varKinds.var : this.varKind;
  688. const rhs = this.rhs === undefined ? "" : ` = ${this.rhs}`;
  689. return `${varKind} ${this.name}${rhs};` + _n;
  690. }
  691. optimizeNames(names, constants) {
  692. if (!names[this.name.str])
  693. return;
  694. if (this.rhs)
  695. this.rhs = optimizeExpr(this.rhs, names, constants);
  696. return this;
  697. }
  698. get names() {
  699. return this.rhs instanceof code_1._CodeOrName ? this.rhs.names : {};
  700. }
  701. }
  702. class Assign extends Node {
  703. constructor(lhs, rhs, sideEffects) {
  704. super();
  705. this.lhs = lhs;
  706. this.rhs = rhs;
  707. this.sideEffects = sideEffects;
  708. }
  709. render({ _n }) {
  710. return `${this.lhs} = ${this.rhs};` + _n;
  711. }
  712. optimizeNames(names, constants) {
  713. if (this.lhs instanceof code_1.Name && !names[this.lhs.str] && !this.sideEffects)
  714. return;
  715. this.rhs = optimizeExpr(this.rhs, names, constants);
  716. return this;
  717. }
  718. get names() {
  719. const names = this.lhs instanceof code_1.Name ? {} : { ...this.lhs.names };
  720. return addExprNames(names, this.rhs);
  721. }
  722. }
  723. class Label extends Node {
  724. constructor(label) {
  725. super();
  726. this.label = label;
  727. this.names = {};
  728. }
  729. render({ _n }) {
  730. return `${this.label}:` + _n;
  731. }
  732. }
  733. class Break extends Node {
  734. constructor(label) {
  735. super();
  736. this.label = label;
  737. this.names = {};
  738. }
  739. render({ _n }) {
  740. const label = this.label ? ` ${this.label}` : "";
  741. return `break${label};` + _n;
  742. }
  743. }
  744. class Throw extends Node {
  745. constructor(error) {
  746. super();
  747. this.error = error;
  748. }
  749. render({ _n }) {
  750. return `throw ${this.error};` + _n;
  751. }
  752. get names() {
  753. return this.error.names;
  754. }
  755. }
  756. class AnyCode extends Node {
  757. constructor(code) {
  758. super();
  759. this.code = code;
  760. }
  761. render({ _n }) {
  762. return `${this.code};` + _n;
  763. }
  764. optimizeNodes() {
  765. return `${this.code}` ? this : undefined;
  766. }
  767. optimizeNames(names, constants) {
  768. this.code = optimizeExpr(this.code, names, constants);
  769. return this;
  770. }
  771. get names() {
  772. return this.code instanceof code_1._CodeOrName ? this.code.names : {};
  773. }
  774. }
  775. class ParentNode extends Node {
  776. constructor(nodes = []) {
  777. super();
  778. this.nodes = nodes;
  779. }
  780. render(opts) {
  781. return this.nodes.reduce((code, n) => code + n.render(opts), "");
  782. }
  783. optimizeNodes() {
  784. const { nodes } = this;
  785. let i = nodes.length;
  786. while (i--) {
  787. const n = nodes[i].optimizeNodes();
  788. if (Array.isArray(n))
  789. nodes.splice(i, 1, ...n);
  790. else if (n)
  791. nodes[i] = n;
  792. else
  793. nodes.splice(i, 1);
  794. }
  795. return nodes.length > 0 ? this : undefined;
  796. }
  797. optimizeNames(names, constants) {
  798. const { nodes } = this;
  799. let i = nodes.length;
  800. while (i--) {
  801. // iterating backwards improves 1-pass optimization
  802. const n = nodes[i];
  803. if (n.optimizeNames(names, constants))
  804. continue;
  805. subtractNames(names, n.names);
  806. nodes.splice(i, 1);
  807. }
  808. return nodes.length > 0 ? this : undefined;
  809. }
  810. get names() {
  811. return this.nodes.reduce((names, n) => addNames(names, n.names), {});
  812. }
  813. }
  814. class BlockNode extends ParentNode {
  815. render(opts) {
  816. return "{" + opts._n + super.render(opts) + "}" + opts._n;
  817. }
  818. }
  819. class Root extends ParentNode {
  820. }
  821. class Else extends BlockNode {
  822. }
  823. Else.kind = "else";
  824. class If extends BlockNode {
  825. constructor(condition, nodes) {
  826. super(nodes);
  827. this.condition = condition;
  828. }
  829. render(opts) {
  830. let code = `if(${this.condition})` + super.render(opts);
  831. if (this.else)
  832. code += "else " + this.else.render(opts);
  833. return code;
  834. }
  835. optimizeNodes() {
  836. super.optimizeNodes();
  837. const cond = this.condition;
  838. if (cond === true)
  839. return this.nodes; // else is ignored here
  840. let e = this.else;
  841. if (e) {
  842. const ns = e.optimizeNodes();
  843. e = this.else = Array.isArray(ns) ? new Else(ns) : ns;
  844. }
  845. if (e) {
  846. if (cond === false)
  847. return e instanceof If ? e : e.nodes;
  848. if (this.nodes.length)
  849. return this;
  850. return new If(not(cond), e instanceof If ? [e] : e.nodes);
  851. }
  852. if (cond === false || !this.nodes.length)
  853. return undefined;
  854. return this;
  855. }
  856. optimizeNames(names, constants) {
  857. var _a;
  858. this.else = (_a = this.else) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
  859. if (!(super.optimizeNames(names, constants) || this.else))
  860. return;
  861. this.condition = optimizeExpr(this.condition, names, constants);
  862. return this;
  863. }
  864. get names() {
  865. const names = super.names;
  866. addExprNames(names, this.condition);
  867. if (this.else)
  868. addNames(names, this.else.names);
  869. return names;
  870. }
  871. }
  872. If.kind = "if";
  873. class For extends BlockNode {
  874. }
  875. For.kind = "for";
  876. class ForLoop extends For {
  877. constructor(iteration) {
  878. super();
  879. this.iteration = iteration;
  880. }
  881. render(opts) {
  882. return `for(${this.iteration})` + super.render(opts);
  883. }
  884. optimizeNames(names, constants) {
  885. if (!super.optimizeNames(names, constants))
  886. return;
  887. this.iteration = optimizeExpr(this.iteration, names, constants);
  888. return this;
  889. }
  890. get names() {
  891. return addNames(super.names, this.iteration.names);
  892. }
  893. }
  894. class ForRange extends For {
  895. constructor(varKind, name, from, to) {
  896. super();
  897. this.varKind = varKind;
  898. this.name = name;
  899. this.from = from;
  900. this.to = to;
  901. }
  902. render(opts) {
  903. const varKind = opts.es5 ? scope_1.varKinds.var : this.varKind;
  904. const { name, from, to } = this;
  905. return `for(${varKind} ${name}=${from}; ${name}<${to}; ${name}++)` + super.render(opts);
  906. }
  907. get names() {
  908. const names = addExprNames(super.names, this.from);
  909. return addExprNames(names, this.to);
  910. }
  911. }
  912. class ForIter extends For {
  913. constructor(loop, varKind, name, iterable) {
  914. super();
  915. this.loop = loop;
  916. this.varKind = varKind;
  917. this.name = name;
  918. this.iterable = iterable;
  919. }
  920. render(opts) {
  921. return `for(${this.varKind} ${this.name} ${this.loop} ${this.iterable})` + super.render(opts);
  922. }
  923. optimizeNames(names, constants) {
  924. if (!super.optimizeNames(names, constants))
  925. return;
  926. this.iterable = optimizeExpr(this.iterable, names, constants);
  927. return this;
  928. }
  929. get names() {
  930. return addNames(super.names, this.iterable.names);
  931. }
  932. }
  933. class Func extends BlockNode {
  934. constructor(name, args, async) {
  935. super();
  936. this.name = name;
  937. this.args = args;
  938. this.async = async;
  939. }
  940. render(opts) {
  941. const _async = this.async ? "async " : "";
  942. return `${_async}function ${this.name}(${this.args})` + super.render(opts);
  943. }
  944. }
  945. Func.kind = "func";
  946. class Return extends ParentNode {
  947. render(opts) {
  948. return "return " + super.render(opts);
  949. }
  950. }
  951. Return.kind = "return";
  952. class Try extends BlockNode {
  953. render(opts) {
  954. let code = "try" + super.render(opts);
  955. if (this.catch)
  956. code += this.catch.render(opts);
  957. if (this.finally)
  958. code += this.finally.render(opts);
  959. return code;
  960. }
  961. optimizeNodes() {
  962. var _a, _b;
  963. super.optimizeNodes();
  964. (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNodes();
  965. (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNodes();
  966. return this;
  967. }
  968. optimizeNames(names, constants) {
  969. var _a, _b;
  970. super.optimizeNames(names, constants);
  971. (_a = this.catch) === null || _a === void 0 ? void 0 : _a.optimizeNames(names, constants);
  972. (_b = this.finally) === null || _b === void 0 ? void 0 : _b.optimizeNames(names, constants);
  973. return this;
  974. }
  975. get names() {
  976. const names = super.names;
  977. if (this.catch)
  978. addNames(names, this.catch.names);
  979. if (this.finally)
  980. addNames(names, this.finally.names);
  981. return names;
  982. }
  983. }
  984. class Catch extends BlockNode {
  985. constructor(error) {
  986. super();
  987. this.error = error;
  988. }
  989. render(opts) {
  990. return `catch(${this.error})` + super.render(opts);
  991. }
  992. }
  993. Catch.kind = "catch";
  994. class Finally extends BlockNode {
  995. render(opts) {
  996. return "finally" + super.render(opts);
  997. }
  998. }
  999. Finally.kind = "finally";
  1000. class CodeGen {
  1001. constructor(extScope, opts = {}) {
  1002. this._values = {};
  1003. this._blockStarts = [];
  1004. this._constants = {};
  1005. this.opts = { ...opts, _n: opts.lines ? "\n" : "" };
  1006. this._extScope = extScope;
  1007. this._scope = new scope_1.Scope({ parent: extScope });
  1008. this._nodes = [new Root()];
  1009. }
  1010. toString() {
  1011. return this._root.render(this.opts);
  1012. }
  1013. // returns unique name in the internal scope
  1014. name(prefix) {
  1015. return this._scope.name(prefix);
  1016. }
  1017. // reserves unique name in the external scope
  1018. scopeName(prefix) {
  1019. return this._extScope.name(prefix);
  1020. }
  1021. // reserves unique name in the external scope and assigns value to it
  1022. scopeValue(prefixOrName, value) {
  1023. const name = this._extScope.value(prefixOrName, value);
  1024. const vs = this._values[name.prefix] || (this._values[name.prefix] = new Set());
  1025. vs.add(name);
  1026. return name;
  1027. }
  1028. getScopeValue(prefix, keyOrRef) {
  1029. return this._extScope.getValue(prefix, keyOrRef);
  1030. }
  1031. // return code that assigns values in the external scope to the names that are used internally
  1032. // (same names that were returned by gen.scopeName or gen.scopeValue)
  1033. scopeRefs(scopeName) {
  1034. return this._extScope.scopeRefs(scopeName, this._values);
  1035. }
  1036. scopeCode() {
  1037. return this._extScope.scopeCode(this._values);
  1038. }
  1039. _def(varKind, nameOrPrefix, rhs, constant) {
  1040. const name = this._scope.toName(nameOrPrefix);
  1041. if (rhs !== undefined && constant)
  1042. this._constants[name.str] = rhs;
  1043. this._leafNode(new Def(varKind, name, rhs));
  1044. return name;
  1045. }
  1046. // `const` declaration (`var` in es5 mode)
  1047. const(nameOrPrefix, rhs, _constant) {
  1048. return this._def(scope_1.varKinds.const, nameOrPrefix, rhs, _constant);
  1049. }
  1050. // `let` declaration with optional assignment (`var` in es5 mode)
  1051. let(nameOrPrefix, rhs, _constant) {
  1052. return this._def(scope_1.varKinds.let, nameOrPrefix, rhs, _constant);
  1053. }
  1054. // `var` declaration with optional assignment
  1055. var(nameOrPrefix, rhs, _constant) {
  1056. return this._def(scope_1.varKinds.var, nameOrPrefix, rhs, _constant);
  1057. }
  1058. // assignment code
  1059. assign(lhs, rhs, sideEffects) {
  1060. return this._leafNode(new Assign(lhs, rhs, sideEffects));
  1061. }
  1062. // appends passed SafeExpr to code or executes Block
  1063. code(c) {
  1064. if (typeof c == "function")
  1065. c();
  1066. else if (c !== code_1.nil)
  1067. this._leafNode(new AnyCode(c));
  1068. return this;
  1069. }
  1070. // returns code for object literal for the passed argument list of key-value pairs
  1071. object(...keyValues) {
  1072. const code = ["{"];
  1073. for (const [key, value] of keyValues) {
  1074. if (code.length > 1)
  1075. code.push(",");
  1076. code.push(key);
  1077. if (key !== value || this.opts.es5) {
  1078. code.push(":");
  1079. code_1.addCodeArg(code, value);
  1080. }
  1081. }
  1082. code.push("}");
  1083. return new code_1._Code(code);
  1084. }
  1085. // `if` clause (or statement if `thenBody` and, optionally, `elseBody` are passed)
  1086. if(condition, thenBody, elseBody) {
  1087. this._blockNode(new If(condition));
  1088. if (thenBody && elseBody) {
  1089. this.code(thenBody).else().code(elseBody).endIf();
  1090. }
  1091. else if (thenBody) {
  1092. this.code(thenBody).endIf();
  1093. }
  1094. else if (elseBody) {
  1095. throw new Error('CodeGen: "else" body without "then" body');
  1096. }
  1097. return this;
  1098. }
  1099. // `else if` clause - invalid without `if` or after `else` clauses
  1100. elseIf(condition) {
  1101. return this._elseNode(new If(condition));
  1102. }
  1103. // `else` clause - only valid after `if` or `else if` clauses
  1104. else() {
  1105. return this._elseNode(new Else());
  1106. }
  1107. // end `if` statement (needed if gen.if was used only with condition)
  1108. endIf() {
  1109. return this._endBlockNode(If, Else);
  1110. }
  1111. _for(node, forBody) {
  1112. this._blockNode(node);
  1113. if (forBody)
  1114. this.code(forBody).endFor();
  1115. return this;
  1116. }
  1117. // a generic `for` clause (or statement if `forBody` is passed)
  1118. for(iteration, forBody) {
  1119. return this._for(new ForLoop(iteration), forBody);
  1120. }
  1121. // `for` statement for a range of values
  1122. forRange(nameOrPrefix, from, to, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.let) {
  1123. const name = this._scope.toName(nameOrPrefix);
  1124. return this._for(new ForRange(varKind, name, from, to), () => forBody(name));
  1125. }
  1126. // `for-of` statement (in es5 mode replace with a normal for loop)
  1127. forOf(nameOrPrefix, iterable, forBody, varKind = scope_1.varKinds.const) {
  1128. const name = this._scope.toName(nameOrPrefix);
  1129. if (this.opts.es5) {
  1130. const arr = iterable instanceof code_1.Name ? iterable : this.var("_arr", iterable);
  1131. return this.forRange("_i", 0, code_1._ `${arr}.length`, (i) => {
  1132. this.var(name, code_1._ `${arr}[${i}]`);
  1133. forBody(name);
  1134. });
  1135. }
  1136. return this._for(new ForIter("of", varKind, name, iterable), () => forBody(name));
  1137. }
  1138. // `for-in` statement.
  1139. // With option `ownProperties` replaced with a `for-of` loop for object keys
  1140. forIn(nameOrPrefix, obj, forBody, varKind = this.opts.es5 ? scope_1.varKinds.var : scope_1.varKinds.const) {
  1141. if (this.opts.ownProperties) {
  1142. return this.forOf(nameOrPrefix, code_1._ `Object.keys(${obj})`, forBody);
  1143. }
  1144. const name = this._scope.toName(nameOrPrefix);
  1145. return this._for(new ForIter("in", varKind, name, obj), () => forBody(name));
  1146. }
  1147. // end `for` loop
  1148. endFor() {
  1149. return this._endBlockNode(For);
  1150. }
  1151. // `label` statement
  1152. label(label) {
  1153. return this._leafNode(new Label(label));
  1154. }
  1155. // `break` statement
  1156. break(label) {
  1157. return this._leafNode(new Break(label));
  1158. }
  1159. // `return` statement
  1160. return(value) {
  1161. const node = new Return();
  1162. this._blockNode(node);
  1163. this.code(value);
  1164. if (node.nodes.length !== 1)
  1165. throw new Error('CodeGen: "return" should have one node');
  1166. return this._endBlockNode(Return);
  1167. }
  1168. // `try` statement
  1169. try(tryBody, catchCode, finallyCode) {
  1170. if (!catchCode && !finallyCode)
  1171. throw new Error('CodeGen: "try" without "catch" and "finally"');
  1172. const node = new Try();
  1173. this._blockNode(node);
  1174. this.code(tryBody);
  1175. if (catchCode) {
  1176. const error = this.name("e");
  1177. this._currNode = node.catch = new Catch(error);
  1178. catchCode(error);
  1179. }
  1180. if (finallyCode) {
  1181. this._currNode = node.finally = new Finally();
  1182. this.code(finallyCode);
  1183. }
  1184. return this._endBlockNode(Catch, Finally);
  1185. }
  1186. // `throw` statement
  1187. throw(error) {
  1188. return this._leafNode(new Throw(error));
  1189. }
  1190. // start self-balancing block
  1191. block(body, nodeCount) {
  1192. this._blockStarts.push(this._nodes.length);
  1193. if (body)
  1194. this.code(body).endBlock(nodeCount);
  1195. return this;
  1196. }
  1197. // end the current self-balancing block
  1198. endBlock(nodeCount) {
  1199. const len = this._blockStarts.pop();
  1200. if (len === undefined)
  1201. throw new Error("CodeGen: not in self-balancing block");
  1202. const toClose = this._nodes.length - len;
  1203. if (toClose < 0 || (nodeCount !== undefined && toClose !== nodeCount)) {
  1204. throw new Error(`CodeGen: wrong number of nodes: ${toClose} vs ${nodeCount} expected`);
  1205. }
  1206. this._nodes.length = len;
  1207. return this;
  1208. }
  1209. // `function` heading (or definition if funcBody is passed)
  1210. func(name, args = code_1.nil, async, funcBody) {
  1211. this._blockNode(new Func(name, args, async));
  1212. if (funcBody)
  1213. this.code(funcBody).endFunc();
  1214. return this;
  1215. }
  1216. // end function definition
  1217. endFunc() {
  1218. return this._endBlockNode(Func);
  1219. }
  1220. optimize(n = 1) {
  1221. while (n-- > 0) {
  1222. this._root.optimizeNodes();
  1223. this._root.optimizeNames(this._root.names, this._constants);
  1224. }
  1225. }
  1226. _leafNode(node) {
  1227. this._currNode.nodes.push(node);
  1228. return this;
  1229. }
  1230. _blockNode(node) {
  1231. this._currNode.nodes.push(node);
  1232. this._nodes.push(node);
  1233. }
  1234. _endBlockNode(N1, N2) {
  1235. const n = this._currNode;
  1236. if (n instanceof N1 || (N2 && n instanceof N2)) {
  1237. this._nodes.pop();
  1238. return this;
  1239. }
  1240. throw new Error(`CodeGen: not in block "${N2 ? `${N1.kind}/${N2.kind}` : N1.kind}"`);
  1241. }
  1242. _elseNode(node) {
  1243. const n = this._currNode;
  1244. if (!(n instanceof If)) {
  1245. throw new Error('CodeGen: "else" without "if"');
  1246. }
  1247. this._currNode = n.else = node;
  1248. return this;
  1249. }
  1250. get _root() {
  1251. return this._nodes[0];
  1252. }
  1253. get _currNode() {
  1254. const ns = this._nodes;
  1255. return ns[ns.length - 1];
  1256. }
  1257. set _currNode(node) {
  1258. const ns = this._nodes;
  1259. ns[ns.length - 1] = node;
  1260. }
  1261. }
  1262. exports.CodeGen = CodeGen;
  1263. function addNames(names, from) {
  1264. for (const n in from)
  1265. names[n] = (names[n] || 0) + (from[n] || 0);
  1266. return names;
  1267. }
  1268. function addExprNames(names, from) {
  1269. return from instanceof code_1._CodeOrName ? addNames(names, from.names) : names;
  1270. }
  1271. function optimizeExpr(expr, names, constants) {
  1272. if (expr instanceof code_1.Name)
  1273. return replaceName(expr);
  1274. if (!canOptimize(expr))
  1275. return expr;
  1276. return new code_1._Code(expr._items.reduce((items, c) => {
  1277. if (c instanceof code_1.Name)
  1278. c = replaceName(c);
  1279. if (c instanceof code_1._Code)
  1280. items.push(...c._items);
  1281. else
  1282. items.push(c);
  1283. return items;
  1284. }, []));
  1285. function replaceName(n) {
  1286. const c = constants[n.str];
  1287. if (c === undefined || names[n.str] !== 1)
  1288. return n;
  1289. delete names[n.str];
  1290. return c;
  1291. }
  1292. function canOptimize(e) {
  1293. return (e instanceof code_1._Code &&
  1294. e._items.some((c) => c instanceof code_1.Name && names[c.str] === 1 && constants[c.str] !== undefined));
  1295. }
  1296. }
  1297. function subtractNames(names, from) {
  1298. for (const n in from)
  1299. names[n] = (names[n] || 0) - (from[n] || 0);
  1300. }
  1301. function not(x) {
  1302. return typeof x == "boolean" || typeof x == "number" || x === null ? !x : code_1._ `!${par(x)}`;
  1303. }
  1304. exports.not = not;
  1305. const andCode = mappend(exports.operators.AND);
  1306. // boolean AND (&&) expression with the passed arguments
  1307. function and(...args) {
  1308. return args.reduce(andCode);
  1309. }
  1310. exports.and = and;
  1311. const orCode = mappend(exports.operators.OR);
  1312. // boolean OR (||) expression with the passed arguments
  1313. function or(...args) {
  1314. return args.reduce(orCode);
  1315. }
  1316. exports.or = or;
  1317. function mappend(op) {
  1318. return (x, y) => (x === code_1.nil ? y : y === code_1.nil ? x : code_1._ `${par(x)} ${op} ${par(y)}`);
  1319. }
  1320. function par(x) {
  1321. return x instanceof code_1.Name ? x : code_1._ `(${x})`;
  1322. }
  1323. //# sourceMappingURL=index.js.map
  1324. }, function(modId) { var map = {"./code":1609944441823,"./scope":1609944441824}; return __REQUIRE__(map[modId], modId); })
  1325. __DEFINE__(1609944441823, function(require, module, exports) {
  1326. Object.defineProperty(exports, "__esModule", { value: true });
  1327. exports.getProperty = exports.safeStringify = exports.stringify = exports.strConcat = exports.addCodeArg = exports.str = exports._ = exports.nil = exports._Code = exports.Name = exports.IDENTIFIER = exports._CodeOrName = void 0;
  1328. class _CodeOrName {
  1329. }
  1330. exports._CodeOrName = _CodeOrName;
  1331. exports.IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
  1332. class Name extends _CodeOrName {
  1333. constructor(s) {
  1334. super();
  1335. if (!exports.IDENTIFIER.test(s))
  1336. throw new Error("CodeGen: name must be a valid identifier");
  1337. this.str = s;
  1338. }
  1339. toString() {
  1340. return this.str;
  1341. }
  1342. emptyStr() {
  1343. return false;
  1344. }
  1345. get names() {
  1346. return { [this.str]: 1 };
  1347. }
  1348. }
  1349. exports.Name = Name;
  1350. class _Code extends _CodeOrName {
  1351. constructor(code) {
  1352. super();
  1353. this._items = typeof code === "string" ? [code] : code;
  1354. }
  1355. toString() {
  1356. return this.str;
  1357. }
  1358. emptyStr() {
  1359. if (this._items.length > 1)
  1360. return false;
  1361. const item = this._items[0];
  1362. return item === "" || item === '""';
  1363. }
  1364. get str() {
  1365. var _a;
  1366. return ((_a = this._str) !== null && _a !== void 0 ? _a : (this._str = this._items.reduce((s, c) => `${s}${c}`, "")));
  1367. }
  1368. get names() {
  1369. var _a;
  1370. return ((_a = this._names) !== null && _a !== void 0 ? _a : (this._names = this._items.reduce((names, c) => {
  1371. if (c instanceof Name)
  1372. names[c.str] = (names[c.str] || 0) + 1;
  1373. return names;
  1374. }, {})));
  1375. }
  1376. }
  1377. exports._Code = _Code;
  1378. exports.nil = new _Code("");
  1379. function _(strs, ...args) {
  1380. const code = [strs[0]];
  1381. let i = 0;
  1382. while (i < args.length) {
  1383. addCodeArg(code, args[i]);
  1384. code.push(strs[++i]);
  1385. }
  1386. return new _Code(code);
  1387. }
  1388. exports._ = _;
  1389. const plus = new _Code("+");
  1390. function str(strs, ...args) {
  1391. const expr = [safeStringify(strs[0])];
  1392. let i = 0;
  1393. while (i < args.length) {
  1394. expr.push(plus);
  1395. addCodeArg(expr, args[i]);
  1396. expr.push(plus, safeStringify(strs[++i]));
  1397. }
  1398. optimize(expr);
  1399. return new _Code(expr);
  1400. }
  1401. exports.str = str;
  1402. function addCodeArg(code, arg) {
  1403. if (arg instanceof _Code)
  1404. code.push(...arg._items);
  1405. else if (arg instanceof Name)
  1406. code.push(arg);
  1407. else
  1408. code.push(interpolate(arg));
  1409. }
  1410. exports.addCodeArg = addCodeArg;
  1411. function optimize(expr) {
  1412. let i = 1;
  1413. while (i < expr.length - 1) {
  1414. if (expr[i] === plus) {
  1415. const res = mergeExprItems(expr[i - 1], expr[i + 1]);
  1416. if (res !== undefined) {
  1417. expr.splice(i - 1, 3, res);
  1418. continue;
  1419. }
  1420. expr[i++] = "+";
  1421. }
  1422. i++;
  1423. }
  1424. }
  1425. function mergeExprItems(a, b) {
  1426. if (b === '""')
  1427. return a;
  1428. if (a === '""')
  1429. return b;
  1430. if (typeof a == "string") {
  1431. if (b instanceof Name || a[a.length - 1] !== '"')
  1432. return;
  1433. if (typeof b != "string")
  1434. return `${a.slice(0, -1)}${b}"`;
  1435. if (b[0] === '"')
  1436. return a.slice(0, -1) + b.slice(1);
  1437. return;
  1438. }
  1439. if (typeof b == "string" && b[0] === '"' && !(a instanceof Name))
  1440. return `"${a}${b.slice(1)}`;
  1441. return;
  1442. }
  1443. function strConcat(c1, c2) {
  1444. return c2.emptyStr() ? c1 : c1.emptyStr() ? c2 : str `${c1}${c2}`;
  1445. }
  1446. exports.strConcat = strConcat;
  1447. // TODO do not allow arrays here
  1448. function interpolate(x) {
  1449. return typeof x == "number" || typeof x == "boolean" || x === null
  1450. ? x
  1451. : safeStringify(Array.isArray(x) ? x.join(",") : x);
  1452. }
  1453. function stringify(x) {
  1454. return new _Code(safeStringify(x));
  1455. }
  1456. exports.stringify = stringify;
  1457. function safeStringify(x) {
  1458. return JSON.stringify(x)
  1459. .replace(/\u2028/g, "\\u2028")
  1460. .replace(/\u2029/g, "\\u2029");
  1461. }
  1462. exports.safeStringify = safeStringify;
  1463. function getProperty(key) {
  1464. return typeof key == "string" && exports.IDENTIFIER.test(key) ? new _Code(`.${key}`) : _ `[${key}]`;
  1465. }
  1466. exports.getProperty = getProperty;
  1467. //# sourceMappingURL=code.js.map
  1468. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  1469. __DEFINE__(1609944441824, function(require, module, exports) {
  1470. Object.defineProperty(exports, "__esModule", { value: true });
  1471. exports.ValueScope = exports.ValueScopeName = exports.Scope = exports.varKinds = void 0;
  1472. const code_1 = require("./code");
  1473. class ValueError extends Error {
  1474. constructor(name) {
  1475. super(`CodeGen: "code" for ${name} not defined`);
  1476. this.value = name.value;
  1477. }
  1478. }
  1479. exports.varKinds = {
  1480. const: new code_1.Name("const"),
  1481. let: new code_1.Name("let"),
  1482. var: new code_1.Name("var"),
  1483. };
  1484. class Scope {
  1485. constructor({ prefixes, parent } = {}) {
  1486. this._names = {};
  1487. this._prefixes = prefixes;
  1488. this._parent = parent;
  1489. }
  1490. toName(nameOrPrefix) {
  1491. return nameOrPrefix instanceof code_1.Name ? nameOrPrefix : this.name(nameOrPrefix);
  1492. }
  1493. name(prefix) {
  1494. return new code_1.Name(this._newName(prefix));
  1495. }
  1496. _newName(prefix) {
  1497. const ng = this._names[prefix] || this._nameGroup(prefix);
  1498. return `${prefix}${ng.index++}`;
  1499. }
  1500. _nameGroup(prefix) {
  1501. var _a, _b;
  1502. if (((_b = (_a = this._parent) === null || _a === void 0 ? void 0 : _a._prefixes) === null || _b === void 0 ? void 0 : _b.has(prefix)) || (this._prefixes && !this._prefixes.has(prefix))) {
  1503. throw new Error(`CodeGen: prefix "${prefix}" is not allowed in this scope`);
  1504. }
  1505. return (this._names[prefix] = { prefix, index: 0 });
  1506. }
  1507. }
  1508. exports.Scope = Scope;
  1509. class ValueScopeName extends code_1.Name {
  1510. constructor(prefix, nameStr) {
  1511. super(nameStr);
  1512. this.prefix = prefix;
  1513. }
  1514. setValue(value, { property, itemIndex }) {
  1515. this.value = value;
  1516. this.scopePath = code_1._ `.${new code_1.Name(property)}[${itemIndex}]`;
  1517. }
  1518. }
  1519. exports.ValueScopeName = ValueScopeName;
  1520. const line = code_1._ `\n`;
  1521. class ValueScope extends Scope {
  1522. constructor(opts) {
  1523. super(opts);
  1524. this._values = {};
  1525. this._scope = opts.scope;
  1526. this.opts = { ...opts, _n: opts.lines ? line : code_1.nil };
  1527. }
  1528. get() {
  1529. return this._scope;
  1530. }
  1531. name(prefix) {
  1532. return new ValueScopeName(prefix, this._newName(prefix));
  1533. }
  1534. value(nameOrPrefix, value) {
  1535. var _a;
  1536. if (value.ref === undefined)
  1537. throw new Error("CodeGen: ref must be passed in value");
  1538. const name = this.toName(nameOrPrefix);
  1539. const { prefix } = name;
  1540. const valueKey = (_a = value.key) !== null && _a !== void 0 ? _a : value.ref;
  1541. let vs = this._values[prefix];
  1542. if (vs) {
  1543. const _name = vs.get(valueKey);
  1544. if (_name)
  1545. return _name;
  1546. }
  1547. else {
  1548. vs = this._values[prefix] = new Map();
  1549. }
  1550. vs.set(valueKey, name);
  1551. const s = this._scope[prefix] || (this._scope[prefix] = []);
  1552. const itemIndex = s.length;
  1553. s[itemIndex] = value.ref;
  1554. name.setValue(value, { property: prefix, itemIndex });
  1555. return name;
  1556. }
  1557. getValue(prefix, keyOrRef) {
  1558. const vs = this._values[prefix];
  1559. if (!vs)
  1560. return;
  1561. return vs.get(keyOrRef);
  1562. }
  1563. scopeRefs(scopeName, values = this._values) {
  1564. return this._reduceValues(values, (name) => {
  1565. if (name.scopePath === undefined)
  1566. throw new Error(`CodeGen: name "${name}" has no value`);
  1567. return code_1._ `${scopeName}${name.scopePath}`;
  1568. });
  1569. }
  1570. scopeCode(values = this._values, usedValues, getCode) {
  1571. return this._reduceValues(values, (name) => {
  1572. if (name.value === undefined)
  1573. throw new Error(`CodeGen: name "${name}" has no value`);
  1574. return name.value.code;
  1575. }, usedValues, getCode);
  1576. }
  1577. _reduceValues(values, valueCode, usedValues = {}, getCode) {
  1578. let code = code_1.nil;
  1579. for (const prefix in values) {
  1580. const vs = values[prefix];
  1581. if (!vs)
  1582. continue;
  1583. const nameSet = (usedValues[prefix] = usedValues[prefix] || new Set());
  1584. vs.forEach((name) => {
  1585. if (nameSet.has(name))
  1586. return;
  1587. nameSet.add(name);
  1588. let c = valueCode(name);
  1589. if (c) {
  1590. const def = this.opts.es5 ? exports.varKinds.var : exports.varKinds.const;
  1591. code = code_1._ `${code}${def} ${name} = ${c};${this.opts._n}`;
  1592. }
  1593. else if ((c = getCode === null || getCode === void 0 ? void 0 : getCode(name))) {
  1594. code = code_1._ `${code}${c}${this.opts._n}`;
  1595. }
  1596. else {
  1597. throw new ValueError(name);
  1598. }
  1599. });
  1600. }
  1601. return code;
  1602. }
  1603. }
  1604. exports.ValueScope = ValueScope;
  1605. //# sourceMappingURL=scope.js.map
  1606. }, function(modId) { var map = {"./code":1609944441823}; return __REQUIRE__(map[modId], modId); })
  1607. __DEFINE__(1609944441825, function(require, module, exports) {
  1608. Object.defineProperty(exports, "__esModule", { value: true });
  1609. const codegen_1 = require("./codegen");
  1610. const names = {
  1611. // validation function arguments
  1612. data: new codegen_1.Name("data"),
  1613. // args passed from referencing schema
  1614. valCxt: new codegen_1.Name("valCxt"),
  1615. dataPath: new codegen_1.Name("dataPath"),
  1616. parentData: new codegen_1.Name("parentData"),
  1617. parentDataProperty: new codegen_1.Name("parentDataProperty"),
  1618. rootData: new codegen_1.Name("rootData"),
  1619. dynamicAnchors: new codegen_1.Name("dynamicAnchors"),
  1620. // function scoped variables
  1621. vErrors: new codegen_1.Name("vErrors"),
  1622. errors: new codegen_1.Name("errors"),
  1623. this: new codegen_1.Name("this"),
  1624. // "globals"
  1625. self: new codegen_1.Name("self"),
  1626. scope: new codegen_1.Name("scope"),
  1627. };
  1628. exports.default = names;
  1629. //# sourceMappingURL=names.js.map
  1630. }, function(modId) { var map = {"./codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  1631. __DEFINE__(1609944441826, function(require, module, exports) {
  1632. Object.defineProperty(exports, "__esModule", { value: true });
  1633. exports.setEvaluated = exports.evaluatedPropsToName = exports.mergeEvaluated = exports.eachItem = exports.unescapeJsonPointer = exports.escapeJsonPointer = exports.escapeFragment = exports.unescapeFragment = exports.schemaRefOrVal = exports.schemaHasRulesButRef = exports.schemaHasRules = exports.checkUnknownRules = exports.alwaysValidSchema = exports.toHash = void 0;
  1634. const codegen_1 = require("./codegen");
  1635. const validate_1 = require("./validate");
  1636. // TODO refactor to use Set
  1637. function toHash(arr) {
  1638. const hash = {};
  1639. for (const item of arr)
  1640. hash[item] = true;
  1641. return hash;
  1642. }
  1643. exports.toHash = toHash;
  1644. function alwaysValidSchema(it, schema) {
  1645. if (typeof schema == "boolean")
  1646. return schema;
  1647. if (Object.keys(schema).length === 0)
  1648. return true;
  1649. checkUnknownRules(it, schema);
  1650. return !schemaHasRules(schema, it.self.RULES.all);
  1651. }
  1652. exports.alwaysValidSchema = alwaysValidSchema;
  1653. function checkUnknownRules(it, schema = it.schema) {
  1654. const { opts, self } = it;
  1655. if (!opts.strict)
  1656. return;
  1657. if (typeof schema === "boolean")
  1658. return;
  1659. const rules = self.RULES.keywords;
  1660. for (const key in schema) {
  1661. if (!rules[key])
  1662. validate_1.checkStrictMode(it, `unknown keyword: "${key}"`);
  1663. }
  1664. }
  1665. exports.checkUnknownRules = checkUnknownRules;
  1666. function schemaHasRules(schema, rules) {
  1667. if (typeof schema == "boolean")
  1668. return !schema;
  1669. for (const key in schema)
  1670. if (rules[key])
  1671. return true;
  1672. return false;
  1673. }
  1674. exports.schemaHasRules = schemaHasRules;
  1675. function schemaHasRulesButRef(schema, RULES) {
  1676. if (typeof schema == "boolean")
  1677. return !schema;
  1678. for (const key in schema)
  1679. if (key !== "$ref" && RULES.all[key])
  1680. return true;
  1681. return false;
  1682. }
  1683. exports.schemaHasRulesButRef = schemaHasRulesButRef;
  1684. function schemaRefOrVal({ topSchemaRef, schemaPath }, schema, keyword, $data) {
  1685. if (!$data) {
  1686. if (typeof schema == "number" || typeof schema == "boolean")
  1687. return schema;
  1688. if (typeof schema == "string")
  1689. return codegen_1._ `${schema}`;
  1690. }
  1691. return codegen_1._ `${topSchemaRef}${schemaPath}${codegen_1.getProperty(keyword)}`;
  1692. }
  1693. exports.schemaRefOrVal = schemaRefOrVal;
  1694. function unescapeFragment(str) {
  1695. return unescapeJsonPointer(decodeURIComponent(str));
  1696. }
  1697. exports.unescapeFragment = unescapeFragment;
  1698. function escapeFragment(str) {
  1699. return encodeURIComponent(escapeJsonPointer(str));
  1700. }
  1701. exports.escapeFragment = escapeFragment;
  1702. function escapeJsonPointer(str) {
  1703. if (typeof str == "number")
  1704. return `${str}`;
  1705. return str.replace(/~/g, "~0").replace(/\//g, "~1");
  1706. }
  1707. exports.escapeJsonPointer = escapeJsonPointer;
  1708. function unescapeJsonPointer(str) {
  1709. return str.replace(/~1/g, "/").replace(/~0/g, "~");
  1710. }
  1711. exports.unescapeJsonPointer = unescapeJsonPointer;
  1712. function eachItem(xs, f) {
  1713. if (Array.isArray(xs)) {
  1714. for (const x of xs)
  1715. f(x);
  1716. }
  1717. else {
  1718. f(xs);
  1719. }
  1720. }
  1721. exports.eachItem = eachItem;
  1722. function makeMergeEvaluated({ mergeNames, mergeToName, mergeValues, resultToName, }) {
  1723. return (gen, from, to, toName) => {
  1724. const res = to === undefined
  1725. ? from
  1726. : to instanceof codegen_1.Name
  1727. ? (from instanceof codegen_1.Name ? mergeNames(gen, from, to) : mergeToName(gen, from, to), to)
  1728. : from instanceof codegen_1.Name
  1729. ? (mergeToName(gen, to, from), from)
  1730. : mergeValues(from, to);
  1731. return toName === codegen_1.Name && !(res instanceof codegen_1.Name) ? resultToName(gen, res) : res;
  1732. };
  1733. }
  1734. exports.mergeEvaluated = {
  1735. props: makeMergeEvaluated({
  1736. mergeNames: (gen, from, to) => gen.if(codegen_1._ `${to} !== true && ${from} !== undefined`, () => {
  1737. gen.if(codegen_1._ `${from} === true`, () => gen.assign(to, true), () => gen.code(codegen_1._ `Object.assign(${to}, ${from})`));
  1738. }),
  1739. mergeToName: (gen, from, to) => gen.if(codegen_1._ `${to} !== true`, () => {
  1740. if (from === true) {
  1741. gen.assign(to, true);
  1742. }
  1743. else {
  1744. gen.assign(to, codegen_1._ `${to} || {}`);
  1745. setEvaluated(gen, to, from);
  1746. }
  1747. }),
  1748. mergeValues: (from, to) => (from === true ? true : { ...from, ...to }),
  1749. resultToName: evaluatedPropsToName,
  1750. }),
  1751. items: makeMergeEvaluated({
  1752. mergeNames: (gen, from, to) => gen.if(codegen_1._ `${to} !== true && ${from} !== undefined`, () => gen.assign(to, codegen_1._ `${from} === true ? true : ${to} > ${from} ? ${to} : ${from}`)),
  1753. mergeToName: (gen, from, to) => gen.if(codegen_1._ `${to} !== true`, () => gen.assign(to, from === true ? true : codegen_1._ `${to} > ${from} ? ${to} : ${from}`)),
  1754. mergeValues: (from, to) => (from === true ? true : Math.max(from, to)),
  1755. resultToName: (gen, items) => gen.var("items", items),
  1756. }),
  1757. };
  1758. function evaluatedPropsToName(gen, ps) {
  1759. if (ps === true)
  1760. return gen.var("props", true);
  1761. const props = gen.var("props", codegen_1._ `{}`);
  1762. if (ps !== undefined)
  1763. setEvaluated(gen, props, ps);
  1764. return props;
  1765. }
  1766. exports.evaluatedPropsToName = evaluatedPropsToName;
  1767. function setEvaluated(gen, props, ps) {
  1768. Object.keys(ps).forEach((p) => gen.assign(codegen_1._ `${props}${codegen_1.getProperty(p)}`, true));
  1769. }
  1770. exports.setEvaluated = setEvaluated;
  1771. //# sourceMappingURL=util.js.map
  1772. }, function(modId) { var map = {"./codegen":1609944441822,"./validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  1773. __DEFINE__(1609944441827, function(require, module, exports) {
  1774. Object.defineProperty(exports, "__esModule", { value: true });
  1775. exports.checkStrictMode = exports.schemaCxtHasRules = exports.subschemaCode = exports.validateFunctionCode = void 0;
  1776. const boolSchema_1 = require("./boolSchema");
  1777. const dataType_1 = require("./dataType");
  1778. const iterate_1 = require("./iterate");
  1779. const codegen_1 = require("../codegen");
  1780. const names_1 = require("../names");
  1781. const resolve_1 = require("../resolve");
  1782. const util_1 = require("../util");
  1783. // schema compilation - generates validation function, subschemaCode (below) is used for subschemas
  1784. function validateFunctionCode(it) {
  1785. if (isSchemaObj(it)) {
  1786. checkKeywords(it);
  1787. if (schemaCxtHasRules(it)) {
  1788. topSchemaObjCode(it);
  1789. return;
  1790. }
  1791. }
  1792. validateFunction(it, () => boolSchema_1.topBoolOrEmptySchema(it));
  1793. }
  1794. exports.validateFunctionCode = validateFunctionCode;
  1795. function validateFunction({ gen, validateName, schema, schemaEnv, opts }, body) {
  1796. if (opts.code.es5) {
  1797. gen.func(validateName, codegen_1._ `${names_1.default.data}, ${names_1.default.valCxt}`, schemaEnv.$async, () => {
  1798. gen.code(codegen_1._ `"use strict"; ${funcSourceUrl(schema, opts)}`);
  1799. destructureValCxtES5(gen, opts);
  1800. gen.code(body);
  1801. });
  1802. }
  1803. else {
  1804. gen.func(validateName, codegen_1._ `${names_1.default.data}, ${destructureValCxt(opts)}`, schemaEnv.$async, () => gen.code(funcSourceUrl(schema, opts)).code(body));
  1805. }
  1806. }
  1807. function destructureValCxt(opts) {
  1808. return codegen_1._ `{${names_1.default.dataPath}="", ${names_1.default.parentData}, ${names_1.default.parentDataProperty}, ${names_1.default.rootData}=${names_1.default.data}${opts.dynamicRef ? codegen_1._ `, ${names_1.default.dynamicAnchors}={}` : codegen_1.nil}}={}`;
  1809. }
  1810. function destructureValCxtES5(gen, opts) {
  1811. gen.if(names_1.default.valCxt, () => {
  1812. gen.var(names_1.default.dataPath, codegen_1._ `${names_1.default.valCxt}.${names_1.default.dataPath}`);
  1813. gen.var(names_1.default.parentData, codegen_1._ `${names_1.default.valCxt}.${names_1.default.parentData}`);
  1814. gen.var(names_1.default.parentDataProperty, codegen_1._ `${names_1.default.valCxt}.${names_1.default.parentDataProperty}`);
  1815. gen.var(names_1.default.rootData, codegen_1._ `${names_1.default.valCxt}.${names_1.default.rootData}`);
  1816. if (opts.dynamicRef)
  1817. gen.var(names_1.default.dynamicAnchors, codegen_1._ `${names_1.default.valCxt}.${names_1.default.dynamicAnchors}`);
  1818. }, () => {
  1819. gen.var(names_1.default.dataPath, codegen_1._ `""`);
  1820. gen.var(names_1.default.parentData, codegen_1._ `undefined`);
  1821. gen.var(names_1.default.parentDataProperty, codegen_1._ `undefined`);
  1822. gen.var(names_1.default.rootData, names_1.default.data);
  1823. if (opts.dynamicRef)
  1824. gen.var(names_1.default.dynamicAnchors, codegen_1._ `{}`);
  1825. });
  1826. }
  1827. function topSchemaObjCode(it) {
  1828. const { schema, opts, gen } = it;
  1829. validateFunction(it, () => {
  1830. if (opts.$comment && schema.$comment)
  1831. commentKeyword(it);
  1832. checkNoDefault(it);
  1833. gen.let(names_1.default.vErrors, null);
  1834. gen.let(names_1.default.errors, 0);
  1835. if (opts.unevaluated)
  1836. resetEvaluated(it);
  1837. typeAndKeywords(it);
  1838. returnResults(it);
  1839. });
  1840. return;
  1841. }
  1842. function resetEvaluated(it) {
  1843. // TODO maybe some hook to execute it in the end to check whether props/items are Name, as in assignEvaluated
  1844. const { gen, validateName } = it;
  1845. it.evaluated = gen.const("evaluated", codegen_1._ `${validateName}.evaluated`);
  1846. gen.if(codegen_1._ `${it.evaluated}.dynamicProps`, () => gen.assign(codegen_1._ `${it.evaluated}.props`, codegen_1._ `undefined`));
  1847. gen.if(codegen_1._ `${it.evaluated}.dynamicItems`, () => gen.assign(codegen_1._ `${it.evaluated}.items`, codegen_1._ `undefined`));
  1848. }
  1849. function funcSourceUrl(schema, opts) {
  1850. return typeof schema == "object" && schema.$id && (opts.code.source || opts.code.process)
  1851. ? codegen_1._ `/*# sourceURL=${schema.$id} */`
  1852. : codegen_1.nil;
  1853. }
  1854. // schema compilation - this function is used recursively to generate code for sub-schemas
  1855. function subschemaCode(it, valid) {
  1856. if (isSchemaObj(it)) {
  1857. checkKeywords(it);
  1858. if (schemaCxtHasRules(it)) {
  1859. subSchemaObjCode(it, valid);
  1860. return;
  1861. }
  1862. }
  1863. boolSchema_1.boolOrEmptySchema(it, valid);
  1864. }
  1865. exports.subschemaCode = subschemaCode;
  1866. function schemaCxtHasRules({ schema, self }) {
  1867. if (typeof schema == "boolean")
  1868. return !schema;
  1869. for (const key in schema)
  1870. if (self.RULES.all[key])
  1871. return true;
  1872. return false;
  1873. }
  1874. exports.schemaCxtHasRules = schemaCxtHasRules;
  1875. function isSchemaObj(it) {
  1876. return typeof it.schema != "boolean";
  1877. }
  1878. function subSchemaObjCode(it, valid) {
  1879. const { schema, gen, opts } = it;
  1880. if (opts.$comment && schema.$comment)
  1881. commentKeyword(it);
  1882. updateContext(it);
  1883. checkAsync(it);
  1884. const errsCount = gen.const("_errs", names_1.default.errors);
  1885. typeAndKeywords(it, errsCount);
  1886. // TODO var
  1887. gen.var(valid, codegen_1._ `${errsCount} === ${names_1.default.errors}`);
  1888. }
  1889. function checkKeywords(it) {
  1890. util_1.checkUnknownRules(it);
  1891. checkRefsAndKeywords(it);
  1892. }
  1893. function typeAndKeywords(it, errsCount) {
  1894. const types = dataType_1.getSchemaTypes(it.schema);
  1895. const checkedTypes = dataType_1.coerceAndCheckDataType(it, types);
  1896. iterate_1.schemaKeywords(it, types, !checkedTypes, errsCount);
  1897. }
  1898. function checkRefsAndKeywords(it) {
  1899. const { schema, errSchemaPath, opts, self } = it;
  1900. if (schema.$ref && opts.ignoreKeywordsWithRef && util_1.schemaHasRulesButRef(schema, self.RULES)) {
  1901. self.logger.warn(`$ref: keywords ignored in schema at path "${errSchemaPath}"`);
  1902. }
  1903. }
  1904. function checkNoDefault(it) {
  1905. const { schema, opts } = it;
  1906. if (schema.default !== undefined && opts.useDefaults && opts.strict) {
  1907. checkStrictMode(it, "default is ignored in the schema root");
  1908. }
  1909. }
  1910. function updateContext(it) {
  1911. if (it.schema.$id)
  1912. it.baseId = resolve_1.resolveUrl(it.baseId, it.schema.$id);
  1913. }
  1914. function checkAsync(it) {
  1915. if (it.schema.$async && !it.schemaEnv.$async)
  1916. throw new Error("async schema in sync schema");
  1917. }
  1918. function commentKeyword({ gen, schemaEnv, schema, errSchemaPath, opts }) {
  1919. const msg = schema.$comment;
  1920. if (opts.$comment === true) {
  1921. gen.code(codegen_1._ `${names_1.default.self}.logger.log(${msg})`);
  1922. }
  1923. else if (typeof opts.$comment == "function") {
  1924. const schemaPath = codegen_1.str `${errSchemaPath}/$comment`;
  1925. const rootName = gen.scopeValue("root", { ref: schemaEnv.root });
  1926. gen.code(codegen_1._ `${names_1.default.self}.opts.$comment(${msg}, ${schemaPath}, ${rootName}.schema)`);
  1927. }
  1928. }
  1929. function returnResults(it) {
  1930. const { gen, schemaEnv, validateName, ValidationError, opts } = it;
  1931. if (schemaEnv.$async) {
  1932. // TODO assign unevaluated
  1933. gen.if(codegen_1._ `${names_1.default.errors} === 0`, () => gen.return(names_1.default.data), () => gen.throw(codegen_1._ `new ${ValidationError}(${names_1.default.vErrors})`));
  1934. }
  1935. else {
  1936. gen.assign(codegen_1._ `${validateName}.errors`, names_1.default.vErrors);
  1937. if (opts.unevaluated)
  1938. assignEvaluated(it);
  1939. gen.return(codegen_1._ `${names_1.default.errors} === 0`);
  1940. }
  1941. }
  1942. function assignEvaluated({ gen, evaluated, props, items }) {
  1943. if (props instanceof codegen_1.Name)
  1944. gen.assign(codegen_1._ `${evaluated}.props`, props);
  1945. if (items instanceof codegen_1.Name)
  1946. gen.assign(codegen_1._ `${evaluated}.items`, items);
  1947. }
  1948. function checkStrictMode(it, msg, mode = it.opts.strict) {
  1949. if (!mode)
  1950. return;
  1951. msg = `strict mode: ${msg}`;
  1952. if (mode === true)
  1953. throw new Error(msg);
  1954. it.self.logger.warn(msg);
  1955. }
  1956. exports.checkStrictMode = checkStrictMode;
  1957. //# sourceMappingURL=index.js.map
  1958. }, function(modId) { var map = {"./boolSchema":1609944441828,"./dataType":1609944441818,"./iterate":1609944441829,"../codegen":1609944441822,"../names":1609944441825,"../resolve":1609944441833,"../util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  1959. __DEFINE__(1609944441828, function(require, module, exports) {
  1960. Object.defineProperty(exports, "__esModule", { value: true });
  1961. exports.boolOrEmptySchema = exports.topBoolOrEmptySchema = void 0;
  1962. const errors_1 = require("../errors");
  1963. const codegen_1 = require("../codegen");
  1964. const names_1 = require("../names");
  1965. const boolError = {
  1966. message: "boolean schema is false",
  1967. };
  1968. function topBoolOrEmptySchema(it) {
  1969. const { gen, schema, validateName } = it;
  1970. if (schema === false) {
  1971. falseSchemaError(it, false);
  1972. }
  1973. else if (typeof schema == "object" && schema.$async === true) {
  1974. gen.return(names_1.default.data);
  1975. }
  1976. else {
  1977. gen.assign(codegen_1._ `${validateName}.errors`, null);
  1978. gen.return(true);
  1979. }
  1980. }
  1981. exports.topBoolOrEmptySchema = topBoolOrEmptySchema;
  1982. function boolOrEmptySchema(it, valid) {
  1983. const { gen, schema } = it;
  1984. if (schema === false) {
  1985. gen.var(valid, false); // TODO var
  1986. falseSchemaError(it);
  1987. }
  1988. else {
  1989. gen.var(valid, true); // TODO var
  1990. }
  1991. }
  1992. exports.boolOrEmptySchema = boolOrEmptySchema;
  1993. function falseSchemaError(it, overrideAllErrors) {
  1994. const { gen, data } = it;
  1995. // TODO maybe some other interface should be used for non-keyword validation errors...
  1996. const cxt = {
  1997. gen,
  1998. keyword: "false schema",
  1999. data,
  2000. schema: false,
  2001. schemaCode: false,
  2002. schemaValue: false,
  2003. params: {},
  2004. it,
  2005. };
  2006. errors_1.reportError(cxt, boolError, overrideAllErrors);
  2007. }
  2008. //# sourceMappingURL=boolSchema.js.map
  2009. }, function(modId) { var map = {"../errors":1609944441821,"../codegen":1609944441822,"../names":1609944441825}; return __REQUIRE__(map[modId], modId); })
  2010. __DEFINE__(1609944441829, function(require, module, exports) {
  2011. Object.defineProperty(exports, "__esModule", { value: true });
  2012. exports.schemaKeywords = void 0;
  2013. const applicability_1 = require("./applicability");
  2014. const dataType_1 = require("./dataType");
  2015. const defaults_1 = require("./defaults");
  2016. const keyword_1 = require("./keyword");
  2017. const util_1 = require("../util");
  2018. const _1 = require(".");
  2019. const codegen_1 = require("../codegen");
  2020. const names_1 = require("../names");
  2021. function schemaKeywords(it, types, typeErrors, errsCount) {
  2022. const { gen, schema, data, allErrors, opts, self } = it;
  2023. const { RULES } = self;
  2024. if (schema.$ref && (opts.ignoreKeywordsWithRef || !util_1.schemaHasRulesButRef(schema, RULES))) {
  2025. gen.block(() => keyword_1.keywordCode(it, "$ref", RULES.all.$ref.definition)); // TODO typecast
  2026. return;
  2027. }
  2028. checkStrictTypes(it, types);
  2029. gen.block(() => {
  2030. for (const group of RULES.rules)
  2031. groupKeywords(group);
  2032. groupKeywords(RULES.post);
  2033. });
  2034. function groupKeywords(group) {
  2035. if (!applicability_1.shouldUseGroup(schema, group))
  2036. return;
  2037. if (group.type) {
  2038. gen.if(dataType_1.checkDataType(group.type, data, opts.strict));
  2039. iterateKeywords(it, group);
  2040. if (types.length === 1 && types[0] === group.type && typeErrors) {
  2041. gen.else();
  2042. dataType_1.reportTypeError(it);
  2043. }
  2044. gen.endIf();
  2045. }
  2046. else {
  2047. iterateKeywords(it, group);
  2048. }
  2049. // TODO make it "ok" call?
  2050. if (!allErrors)
  2051. gen.if(codegen_1._ `${names_1.default.errors} === ${errsCount || 0}`);
  2052. }
  2053. }
  2054. exports.schemaKeywords = schemaKeywords;
  2055. function iterateKeywords(it, group) {
  2056. const { gen, schema, opts: { useDefaults }, } = it;
  2057. if (useDefaults)
  2058. defaults_1.assignDefaults(it, group.type);
  2059. gen.block(() => {
  2060. for (const rule of group.rules) {
  2061. if (applicability_1.shouldUseRule(schema, rule)) {
  2062. keyword_1.keywordCode(it, rule.keyword, rule.definition, group.type);
  2063. }
  2064. }
  2065. });
  2066. }
  2067. function checkStrictTypes(it, types) {
  2068. if (it.schemaEnv.meta || !it.opts.strictTypes)
  2069. return;
  2070. checkContextTypes(it, types);
  2071. if (!it.opts.allowUnionTypes)
  2072. checkMultipleTypes(it, types);
  2073. checkKeywordTypes(it, it.dataTypes);
  2074. }
  2075. function checkContextTypes(it, types) {
  2076. if (!types.length)
  2077. return;
  2078. if (!it.dataTypes.length) {
  2079. it.dataTypes = types;
  2080. return;
  2081. }
  2082. types.forEach((t) => {
  2083. if (!includesType(it.dataTypes, t)) {
  2084. strictTypesError(it, `type "${t}" not allowed by context "${it.dataTypes.join(",")}"`);
  2085. }
  2086. });
  2087. it.dataTypes = it.dataTypes.filter((t) => includesType(types, t));
  2088. }
  2089. function checkMultipleTypes(it, ts) {
  2090. if (ts.length > 1 && !(ts.length === 2 && ts.includes("null"))) {
  2091. strictTypesError(it, "use allowUnionTypes to allow union type keyword");
  2092. }
  2093. }
  2094. function checkKeywordTypes(it, ts) {
  2095. const rules = it.self.RULES.all;
  2096. for (const keyword in rules) {
  2097. const rule = rules[keyword];
  2098. if (typeof rule == "object" && applicability_1.shouldUseRule(it.schema, rule)) {
  2099. const { type } = rule.definition;
  2100. if (type.length && !type.some((t) => hasApplicableType(ts, t))) {
  2101. strictTypesError(it, `missing type "${type.join(",")}" for keyword "${keyword}"`);
  2102. }
  2103. }
  2104. }
  2105. }
  2106. function hasApplicableType(schTs, kwdT) {
  2107. return schTs.includes(kwdT) || (kwdT === "number" && schTs.includes("integer"));
  2108. }
  2109. function includesType(ts, t) {
  2110. return ts.includes(t) || (t === "integer" && ts.includes("number"));
  2111. }
  2112. function strictTypesError(it, msg) {
  2113. const schemaPath = it.schemaEnv.baseId + it.errSchemaPath;
  2114. msg += ` at "${schemaPath}" (strictTypes)`;
  2115. _1.checkStrictMode(it, msg, it.opts.strictTypes);
  2116. }
  2117. //# sourceMappingURL=iterate.js.map
  2118. }, function(modId) { var map = {"./applicability":1609944441820,"./dataType":1609944441818,"./defaults":1609944441830,"./keyword":1609944441831,"../util":1609944441826,".":1609944441827,"../codegen":1609944441822,"../names":1609944441825}; return __REQUIRE__(map[modId], modId); })
  2119. __DEFINE__(1609944441830, function(require, module, exports) {
  2120. Object.defineProperty(exports, "__esModule", { value: true });
  2121. exports.assignDefaults = void 0;
  2122. const codegen_1 = require("../codegen");
  2123. const _1 = require(".");
  2124. function assignDefaults(it, ty) {
  2125. const { properties, items } = it.schema;
  2126. if (ty === "object" && properties) {
  2127. for (const key in properties) {
  2128. assignDefault(it, key, properties[key].default);
  2129. }
  2130. }
  2131. else if (ty === "array" && Array.isArray(items)) {
  2132. items.forEach((sch, i) => assignDefault(it, i, sch.default));
  2133. }
  2134. }
  2135. exports.assignDefaults = assignDefaults;
  2136. function assignDefault(it, prop, defaultValue) {
  2137. const { gen, compositeRule, data, opts } = it;
  2138. if (defaultValue === undefined)
  2139. return;
  2140. const childData = codegen_1._ `${data}${codegen_1.getProperty(prop)}`;
  2141. if (compositeRule) {
  2142. _1.checkStrictMode(it, `default is ignored for: ${childData}`);
  2143. return;
  2144. }
  2145. let condition = codegen_1._ `${childData} === undefined`;
  2146. if (opts.useDefaults === "empty") {
  2147. condition = codegen_1._ `${condition} || ${childData} === null || ${childData} === ""`;
  2148. }
  2149. // `${childData} === undefined` +
  2150. // (opts.useDefaults === "empty" ? ` || ${childData} === null || ${childData} === ""` : "")
  2151. gen.if(condition, codegen_1._ `${childData} = ${codegen_1.stringify(defaultValue)}`);
  2152. }
  2153. //# sourceMappingURL=defaults.js.map
  2154. }, function(modId) { var map = {"../codegen":1609944441822,".":1609944441827}; return __REQUIRE__(map[modId], modId); })
  2155. __DEFINE__(1609944441831, function(require, module, exports) {
  2156. Object.defineProperty(exports, "__esModule", { value: true });
  2157. exports.keywordCode = void 0;
  2158. const context_1 = require("../context");
  2159. const errors_1 = require("../errors");
  2160. const code_1 = require("../../vocabularies/code");
  2161. const codegen_1 = require("../codegen");
  2162. const names_1 = require("../names");
  2163. function keywordCode(it, keyword, def, ruleType) {
  2164. const cxt = new context_1.default(it, def, keyword);
  2165. if ("code" in def) {
  2166. def.code(cxt, ruleType);
  2167. }
  2168. else if (cxt.$data && def.validate) {
  2169. funcKeywordCode(cxt, def);
  2170. }
  2171. else if ("macro" in def) {
  2172. macroKeywordCode(cxt, def);
  2173. }
  2174. else if (def.compile || def.validate) {
  2175. funcKeywordCode(cxt, def);
  2176. }
  2177. }
  2178. exports.keywordCode = keywordCode;
  2179. function macroKeywordCode(cxt, def) {
  2180. const { gen, keyword, schema, parentSchema, it } = cxt;
  2181. const macroSchema = def.macro.call(it.self, schema, parentSchema, it);
  2182. const schemaRef = useKeyword(gen, keyword, macroSchema);
  2183. if (it.opts.validateSchema !== false)
  2184. it.self.validateSchema(macroSchema, true);
  2185. const valid = gen.name("valid");
  2186. cxt.subschema({
  2187. schema: macroSchema,
  2188. schemaPath: codegen_1.nil,
  2189. errSchemaPath: `${it.errSchemaPath}/${keyword}`,
  2190. topSchemaRef: schemaRef,
  2191. compositeRule: true,
  2192. }, valid);
  2193. cxt.pass(valid, () => cxt.error(true));
  2194. }
  2195. function funcKeywordCode(cxt, def) {
  2196. var _a;
  2197. const { gen, keyword, schema, parentSchema, $data, it } = cxt;
  2198. checkAsync(it, def);
  2199. const validate = !$data && def.compile ? def.compile.call(it.self, schema, parentSchema, it) : def.validate;
  2200. const validateRef = useKeyword(gen, keyword, validate);
  2201. const valid = gen.let("valid");
  2202. cxt.block$data(valid, validateKeyword);
  2203. cxt.ok((_a = def.valid) !== null && _a !== void 0 ? _a : valid);
  2204. function validateKeyword() {
  2205. if (def.errors === false) {
  2206. assignValid();
  2207. if (def.modifying)
  2208. modifyData(cxt);
  2209. reportErrs(() => cxt.error());
  2210. }
  2211. else {
  2212. const ruleErrs = def.async ? validateAsync() : validateSync();
  2213. if (def.modifying)
  2214. modifyData(cxt);
  2215. reportErrs(() => addErrs(cxt, ruleErrs));
  2216. }
  2217. }
  2218. function validateAsync() {
  2219. const ruleErrs = gen.let("ruleErrs", null);
  2220. gen.try(() => assignValid(codegen_1._ `await `), (e) => gen.assign(valid, false).if(codegen_1._ `${e} instanceof ${it.ValidationError}`, () => gen.assign(ruleErrs, codegen_1._ `${e}.errors`), () => gen.throw(e)));
  2221. return ruleErrs;
  2222. }
  2223. function validateSync() {
  2224. const validateErrs = codegen_1._ `${validateRef}.errors`;
  2225. gen.assign(validateErrs, null);
  2226. assignValid(codegen_1.nil);
  2227. return validateErrs;
  2228. }
  2229. function assignValid(_await = def.async ? codegen_1._ `await ` : codegen_1.nil) {
  2230. const passCxt = it.opts.passContext ? names_1.default.this : names_1.default.self;
  2231. const passSchema = !(("compile" in def && !$data) || def.schema === false);
  2232. gen.assign(valid, codegen_1._ `${_await}${code_1.callValidateCode(cxt, validateRef, passCxt, passSchema)}`, def.modifying);
  2233. }
  2234. function reportErrs(errors) {
  2235. var _a;
  2236. gen.if(codegen_1.not((_a = def.valid) !== null && _a !== void 0 ? _a : valid), errors);
  2237. }
  2238. }
  2239. function modifyData(cxt) {
  2240. const { gen, data, it } = cxt;
  2241. gen.if(it.parentData, () => gen.assign(data, codegen_1._ `${it.parentData}[${it.parentDataProperty}]`));
  2242. }
  2243. function addErrs(cxt, errs) {
  2244. const { gen } = cxt;
  2245. gen.if(codegen_1._ `Array.isArray(${errs})`, () => {
  2246. gen
  2247. .assign(names_1.default.vErrors, codegen_1._ `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`)
  2248. .assign(names_1.default.errors, codegen_1._ `${names_1.default.vErrors}.length`);
  2249. errors_1.extendErrors(cxt);
  2250. }, () => cxt.error());
  2251. }
  2252. function checkAsync({ schemaEnv }, def) {
  2253. if (def.async && !schemaEnv.$async)
  2254. throw new Error("async keyword in sync schema");
  2255. }
  2256. function useKeyword(gen, keyword, result) {
  2257. if (result === undefined)
  2258. throw new Error(`keyword "${keyword}" failed to compile`);
  2259. return gen.scopeValue("keyword", typeof result == "function" ? { ref: result } : { ref: result, code: codegen_1.stringify(result) });
  2260. }
  2261. //# sourceMappingURL=keyword.js.map
  2262. }, function(modId) { var map = {"../context":1609944441817,"../errors":1609944441821,"../../vocabularies/code":1609944441832,"../codegen":1609944441822,"../names":1609944441825}; return __REQUIRE__(map[modId], modId); })
  2263. __DEFINE__(1609944441832, function(require, module, exports) {
  2264. Object.defineProperty(exports, "__esModule", { value: true });
  2265. exports.usePattern = exports.callValidateCode = exports.schemaProperties = exports.allSchemaProperties = exports.noPropertyInData = exports.propertyInData = exports.reportMissingProp = exports.checkMissingProp = exports.checkReportMissingProp = void 0;
  2266. const codegen_1 = require("../compile/codegen");
  2267. const util_1 = require("../compile/util");
  2268. const names_1 = require("../compile/names");
  2269. function checkReportMissingProp(cxt, prop) {
  2270. const { gen, data, it } = cxt;
  2271. gen.if(noPropertyInData(data, prop, it.opts.ownProperties), () => {
  2272. cxt.setParams({ missingProperty: codegen_1._ `${prop}` }, true);
  2273. cxt.error();
  2274. });
  2275. }
  2276. exports.checkReportMissingProp = checkReportMissingProp;
  2277. function checkMissingProp({ data, it: { opts } }, properties, missing) {
  2278. return codegen_1.or(...properties.map((prop) => codegen_1._ `${noPropertyInData(data, prop, opts.ownProperties)} && (${missing} = ${prop})`));
  2279. }
  2280. exports.checkMissingProp = checkMissingProp;
  2281. function reportMissingProp(cxt, missing) {
  2282. cxt.setParams({ missingProperty: missing }, true);
  2283. cxt.error();
  2284. }
  2285. exports.reportMissingProp = reportMissingProp;
  2286. function isOwnProperty(data, property) {
  2287. return codegen_1._ `Object.prototype.hasOwnProperty.call(${data}, ${property})`;
  2288. }
  2289. function propertyInData(data, property, ownProperties) {
  2290. const cond = codegen_1._ `${data}${codegen_1.getProperty(property)} !== undefined`;
  2291. return ownProperties ? codegen_1._ `${cond} && ${isOwnProperty(data, property)}` : cond;
  2292. }
  2293. exports.propertyInData = propertyInData;
  2294. function noPropertyInData(data, property, ownProperties) {
  2295. const cond = codegen_1._ `${data}${codegen_1.getProperty(property)} === undefined`;
  2296. return ownProperties ? codegen_1._ `${cond} || !${isOwnProperty(data, property)}` : cond;
  2297. }
  2298. exports.noPropertyInData = noPropertyInData;
  2299. function allSchemaProperties(schemaMap) {
  2300. return schemaMap ? Object.keys(schemaMap).filter((p) => p !== "__proto__") : [];
  2301. }
  2302. exports.allSchemaProperties = allSchemaProperties;
  2303. function schemaProperties(it, schemaMap) {
  2304. return allSchemaProperties(schemaMap).filter((p) => !util_1.alwaysValidSchema(it, schemaMap[p]));
  2305. }
  2306. exports.schemaProperties = schemaProperties;
  2307. function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPath, errorPath }, it }, func, context, passSchema) {
  2308. const dataAndSchema = passSchema ? codegen_1._ `${schemaCode}, ${data}, ${topSchemaRef}${schemaPath}` : data;
  2309. const valCxt = [
  2310. [names_1.default.dataPath, codegen_1.strConcat(names_1.default.dataPath, errorPath)],
  2311. [names_1.default.parentData, it.parentData],
  2312. [names_1.default.parentDataProperty, it.parentDataProperty],
  2313. [names_1.default.rootData, names_1.default.rootData],
  2314. ];
  2315. if (it.opts.dynamicRef)
  2316. valCxt.push([names_1.default.dynamicAnchors, names_1.default.dynamicAnchors]);
  2317. const args = codegen_1._ `${dataAndSchema}, ${gen.object(...valCxt)}`;
  2318. return context !== codegen_1.nil ? codegen_1._ `${func}.call(${context}, ${args})` : codegen_1._ `${func}(${args})`;
  2319. }
  2320. exports.callValidateCode = callValidateCode;
  2321. function usePattern(gen, pattern) {
  2322. return gen.scopeValue("pattern", {
  2323. key: pattern,
  2324. ref: new RegExp(pattern, "u"),
  2325. code: codegen_1._ `new RegExp(${pattern}, "u")`,
  2326. });
  2327. }
  2328. exports.usePattern = usePattern;
  2329. //# sourceMappingURL=code.js.map
  2330. }, function(modId) { var map = {"../compile/codegen":1609944441822,"../compile/util":1609944441826,"../compile/names":1609944441825}; return __REQUIRE__(map[modId], modId); })
  2331. __DEFINE__(1609944441833, function(require, module, exports) {
  2332. Object.defineProperty(exports, "__esModule", { value: true });
  2333. exports.getSchemaRefs = exports.resolveUrl = exports.normalizeId = exports._getFullPath = exports.getFullPath = exports.inlineRef = void 0;
  2334. const util_1 = require("./util");
  2335. const equal = require("fast-deep-equal");
  2336. const traverse = require("json-schema-traverse");
  2337. const URI = require("uri-js");
  2338. // TODO refactor to use keyword definitions
  2339. const SIMPLE_INLINED = new Set([
  2340. "type",
  2341. "format",
  2342. "pattern",
  2343. "maxLength",
  2344. "minLength",
  2345. "maxProperties",
  2346. "minProperties",
  2347. "maxItems",
  2348. "minItems",
  2349. "maximum",
  2350. "minimum",
  2351. "uniqueItems",
  2352. "multipleOf",
  2353. "required",
  2354. "enum",
  2355. "const",
  2356. ]);
  2357. function inlineRef(schema, limit = true) {
  2358. if (typeof schema == "boolean")
  2359. return true;
  2360. if (limit === true)
  2361. return !hasRef(schema);
  2362. if (!limit)
  2363. return false;
  2364. return countKeys(schema) <= limit;
  2365. }
  2366. exports.inlineRef = inlineRef;
  2367. const REF_KEYWORDS = new Set([
  2368. "$ref",
  2369. "$recursiveRef",
  2370. "$recursiveAnchor",
  2371. "$dynamicRef",
  2372. "$dynamicAnchor",
  2373. ]);
  2374. function hasRef(schema) {
  2375. for (const key in schema) {
  2376. if (REF_KEYWORDS.has(key))
  2377. return true;
  2378. const sch = schema[key];
  2379. if (Array.isArray(sch) && sch.some(hasRef))
  2380. return true;
  2381. if (typeof sch == "object" && hasRef(sch))
  2382. return true;
  2383. }
  2384. return false;
  2385. }
  2386. function countKeys(schema) {
  2387. let count = 0;
  2388. for (const key in schema) {
  2389. if (key === "$ref")
  2390. return Infinity;
  2391. count++;
  2392. if (SIMPLE_INLINED.has(key))
  2393. continue;
  2394. if (typeof schema[key] == "object") {
  2395. util_1.eachItem(schema[key], (sch) => (count += countKeys(sch)));
  2396. }
  2397. if (count === Infinity)
  2398. return Infinity;
  2399. }
  2400. return count;
  2401. }
  2402. function getFullPath(id = "", normalize) {
  2403. if (normalize !== false)
  2404. id = normalizeId(id);
  2405. const p = URI.parse(id);
  2406. return _getFullPath(p);
  2407. }
  2408. exports.getFullPath = getFullPath;
  2409. function _getFullPath(p) {
  2410. return URI.serialize(p).split("#")[0] + "#";
  2411. }
  2412. exports._getFullPath = _getFullPath;
  2413. const TRAILING_SLASH_HASH = /#\/?$/;
  2414. function normalizeId(id) {
  2415. return id ? id.replace(TRAILING_SLASH_HASH, "") : "";
  2416. }
  2417. exports.normalizeId = normalizeId;
  2418. function resolveUrl(baseId, id) {
  2419. id = normalizeId(id);
  2420. return URI.resolve(baseId, id);
  2421. }
  2422. exports.resolveUrl = resolveUrl;
  2423. const ANCHOR = /^[a-z_][-a-z0-9._]*$/i;
  2424. function getSchemaRefs(schema) {
  2425. if (typeof schema == "boolean")
  2426. return {};
  2427. const schemaId = normalizeId(schema.$id);
  2428. const baseIds = { "": schemaId };
  2429. const pathPrefix = getFullPath(schemaId, false);
  2430. const localRefs = {};
  2431. const schemaRefs = new Set();
  2432. traverse(schema, { allKeys: true }, (sch, jsonPtr, _, parentJsonPtr) => {
  2433. if (parentJsonPtr === undefined)
  2434. return;
  2435. const fullPath = pathPrefix + jsonPtr;
  2436. let baseId = baseIds[parentJsonPtr];
  2437. if (typeof sch.$id == "string")
  2438. baseId = addRef.call(this, sch.$id);
  2439. addAnchor.call(this, sch.$anchor);
  2440. addAnchor.call(this, sch.$dynamicAnchor);
  2441. baseIds[jsonPtr] = baseId;
  2442. function addRef(ref) {
  2443. ref = normalizeId(baseId ? URI.resolve(baseId, ref) : ref);
  2444. if (schemaRefs.has(ref))
  2445. throw ambiguos(ref);
  2446. schemaRefs.add(ref);
  2447. let schOrRef = this.refs[ref];
  2448. if (typeof schOrRef == "string")
  2449. schOrRef = this.refs[schOrRef];
  2450. if (typeof schOrRef == "object") {
  2451. checkAmbiguosRef(sch, schOrRef.schema, ref);
  2452. }
  2453. else if (ref !== normalizeId(fullPath)) {
  2454. if (ref[0] === "#") {
  2455. checkAmbiguosRef(sch, localRefs[ref], ref);
  2456. localRefs[ref] = sch;
  2457. }
  2458. else {
  2459. this.refs[ref] = fullPath;
  2460. }
  2461. }
  2462. return ref;
  2463. }
  2464. function addAnchor(anchor) {
  2465. if (typeof anchor == "string") {
  2466. if (!ANCHOR.test(anchor))
  2467. throw new Error(`invalid anchor "${anchor}"`);
  2468. addRef.call(this, `#${anchor}`);
  2469. }
  2470. }
  2471. });
  2472. return localRefs;
  2473. function checkAmbiguosRef(sch1, sch2, ref) {
  2474. if (sch2 !== undefined && !equal(sch1, sch2))
  2475. throw ambiguos(ref);
  2476. }
  2477. function ambiguos(ref) {
  2478. return new Error(`reference "${ref}" resolves to more than one schema`);
  2479. }
  2480. }
  2481. exports.getSchemaRefs = getSchemaRefs;
  2482. //# sourceMappingURL=resolve.js.map
  2483. }, function(modId) { var map = {"./util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  2484. __DEFINE__(1609944441834, function(require, module, exports) {
  2485. Object.defineProperty(exports, "__esModule", { value: true });
  2486. exports.applySubschema = exports.Type = void 0;
  2487. const validate_1 = require("./validate");
  2488. const util_1 = require("./util");
  2489. const codegen_1 = require("./codegen");
  2490. var Type;
  2491. (function (Type) {
  2492. Type[Type["Num"] = 0] = "Num";
  2493. Type[Type["Str"] = 1] = "Str";
  2494. })(Type = exports.Type || (exports.Type = {}));
  2495. function applySubschema(it, appl, valid) {
  2496. const subschema = getSubschema(it, appl);
  2497. extendSubschemaData(subschema, it, appl);
  2498. extendSubschemaMode(subschema, appl);
  2499. const nextContext = { ...it, ...subschema, items: undefined, props: undefined };
  2500. validate_1.subschemaCode(nextContext, valid);
  2501. return nextContext;
  2502. }
  2503. exports.applySubschema = applySubschema;
  2504. function getSubschema(it, { keyword, schemaProp, schema, strictSchema, schemaPath, errSchemaPath, topSchemaRef, }) {
  2505. if (keyword !== undefined && schema !== undefined) {
  2506. throw new Error('both "keyword" and "schema" passed, only one allowed');
  2507. }
  2508. if (keyword !== undefined) {
  2509. const sch = it.schema[keyword];
  2510. return schemaProp === undefined
  2511. ? {
  2512. schema: sch,
  2513. schemaPath: codegen_1._ `${it.schemaPath}${codegen_1.getProperty(keyword)}`,
  2514. errSchemaPath: `${it.errSchemaPath}/${keyword}`,
  2515. }
  2516. : {
  2517. schema: sch[schemaProp],
  2518. schemaPath: codegen_1._ `${it.schemaPath}${codegen_1.getProperty(keyword)}${codegen_1.getProperty(schemaProp)}`,
  2519. errSchemaPath: `${it.errSchemaPath}/${keyword}/${util_1.escapeFragment(schemaProp)}`,
  2520. };
  2521. }
  2522. if (schema !== undefined) {
  2523. if (schemaPath === undefined || errSchemaPath === undefined || topSchemaRef === undefined) {
  2524. throw new Error('"schemaPath", "errSchemaPath" and "topSchemaRef" are required with "schema"');
  2525. }
  2526. return {
  2527. schema,
  2528. strictSchema,
  2529. schemaPath,
  2530. topSchemaRef,
  2531. errSchemaPath,
  2532. };
  2533. }
  2534. throw new Error('either "keyword" or "schema" must be passed');
  2535. }
  2536. function extendSubschemaData(subschema, it, { dataProp, dataPropType: dpType, data, dataTypes, propertyName }) {
  2537. if (data !== undefined && dataProp !== undefined) {
  2538. throw new Error('both "data" and "dataProp" passed, only one allowed');
  2539. }
  2540. const { gen } = it;
  2541. if (dataProp !== undefined) {
  2542. const { errorPath, dataPathArr, opts } = it;
  2543. const nextData = gen.let("data", codegen_1._ `${it.data}${codegen_1.getProperty(dataProp)}`, true);
  2544. dataContextProps(nextData);
  2545. subschema.errorPath = codegen_1.str `${errorPath}${getErrorPath(dataProp, dpType, opts.jsPropertySyntax)}`;
  2546. subschema.parentDataProperty = codegen_1._ `${dataProp}`;
  2547. subschema.dataPathArr = [...dataPathArr, subschema.parentDataProperty];
  2548. }
  2549. if (data !== undefined) {
  2550. const nextData = data instanceof codegen_1.Name ? data : gen.let("data", data, true); // replaceable if used once?
  2551. dataContextProps(nextData);
  2552. if (propertyName !== undefined)
  2553. subschema.propertyName = propertyName;
  2554. // TODO something is possibly wrong here with not changing parentDataProperty and not appending dataPathArr
  2555. }
  2556. if (dataTypes)
  2557. subschema.dataTypes = dataTypes;
  2558. function dataContextProps(_nextData) {
  2559. subschema.data = _nextData;
  2560. subschema.dataLevel = it.dataLevel + 1;
  2561. subschema.dataTypes = [];
  2562. subschema.parentData = it.data;
  2563. subschema.dataNames = [...it.dataNames, _nextData];
  2564. }
  2565. }
  2566. function extendSubschemaMode(subschema, { compositeRule, createErrors, allErrors, strictSchema }) {
  2567. if (compositeRule !== undefined)
  2568. subschema.compositeRule = compositeRule;
  2569. if (createErrors !== undefined)
  2570. subschema.createErrors = createErrors;
  2571. if (allErrors !== undefined)
  2572. subschema.allErrors = allErrors;
  2573. subschema.strictSchema = strictSchema; // not inherited
  2574. }
  2575. function getErrorPath(dataProp, dataPropType, jsPropertySyntax) {
  2576. // let path
  2577. if (dataProp instanceof codegen_1.Name) {
  2578. const isNumber = dataPropType === Type.Num;
  2579. return jsPropertySyntax
  2580. ? isNumber
  2581. ? codegen_1._ `"[" + ${dataProp} + "]"`
  2582. : codegen_1._ `"['" + ${dataProp} + "']"`
  2583. : isNumber
  2584. ? codegen_1._ `"/" + ${dataProp}`
  2585. : codegen_1._ `"/" + ${dataProp}.replace(/~/g, "~0").replace(/\\//g, "~1")`; // TODO maybe use global escapePointer
  2586. }
  2587. return jsPropertySyntax ? codegen_1.getProperty(dataProp).toString() : "/" + util_1.escapeJsonPointer(dataProp);
  2588. }
  2589. //# sourceMappingURL=subschema.js.map
  2590. }, function(modId) { var map = {"./validate":1609944441827,"./util":1609944441826,"./codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  2591. __DEFINE__(1609944441835, function(require, module, exports) {
  2592. Object.defineProperty(exports, "__esModule", { value: true });
  2593. exports.CodeGen = exports.Name = exports.nil = exports.stringify = exports.str = exports._ = exports.KeywordCxt = void 0;
  2594. const context_1 = require("./compile/context");
  2595. exports.KeywordCxt = context_1.default;
  2596. var codegen_1 = require("./compile/codegen");
  2597. Object.defineProperty(exports, "_", { enumerable: true, get: function () { return codegen_1._; } });
  2598. Object.defineProperty(exports, "str", { enumerable: true, get: function () { return codegen_1.str; } });
  2599. Object.defineProperty(exports, "stringify", { enumerable: true, get: function () { return codegen_1.stringify; } });
  2600. Object.defineProperty(exports, "nil", { enumerable: true, get: function () { return codegen_1.nil; } });
  2601. Object.defineProperty(exports, "Name", { enumerable: true, get: function () { return codegen_1.Name; } });
  2602. Object.defineProperty(exports, "CodeGen", { enumerable: true, get: function () { return codegen_1.CodeGen; } });
  2603. const error_classes_1 = require("./compile/error_classes");
  2604. const rules_1 = require("./compile/rules");
  2605. const compile_1 = require("./compile");
  2606. const codegen_2 = require("./compile/codegen");
  2607. const resolve_1 = require("./compile/resolve");
  2608. const dataType_1 = require("./compile/validate/dataType");
  2609. const util_1 = require("./compile/util");
  2610. const $dataRefSchema = require("./refs/data.json");
  2611. const META_IGNORE_OPTIONS = ["removeAdditional", "useDefaults", "coerceTypes"];
  2612. const EXT_SCOPE_NAMES = new Set([
  2613. "validate",
  2614. "wrapper",
  2615. "root",
  2616. "schema",
  2617. "keyword",
  2618. "pattern",
  2619. "formats",
  2620. "validate$data",
  2621. "func",
  2622. "obj",
  2623. "Error",
  2624. ]);
  2625. const removedOptions = {
  2626. errorDataPath: "",
  2627. format: "`validateFormats: false` can be used instead.",
  2628. nullable: '"nullable" keyword is supported by default.',
  2629. jsonPointers: "Deprecated jsPropertySyntax can be used instead.",
  2630. extendRefs: "Deprecated ignoreKeywordsWithRef can be used instead.",
  2631. missingRefs: "Pass empty schema with $id that should be ignored to ajv.addSchema.",
  2632. processCode: "Use option `code: {process: (code, schemaEnv: object) => string}`",
  2633. sourceCode: "Use option `code: {source: true}`",
  2634. schemaId: "JSON Schema draft-04 is not supported in Ajv v7.",
  2635. strictDefaults: "It is default now, see option `strict`.",
  2636. strictKeywords: "It is default now, see option `strict`.",
  2637. strictNumbers: "It is default now, see option `strict`.",
  2638. uniqueItems: '"uniqueItems" keyword is always validated.',
  2639. unknownFormats: "Disable strict mode or pass `true` to `ajv.addFormat` (or `formats` option).",
  2640. cache: "Map is used as cache, schema object as key.",
  2641. serialize: "Map is used as cache, schema object as key.",
  2642. };
  2643. const deprecatedOptions = {
  2644. ignoreKeywordsWithRef: "",
  2645. jsPropertySyntax: "",
  2646. unicode: '"minLength"/"maxLength" account for unicode characters by default.',
  2647. };
  2648. function requiredOptions(o) {
  2649. var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
  2650. const strict = (_a = o.strict) !== null && _a !== void 0 ? _a : true;
  2651. const strictLog = strict ? "log" : false;
  2652. const _optz = (_b = o.code) === null || _b === void 0 ? void 0 : _b.optimize;
  2653. const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0;
  2654. return {
  2655. strict,
  2656. strictTypes: (_c = o.strictTypes) !== null && _c !== void 0 ? _c : strictLog,
  2657. strictTuples: (_d = o.strictTuples) !== null && _d !== void 0 ? _d : strictLog,
  2658. code: o.code ? { ...o.code, optimize } : { optimize },
  2659. loopRequired: (_e = o.loopRequired) !== null && _e !== void 0 ? _e : Infinity,
  2660. loopEnum: (_f = o.loopEnum) !== null && _f !== void 0 ? _f : Infinity,
  2661. meta: (_g = o.meta) !== null && _g !== void 0 ? _g : true,
  2662. messages: (_h = o.messages) !== null && _h !== void 0 ? _h : true,
  2663. inlineRefs: (_j = o.inlineRefs) !== null && _j !== void 0 ? _j : true,
  2664. addUsedSchema: (_k = o.addUsedSchema) !== null && _k !== void 0 ? _k : true,
  2665. validateSchema: (_l = o.validateSchema) !== null && _l !== void 0 ? _l : true,
  2666. validateFormats: (_m = o.validateFormats) !== null && _m !== void 0 ? _m : true,
  2667. };
  2668. }
  2669. class Ajv {
  2670. constructor(opts = {}) {
  2671. this.schemas = {};
  2672. this.refs = {};
  2673. this.formats = {};
  2674. this._compilations = new Set();
  2675. this._loading = {};
  2676. this._cache = new Map();
  2677. opts = this.opts = { ...opts, ...requiredOptions(opts) };
  2678. const { es5, lines } = this.opts.code;
  2679. this.scope = new codegen_2.ValueScope({ scope: {}, prefixes: EXT_SCOPE_NAMES, es5, lines });
  2680. this.logger = getLogger(opts.logger);
  2681. const formatOpt = opts.validateFormats;
  2682. opts.validateFormats = false;
  2683. this.RULES = rules_1.getRules();
  2684. checkOptions.call(this, removedOptions, opts, "NOT SUPPORTED");
  2685. checkOptions.call(this, deprecatedOptions, opts, "DEPRECATED", "warn");
  2686. this._metaOpts = getMetaSchemaOptions.call(this);
  2687. if (opts.formats)
  2688. addInitialFormats.call(this);
  2689. this._addVocabularies();
  2690. this._addDefaultMetaSchema();
  2691. if (opts.keywords)
  2692. addInitialKeywords.call(this, opts.keywords);
  2693. if (typeof opts.meta == "object")
  2694. this.addMetaSchema(opts.meta);
  2695. addInitialSchemas.call(this);
  2696. opts.validateFormats = formatOpt;
  2697. }
  2698. _addVocabularies() {
  2699. this.addKeyword("$async");
  2700. }
  2701. _addDefaultMetaSchema() {
  2702. const { $data, meta } = this.opts;
  2703. if (meta && $data)
  2704. this.addMetaSchema($dataRefSchema, $dataRefSchema.$id, false);
  2705. }
  2706. defaultMeta() {
  2707. const { meta } = this.opts;
  2708. return (this.opts.defaultMeta = typeof meta == "object" ? meta.$id || meta : undefined);
  2709. }
  2710. validate(schemaKeyRef, // key, ref or schema object
  2711. data // to be validated
  2712. ) {
  2713. let v;
  2714. if (typeof schemaKeyRef == "string") {
  2715. v = this.getSchema(schemaKeyRef);
  2716. if (!v)
  2717. throw new Error(`no schema with key or ref "${schemaKeyRef}"`);
  2718. }
  2719. else {
  2720. v = this.compile(schemaKeyRef);
  2721. }
  2722. const valid = v(data);
  2723. if (!("$async" in v))
  2724. this.errors = v.errors;
  2725. return valid;
  2726. }
  2727. compile(schema, _meta) {
  2728. const sch = this._addSchema(schema, _meta);
  2729. return (sch.validate || this._compileSchemaEnv(sch));
  2730. }
  2731. compileAsync(schema, meta) {
  2732. if (typeof this.opts.loadSchema != "function") {
  2733. throw new Error("options.loadSchema should be a function");
  2734. }
  2735. const { loadSchema } = this.opts;
  2736. return runCompileAsync.call(this, schema, meta);
  2737. async function runCompileAsync(_schema, _meta) {
  2738. await loadMetaSchema.call(this, _schema.$schema);
  2739. const sch = this._addSchema(_schema, _meta);
  2740. return sch.validate || _compileAsync.call(this, sch);
  2741. }
  2742. async function loadMetaSchema($ref) {
  2743. if ($ref && !this.getSchema($ref)) {
  2744. await runCompileAsync.call(this, { $ref }, true);
  2745. }
  2746. }
  2747. async function _compileAsync(sch) {
  2748. try {
  2749. return this._compileSchemaEnv(sch);
  2750. }
  2751. catch (e) {
  2752. if (!(e instanceof error_classes_1.MissingRefError))
  2753. throw e;
  2754. checkLoaded.call(this, e);
  2755. await loadMissingSchema.call(this, e.missingSchema);
  2756. return _compileAsync.call(this, sch);
  2757. }
  2758. }
  2759. function checkLoaded({ missingSchema: ref, missingRef }) {
  2760. if (this.refs[ref]) {
  2761. throw new Error(`AnySchema ${ref} is loaded but ${missingRef} cannot be resolved`);
  2762. }
  2763. }
  2764. async function loadMissingSchema(ref) {
  2765. const _schema = await _loadSchema.call(this, ref);
  2766. if (!this.refs[ref])
  2767. await loadMetaSchema.call(this, _schema.$schema);
  2768. if (!this.refs[ref])
  2769. this.addSchema(_schema, ref, meta);
  2770. }
  2771. async function _loadSchema(ref) {
  2772. const p = this._loading[ref];
  2773. if (p)
  2774. return p;
  2775. try {
  2776. return await (this._loading[ref] = loadSchema(ref));
  2777. }
  2778. finally {
  2779. delete this._loading[ref];
  2780. }
  2781. }
  2782. }
  2783. // Adds schema to the instance
  2784. addSchema(schema, // If array is passed, `key` will be ignored
  2785. 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`.
  2786. _meta, // true if schema is a meta-schema. Used internally, addMetaSchema should be used instead.
  2787. _validateSchema = this.opts.validateSchema // false to skip schema validation. Used internally, option validateSchema should be used instead.
  2788. ) {
  2789. if (Array.isArray(schema)) {
  2790. for (const sch of schema)
  2791. this.addSchema(sch, undefined, _meta, _validateSchema);
  2792. return this;
  2793. }
  2794. let id;
  2795. if (typeof schema === "object") {
  2796. id = schema.$id;
  2797. if (id !== undefined && typeof id != "string")
  2798. throw new Error("schema id must be string");
  2799. }
  2800. key = resolve_1.normalizeId(key || id);
  2801. this._checkUnique(key);
  2802. this.schemas[key] = this._addSchema(schema, _meta, _validateSchema, true);
  2803. return this;
  2804. }
  2805. // Add schema that will be used to validate other schemas
  2806. // options in META_IGNORE_OPTIONS are alway set to false
  2807. addMetaSchema(schema, key, // schema key
  2808. _validateSchema = this.opts.validateSchema // false to skip schema validation, can be used to override validateSchema option for meta-schema
  2809. ) {
  2810. this.addSchema(schema, key, true, _validateSchema);
  2811. return this;
  2812. }
  2813. // Validate schema against its meta-schema
  2814. validateSchema(schema, throwOrLogError) {
  2815. if (typeof schema == "boolean")
  2816. return true;
  2817. let $schema;
  2818. $schema = schema.$schema;
  2819. if ($schema !== undefined && typeof $schema != "string") {
  2820. throw new Error("$schema must be a string");
  2821. }
  2822. $schema = $schema || this.opts.defaultMeta || this.defaultMeta();
  2823. if (!$schema) {
  2824. this.logger.warn("meta-schema not available");
  2825. this.errors = null;
  2826. return true;
  2827. }
  2828. const valid = this.validate($schema, schema);
  2829. if (!valid && throwOrLogError) {
  2830. const message = "schema is invalid: " + this.errorsText();
  2831. if (this.opts.validateSchema === "log")
  2832. this.logger.error(message);
  2833. else
  2834. throw new Error(message);
  2835. }
  2836. return valid;
  2837. }
  2838. // Get compiled schema by `key` or `ref`.
  2839. // (`key` that was passed to `addSchema` or full schema reference - `schema.$id` or resolved id)
  2840. getSchema(keyRef) {
  2841. let sch;
  2842. while (typeof (sch = getSchEnv.call(this, keyRef)) == "string")
  2843. keyRef = sch;
  2844. if (sch === undefined) {
  2845. const root = new compile_1.SchemaEnv({ schema: {} });
  2846. sch = compile_1.resolveSchema.call(this, root, keyRef);
  2847. if (!sch)
  2848. return;
  2849. this.refs[keyRef] = sch;
  2850. }
  2851. return (sch.validate || this._compileSchemaEnv(sch));
  2852. }
  2853. // Remove cached schema(s).
  2854. // If no parameter is passed all schemas but meta-schemas are removed.
  2855. // If RegExp is passed all schemas with key/id matching pattern but meta-schemas are removed.
  2856. // Even if schema is referenced by other schemas it still can be removed as other schemas have local references.
  2857. removeSchema(schemaKeyRef) {
  2858. if (schemaKeyRef instanceof RegExp) {
  2859. this._removeAllSchemas(this.schemas, schemaKeyRef);
  2860. this._removeAllSchemas(this.refs, schemaKeyRef);
  2861. return this;
  2862. }
  2863. switch (typeof schemaKeyRef) {
  2864. case "undefined":
  2865. this._removeAllSchemas(this.schemas);
  2866. this._removeAllSchemas(this.refs);
  2867. this._cache.clear();
  2868. return this;
  2869. case "string": {
  2870. const sch = getSchEnv.call(this, schemaKeyRef);
  2871. if (typeof sch == "object")
  2872. this._cache.delete(sch.schema);
  2873. delete this.schemas[schemaKeyRef];
  2874. delete this.refs[schemaKeyRef];
  2875. return this;
  2876. }
  2877. case "object": {
  2878. const cacheKey = schemaKeyRef;
  2879. this._cache.delete(cacheKey);
  2880. let id = schemaKeyRef.$id;
  2881. if (id) {
  2882. id = resolve_1.normalizeId(id);
  2883. delete this.schemas[id];
  2884. delete this.refs[id];
  2885. }
  2886. return this;
  2887. }
  2888. default:
  2889. throw new Error("ajv.removeSchema: invalid parameter");
  2890. }
  2891. }
  2892. // add "vocabulary" - a collection of keywords
  2893. addVocabulary(definitions) {
  2894. for (const def of definitions)
  2895. this.addKeyword(def);
  2896. return this;
  2897. }
  2898. addKeyword(kwdOrDef, def // deprecated
  2899. ) {
  2900. let keyword;
  2901. if (typeof kwdOrDef == "string") {
  2902. keyword = kwdOrDef;
  2903. if (typeof def == "object") {
  2904. this.logger.warn("these parameters are deprecated, see docs for addKeyword");
  2905. def.keyword = keyword;
  2906. }
  2907. }
  2908. else if (typeof kwdOrDef == "object" && def === undefined) {
  2909. def = kwdOrDef;
  2910. keyword = def.keyword;
  2911. if (Array.isArray(keyword) && !keyword.length) {
  2912. throw new Error("addKeywords: keyword must be string or non-empty array");
  2913. }
  2914. }
  2915. else {
  2916. throw new Error("invalid addKeywords parameters");
  2917. }
  2918. checkKeyword.call(this, keyword, def);
  2919. if (!def) {
  2920. util_1.eachItem(keyword, (kwd) => addRule.call(this, kwd));
  2921. return this;
  2922. }
  2923. keywordMetaschema.call(this, def);
  2924. const definition = {
  2925. ...def,
  2926. type: dataType_1.getJSONTypes(def.type),
  2927. schemaType: dataType_1.getJSONTypes(def.schemaType),
  2928. };
  2929. util_1.eachItem(keyword, definition.type.length === 0
  2930. ? (k) => addRule.call(this, k, definition)
  2931. : (k) => definition.type.forEach((t) => addRule.call(this, k, definition, t)));
  2932. return this;
  2933. }
  2934. getKeyword(keyword) {
  2935. const rule = this.RULES.all[keyword];
  2936. return typeof rule == "object" ? rule.definition : !!rule;
  2937. }
  2938. // Remove keyword
  2939. removeKeyword(keyword) {
  2940. // TODO return type should be Ajv
  2941. const { RULES } = this;
  2942. delete RULES.keywords[keyword];
  2943. delete RULES.all[keyword];
  2944. for (const group of RULES.rules) {
  2945. const i = group.rules.findIndex((rule) => rule.keyword === keyword);
  2946. if (i >= 0)
  2947. group.rules.splice(i, 1);
  2948. }
  2949. return this;
  2950. }
  2951. // Add format
  2952. addFormat(name, format) {
  2953. if (typeof format == "string")
  2954. format = new RegExp(format);
  2955. this.formats[name] = format;
  2956. return this;
  2957. }
  2958. errorsText(errors = this.errors, // optional array of validation errors
  2959. { separator = ", ", dataVar = "data" } = {} // optional options with properties `separator` and `dataVar`
  2960. ) {
  2961. if (!errors || errors.length === 0)
  2962. return "No errors";
  2963. return errors
  2964. .map((e) => `${dataVar}${e.dataPath} ${e.message}`)
  2965. .reduce((text, msg) => text + separator + msg);
  2966. }
  2967. $dataMetaSchema(metaSchema, keywordsJsonPointers) {
  2968. const rules = this.RULES.all;
  2969. metaSchema = JSON.parse(JSON.stringify(metaSchema));
  2970. for (const jsonPointer of keywordsJsonPointers) {
  2971. const segments = jsonPointer.split("/").slice(1); // first segment is an empty string
  2972. let keywords = metaSchema;
  2973. for (const seg of segments)
  2974. keywords = keywords[seg];
  2975. for (const key in rules) {
  2976. const rule = rules[key];
  2977. if (typeof rule != "object")
  2978. continue;
  2979. const { $data } = rule.definition;
  2980. const schema = keywords[key];
  2981. if ($data && schema)
  2982. keywords[key] = schemaOrData(schema);
  2983. }
  2984. }
  2985. return metaSchema;
  2986. }
  2987. _removeAllSchemas(schemas, regex) {
  2988. for (const keyRef in schemas) {
  2989. const sch = schemas[keyRef];
  2990. if (!regex || regex.test(keyRef)) {
  2991. if (typeof sch == "string") {
  2992. delete schemas[keyRef];
  2993. }
  2994. else if (sch && !sch.meta) {
  2995. this._cache.delete(sch.schema);
  2996. delete schemas[keyRef];
  2997. }
  2998. }
  2999. }
  3000. }
  3001. _addSchema(schema, meta, validateSchema = this.opts.validateSchema, addSchema = this.opts.addUsedSchema) {
  3002. if (typeof schema != "object" && typeof schema != "boolean") {
  3003. throw new Error("schema must be object or boolean");
  3004. }
  3005. let sch = this._cache.get(schema);
  3006. if (sch !== undefined)
  3007. return sch;
  3008. const localRefs = resolve_1.getSchemaRefs.call(this, schema);
  3009. sch = new compile_1.SchemaEnv({ schema, meta, localRefs });
  3010. this._cache.set(sch.schema, sch);
  3011. const id = sch.baseId;
  3012. if (addSchema && !id.startsWith("#")) {
  3013. // TODO atm it is allowed to overwrite schemas without id (instead of not adding them)
  3014. if (id)
  3015. this._checkUnique(id);
  3016. this.refs[id] = sch;
  3017. }
  3018. if (validateSchema)
  3019. this.validateSchema(schema, true);
  3020. return sch;
  3021. }
  3022. _checkUnique(id) {
  3023. if (this.schemas[id] || this.refs[id]) {
  3024. throw new Error(`schema with key or id "${id}" already exists`);
  3025. }
  3026. }
  3027. _compileSchemaEnv(sch) {
  3028. if (sch.meta)
  3029. this._compileMetaSchema(sch);
  3030. else
  3031. compile_1.compileSchema.call(this, sch);
  3032. /* istanbul ignore if */
  3033. if (!sch.validate)
  3034. throw new Error("ajv implementation error");
  3035. return sch.validate;
  3036. }
  3037. _compileMetaSchema(sch) {
  3038. const currentOpts = this.opts;
  3039. this.opts = this._metaOpts;
  3040. try {
  3041. compile_1.compileSchema.call(this, sch);
  3042. }
  3043. finally {
  3044. this.opts = currentOpts;
  3045. }
  3046. }
  3047. }
  3048. exports.default = Ajv;
  3049. Ajv.ValidationError = error_classes_1.ValidationError;
  3050. Ajv.MissingRefError = error_classes_1.MissingRefError;
  3051. function checkOptions(checkOpts, options, msg, log = "error") {
  3052. for (const key in checkOpts) {
  3053. const opt = key;
  3054. if (opt in options)
  3055. this.logger[log](`${msg}: option ${key}. ${checkOpts[opt]}`);
  3056. }
  3057. }
  3058. function getSchEnv(keyRef) {
  3059. keyRef = resolve_1.normalizeId(keyRef); // TODO tests fail without this line
  3060. return this.schemas[keyRef] || this.refs[keyRef];
  3061. }
  3062. function addInitialSchemas() {
  3063. const optsSchemas = this.opts.schemas;
  3064. if (!optsSchemas)
  3065. return;
  3066. if (Array.isArray(optsSchemas))
  3067. this.addSchema(optsSchemas);
  3068. else
  3069. for (const key in optsSchemas)
  3070. this.addSchema(optsSchemas[key], key);
  3071. }
  3072. function addInitialFormats() {
  3073. for (const name in this.opts.formats) {
  3074. const format = this.opts.formats[name];
  3075. if (format)
  3076. this.addFormat(name, format);
  3077. }
  3078. }
  3079. function addInitialKeywords(defs) {
  3080. if (Array.isArray(defs)) {
  3081. this.addVocabulary(defs);
  3082. return;
  3083. }
  3084. this.logger.warn("keywords option as map is deprecated, pass array");
  3085. for (const keyword in defs) {
  3086. const def = defs[keyword];
  3087. if (!def.keyword)
  3088. def.keyword = keyword;
  3089. this.addKeyword(def);
  3090. }
  3091. }
  3092. function getMetaSchemaOptions() {
  3093. const metaOpts = { ...this.opts };
  3094. for (const opt of META_IGNORE_OPTIONS)
  3095. delete metaOpts[opt];
  3096. return metaOpts;
  3097. }
  3098. const noLogs = { log() { }, warn() { }, error() { } };
  3099. function getLogger(logger) {
  3100. if (logger === false)
  3101. return noLogs;
  3102. if (logger === undefined)
  3103. return console;
  3104. if (logger.log && logger.warn && logger.error)
  3105. return logger;
  3106. throw new Error("logger must implement log, warn and error methods");
  3107. }
  3108. const KEYWORD_NAME = /^[a-z_$][a-z0-9_$-]*$/i;
  3109. function checkKeyword(keyword, def) {
  3110. const { RULES } = this;
  3111. util_1.eachItem(keyword, (kwd) => {
  3112. if (RULES.keywords[kwd])
  3113. throw new Error(`Keyword ${kwd} is already defined`);
  3114. if (!KEYWORD_NAME.test(kwd))
  3115. throw new Error(`Keyword ${kwd} has invalid name`);
  3116. });
  3117. if (!def)
  3118. return;
  3119. if (def.$data && !("code" in def || "validate" in def)) {
  3120. throw new Error('$data keyword must have "code" or "validate" function');
  3121. }
  3122. }
  3123. function addRule(keyword, definition, dataType) {
  3124. var _a;
  3125. const post = definition === null || definition === void 0 ? void 0 : definition.post;
  3126. if (dataType && post)
  3127. throw new Error('keyword with "post" flag cannot have "type"');
  3128. const { RULES } = this;
  3129. let ruleGroup = post ? RULES.post : RULES.rules.find(({ type: t }) => t === dataType);
  3130. if (!ruleGroup) {
  3131. ruleGroup = { type: dataType, rules: [] };
  3132. RULES.rules.push(ruleGroup);
  3133. }
  3134. RULES.keywords[keyword] = true;
  3135. if (!definition)
  3136. return;
  3137. const rule = {
  3138. keyword,
  3139. definition: {
  3140. ...definition,
  3141. type: dataType_1.getJSONTypes(definition.type),
  3142. schemaType: dataType_1.getJSONTypes(definition.schemaType),
  3143. },
  3144. };
  3145. if (definition.before)
  3146. addBeforeRule.call(this, ruleGroup, rule, definition.before);
  3147. else
  3148. ruleGroup.rules.push(rule);
  3149. RULES.all[keyword] = rule;
  3150. (_a = definition.implements) === null || _a === void 0 ? void 0 : _a.forEach((kwd) => this.addKeyword(kwd));
  3151. }
  3152. function addBeforeRule(ruleGroup, rule, before) {
  3153. const i = ruleGroup.rules.findIndex((_rule) => _rule.keyword === before);
  3154. if (i >= 0) {
  3155. ruleGroup.rules.splice(i, 0, rule);
  3156. }
  3157. else {
  3158. ruleGroup.rules.push(rule);
  3159. this.logger.warn(`rule ${before} is not defined`);
  3160. }
  3161. }
  3162. function keywordMetaschema(def) {
  3163. let { metaSchema } = def;
  3164. if (metaSchema === undefined)
  3165. return;
  3166. if (def.$data && this.opts.$data)
  3167. metaSchema = schemaOrData(metaSchema);
  3168. def.validateSchema = this.compile(metaSchema, true);
  3169. }
  3170. const $dataRef = {
  3171. $ref: "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
  3172. };
  3173. function schemaOrData(schema) {
  3174. return { anyOf: [schema, $dataRef] };
  3175. }
  3176. //# sourceMappingURL=core.js.map
  3177. }, function(modId) { var map = {"./compile/context":1609944441817,"./compile/codegen":1609944441822,"./compile/error_classes":1609944441836,"./compile/rules":1609944441819,"./compile":1609944441837,"./compile/resolve":1609944441833,"./compile/validate/dataType":1609944441818,"./compile/util":1609944441826,"./refs/data.json":1609944441838}; return __REQUIRE__(map[modId], modId); })
  3178. __DEFINE__(1609944441836, function(require, module, exports) {
  3179. Object.defineProperty(exports, "__esModule", { value: true });
  3180. exports.MissingRefError = exports.ValidationError = void 0;
  3181. const resolve_1 = require("./resolve");
  3182. class ValidationError extends Error {
  3183. constructor(errors) {
  3184. super("validation failed");
  3185. this.errors = errors;
  3186. this.ajv = this.validation = true;
  3187. }
  3188. }
  3189. exports.ValidationError = ValidationError;
  3190. class MissingRefError extends Error {
  3191. constructor(baseId, ref) {
  3192. super(`can't resolve reference ${ref} from id ${baseId}`);
  3193. this.missingRef = resolve_1.resolveUrl(baseId, ref);
  3194. this.missingSchema = resolve_1.normalizeId(resolve_1.getFullPath(this.missingRef));
  3195. }
  3196. }
  3197. exports.MissingRefError = MissingRefError;
  3198. module.exports = {
  3199. ValidationError,
  3200. MissingRefError,
  3201. };
  3202. //# sourceMappingURL=error_classes.js.map
  3203. }, function(modId) { var map = {"./resolve":1609944441833}; return __REQUIRE__(map[modId], modId); })
  3204. __DEFINE__(1609944441837, function(require, module, exports) {
  3205. Object.defineProperty(exports, "__esModule", { value: true });
  3206. exports.resolveSchema = exports.resolveRef = exports.compileSchema = exports.SchemaEnv = void 0;
  3207. const codegen_1 = require("./codegen");
  3208. const error_classes_1 = require("./error_classes");
  3209. const names_1 = require("./names");
  3210. const resolve_1 = require("./resolve");
  3211. const util_1 = require("./util");
  3212. const validate_1 = require("./validate");
  3213. const URI = require("uri-js");
  3214. class SchemaEnv {
  3215. constructor(env) {
  3216. var _a;
  3217. this.refs = {};
  3218. this.dynamicAnchors = {};
  3219. let schema;
  3220. if (typeof env.schema == "object")
  3221. schema = env.schema;
  3222. this.schema = env.schema;
  3223. this.root = env.root || this;
  3224. this.baseId = (_a = env.baseId) !== null && _a !== void 0 ? _a : resolve_1.normalizeId(schema === null || schema === void 0 ? void 0 : schema.$id);
  3225. this.localRefs = env.localRefs;
  3226. this.meta = env.meta;
  3227. this.$async = schema === null || schema === void 0 ? void 0 : schema.$async;
  3228. this.refs = {};
  3229. }
  3230. }
  3231. exports.SchemaEnv = SchemaEnv;
  3232. // let codeSize = 0
  3233. // let nodeCount = 0
  3234. // Compiles schema in SchemaEnv
  3235. function compileSchema(sch) {
  3236. // TODO refactor - remove compilations
  3237. const _sch = getCompilingSchema.call(this, sch);
  3238. if (_sch)
  3239. return _sch;
  3240. const rootId = resolve_1.getFullPath(sch.root.baseId); // TODO if getFullPath removed 1 tests fails
  3241. const { es5, lines } = this.opts.code;
  3242. const { ownProperties } = this.opts;
  3243. const gen = new codegen_1.CodeGen(this.scope, { es5, lines, ownProperties });
  3244. let _ValidationError;
  3245. if (sch.$async) {
  3246. _ValidationError = gen.scopeValue("Error", {
  3247. ref: error_classes_1.ValidationError,
  3248. code: codegen_1._ `require("ajv/dist/compile/error_classes").ValidationError`,
  3249. });
  3250. }
  3251. const validateName = gen.scopeName("validate");
  3252. sch.validateName = validateName;
  3253. const schemaCxt = {
  3254. gen,
  3255. allErrors: this.opts.allErrors,
  3256. data: names_1.default.data,
  3257. parentData: names_1.default.parentData,
  3258. parentDataProperty: names_1.default.parentDataProperty,
  3259. dataNames: [names_1.default.data],
  3260. dataPathArr: [codegen_1.nil],
  3261. dataLevel: 0,
  3262. dataTypes: [],
  3263. topSchemaRef: gen.scopeValue("schema", this.opts.code.source === true
  3264. ? { ref: sch.schema, code: codegen_1.stringify(sch.schema) }
  3265. : { ref: sch.schema }),
  3266. validateName,
  3267. ValidationError: _ValidationError,
  3268. schema: sch.schema,
  3269. schemaEnv: sch,
  3270. strictSchema: true,
  3271. rootId,
  3272. baseId: sch.baseId || rootId,
  3273. schemaPath: codegen_1.nil,
  3274. errSchemaPath: "#",
  3275. errorPath: codegen_1._ `""`,
  3276. opts: this.opts,
  3277. self: this,
  3278. };
  3279. let sourceCode;
  3280. try {
  3281. this._compilations.add(sch);
  3282. validate_1.validateFunctionCode(schemaCxt);
  3283. gen.optimize(this.opts.code.optimize);
  3284. // gen.optimize(1)
  3285. const validateCode = gen.toString();
  3286. sourceCode = `${gen.scopeRefs(names_1.default.scope)}return ${validateCode}`;
  3287. // console.log((codeSize += sourceCode.length), (nodeCount += gen.nodeCount))
  3288. if (this.opts.code.process)
  3289. sourceCode = this.opts.code.process(sourceCode, sch);
  3290. // console.log("\n\n\n *** \n", sourceCode)
  3291. const makeValidate = new Function(`${names_1.default.self}`, `${names_1.default.scope}`, sourceCode);
  3292. const validate = makeValidate(this, this.scope.get());
  3293. this.scope.value(validateName, { ref: validate });
  3294. validate.errors = null;
  3295. validate.schema = sch.schema;
  3296. validate.schemaEnv = sch;
  3297. if (sch.$async)
  3298. validate.$async = true;
  3299. if (this.opts.code.source === true) {
  3300. validate.source = { validateName, validateCode, scopeValues: gen._values };
  3301. }
  3302. if (this.opts.unevaluated) {
  3303. const { props, items } = schemaCxt;
  3304. validate.evaluated = {
  3305. props: props instanceof codegen_1.Name ? undefined : props,
  3306. items: items instanceof codegen_1.Name ? undefined : items,
  3307. dynamicProps: props instanceof codegen_1.Name,
  3308. dynamicItems: items instanceof codegen_1.Name,
  3309. };
  3310. if (validate.source)
  3311. validate.source.evaluated = codegen_1.stringify(validate.evaluated);
  3312. }
  3313. sch.validate = validate;
  3314. return sch;
  3315. }
  3316. catch (e) {
  3317. delete sch.validate;
  3318. delete sch.validateName;
  3319. if (sourceCode)
  3320. this.logger.error("Error compiling schema, function code:", sourceCode);
  3321. // console.log("\n\n\n *** \n", sourceCode, this.opts)
  3322. throw e;
  3323. }
  3324. finally {
  3325. this._compilations.delete(sch);
  3326. }
  3327. }
  3328. exports.compileSchema = compileSchema;
  3329. function resolveRef(root, baseId, ref) {
  3330. var _a;
  3331. ref = resolve_1.resolveUrl(baseId, ref);
  3332. const schOrFunc = root.refs[ref];
  3333. if (schOrFunc)
  3334. return schOrFunc;
  3335. let _sch = resolve.call(this, root, ref);
  3336. if (_sch === undefined) {
  3337. const schema = (_a = root.localRefs) === null || _a === void 0 ? void 0 : _a[ref]; // TODO maybe localRefs should hold SchemaEnv
  3338. if (schema)
  3339. _sch = new SchemaEnv({ schema, root, baseId });
  3340. }
  3341. if (_sch === undefined)
  3342. return;
  3343. return (root.refs[ref] = inlineOrCompile.call(this, _sch));
  3344. }
  3345. exports.resolveRef = resolveRef;
  3346. function inlineOrCompile(sch) {
  3347. if (resolve_1.inlineRef(sch.schema, this.opts.inlineRefs))
  3348. return sch.schema;
  3349. return sch.validate ? sch : compileSchema.call(this, sch);
  3350. }
  3351. // Index of schema compilation in the currently compiled list
  3352. function getCompilingSchema(schEnv) {
  3353. for (const sch of this._compilations) {
  3354. if (sameSchemaEnv(sch, schEnv))
  3355. return sch;
  3356. }
  3357. }
  3358. function sameSchemaEnv(s1, s2) {
  3359. return s1.schema === s2.schema && s1.root === s2.root && s1.baseId === s2.baseId;
  3360. }
  3361. // resolve and compile the references ($ref)
  3362. // TODO returns AnySchemaObject (if the schema can be inlined) or validation function
  3363. function resolve(root, // information about the root schema for the current schema
  3364. ref // reference to resolve
  3365. ) {
  3366. let sch;
  3367. while (typeof (sch = this.refs[ref]) == "string")
  3368. ref = sch;
  3369. return sch || this.schemas[ref] || resolveSchema.call(this, root, ref);
  3370. }
  3371. // Resolve schema, its root and baseId
  3372. function resolveSchema(root, // root object with properties schema, refs TODO below SchemaEnv is assigned to it
  3373. ref // reference to resolve
  3374. ) {
  3375. const p = URI.parse(ref);
  3376. const refPath = resolve_1._getFullPath(p);
  3377. const baseId = resolve_1.getFullPath(root.baseId);
  3378. // TODO `Object.keys(root.schema).length > 0` should not be needed - but removing breaks 2 tests
  3379. if (Object.keys(root.schema).length > 0 && refPath === baseId) {
  3380. return getJsonPointer.call(this, p, root);
  3381. }
  3382. const id = resolve_1.normalizeId(refPath);
  3383. const schOrRef = this.refs[id] || this.schemas[id];
  3384. if (typeof schOrRef == "string") {
  3385. const sch = resolveSchema.call(this, root, schOrRef);
  3386. if (typeof (sch === null || sch === void 0 ? void 0 : sch.schema) !== "object")
  3387. return;
  3388. return getJsonPointer.call(this, p, sch);
  3389. }
  3390. if (typeof (schOrRef === null || schOrRef === void 0 ? void 0 : schOrRef.schema) !== "object")
  3391. return;
  3392. if (!schOrRef.validate)
  3393. compileSchema.call(this, schOrRef);
  3394. if (id === resolve_1.normalizeId(ref))
  3395. return new SchemaEnv({ schema: schOrRef.schema, root, baseId });
  3396. return getJsonPointer.call(this, p, schOrRef);
  3397. }
  3398. exports.resolveSchema = resolveSchema;
  3399. const PREVENT_SCOPE_CHANGE = new Set([
  3400. "properties",
  3401. "patternProperties",
  3402. "enum",
  3403. "dependencies",
  3404. "definitions",
  3405. ]);
  3406. function getJsonPointer(parsedRef, { baseId, schema, root }) {
  3407. var _a;
  3408. if (((_a = parsedRef.fragment) === null || _a === void 0 ? void 0 : _a[0]) !== "/")
  3409. return;
  3410. for (const part of parsedRef.fragment.slice(1).split("/")) {
  3411. if (typeof schema == "boolean")
  3412. return;
  3413. schema = schema[util_1.unescapeFragment(part)];
  3414. if (schema === undefined)
  3415. return;
  3416. // TODO PREVENT_SCOPE_CHANGE could be defined in keyword def?
  3417. if (!PREVENT_SCOPE_CHANGE.has(part) && typeof schema == "object" && schema.$id) {
  3418. baseId = resolve_1.resolveUrl(baseId, schema.$id);
  3419. }
  3420. }
  3421. let env;
  3422. if (typeof schema != "boolean" && schema.$ref && !util_1.schemaHasRulesButRef(schema, this.RULES)) {
  3423. const $ref = resolve_1.resolveUrl(baseId, schema.$ref);
  3424. env = resolveSchema.call(this, root, $ref);
  3425. }
  3426. // even though resolution failed we need to return SchemaEnv to throw exception
  3427. // so that compileAsync loads missing schema.
  3428. env = env || new SchemaEnv({ schema, root, baseId });
  3429. if (env.schema !== env.root.schema)
  3430. return env;
  3431. return undefined;
  3432. }
  3433. //# sourceMappingURL=index.js.map
  3434. }, function(modId) { var map = {"./codegen":1609944441822,"./error_classes":1609944441836,"./names":1609944441825,"./resolve":1609944441833,"./util":1609944441826,"./validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  3435. __DEFINE__(1609944441838, function(require, module, exports) {
  3436. module.exports = {
  3437. "$id": "https://raw.githubusercontent.com/ajv-validator/ajv/master/lib/refs/data.json#",
  3438. "description": "Meta-schema for $data reference (JSON AnySchema extension proposal)",
  3439. "type": "object",
  3440. "required": ["$data"],
  3441. "properties": {
  3442. "$data": {
  3443. "type": "string",
  3444. "anyOf": [{"format": "relative-json-pointer"}, {"format": "json-pointer"}]
  3445. }
  3446. },
  3447. "additionalProperties": false
  3448. }
  3449. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3450. __DEFINE__(1609944441839, function(require, module, exports) {
  3451. Object.defineProperty(exports, "__esModule", { value: true });
  3452. const core_1 = require("./core");
  3453. const validation_1 = require("./validation");
  3454. const applicator_1 = require("./applicator");
  3455. const format_1 = require("./format");
  3456. const metadata_1 = require("./metadata");
  3457. const draft7Vocabularies = [
  3458. core_1.default,
  3459. validation_1.default,
  3460. applicator_1.default,
  3461. format_1.default,
  3462. metadata_1.metadataVocabulary,
  3463. metadata_1.contentVocabulary,
  3464. ];
  3465. exports.default = draft7Vocabularies;
  3466. //# sourceMappingURL=draft7.js.map
  3467. }, function(modId) { var map = {"./core":1609944441840,"./validation":1609944441843,"./applicator":1609944441855,"./format":1609944441870,"./metadata":1609944441872}; return __REQUIRE__(map[modId], modId); })
  3468. __DEFINE__(1609944441840, function(require, module, exports) {
  3469. Object.defineProperty(exports, "__esModule", { value: true });
  3470. const id_1 = require("./id");
  3471. const ref_1 = require("./ref");
  3472. const core = [
  3473. "$schema",
  3474. "$id",
  3475. "$defs",
  3476. "$vocabulary",
  3477. "definitions",
  3478. id_1.default,
  3479. ref_1.default,
  3480. ];
  3481. exports.default = core;
  3482. //# sourceMappingURL=index.js.map
  3483. }, function(modId) { var map = {"./id":1609944441841,"./ref":1609944441842}; return __REQUIRE__(map[modId], modId); })
  3484. __DEFINE__(1609944441841, function(require, module, exports) {
  3485. Object.defineProperty(exports, "__esModule", { value: true });
  3486. const def = {
  3487. keyword: "id",
  3488. code() {
  3489. throw new Error('NOT SUPPORTED: keyword "id", use "$id" for schema ID');
  3490. },
  3491. };
  3492. exports.default = def;
  3493. //# sourceMappingURL=id.js.map
  3494. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3495. __DEFINE__(1609944441842, function(require, module, exports) {
  3496. Object.defineProperty(exports, "__esModule", { value: true });
  3497. exports.callRef = exports.getValidate = void 0;
  3498. const error_classes_1 = require("../../compile/error_classes");
  3499. const code_1 = require("../code");
  3500. const codegen_1 = require("../../compile/codegen");
  3501. const names_1 = require("../../compile/names");
  3502. const compile_1 = require("../../compile");
  3503. const util_1 = require("../../compile/util");
  3504. const def = {
  3505. keyword: "$ref",
  3506. schemaType: "string",
  3507. code(cxt) {
  3508. const { gen, schema, it } = cxt;
  3509. const { baseId, schemaEnv: env, validateName, opts, self } = it;
  3510. // TODO See comment in dynamicRef.ts
  3511. // This has to be improved to resolve #815.
  3512. if (schema === "#" || schema === "#/")
  3513. return callRootRef();
  3514. const schOrEnv = compile_1.resolveRef.call(self, env.root, baseId, schema);
  3515. if (schOrEnv === undefined)
  3516. throw new error_classes_1.MissingRefError(baseId, schema);
  3517. if (schOrEnv instanceof compile_1.SchemaEnv)
  3518. return callValidate(schOrEnv);
  3519. return inlineRefSchema(schOrEnv);
  3520. function callRootRef() {
  3521. if (env === env.root)
  3522. return callRef(cxt, validateName, env, env.$async);
  3523. const rootName = gen.scopeValue("root", { ref: env.root });
  3524. return callRef(cxt, codegen_1._ `${rootName}.validate`, env.root, env.root.$async);
  3525. }
  3526. function callValidate(sch) {
  3527. const v = getValidate(cxt, sch);
  3528. callRef(cxt, v, sch, sch.$async);
  3529. }
  3530. function inlineRefSchema(sch) {
  3531. const schName = gen.scopeValue("schema", opts.code.source === true ? { ref: sch, code: codegen_1.stringify(sch) } : { ref: sch });
  3532. const valid = gen.name("valid");
  3533. const schCxt = cxt.subschema({
  3534. schema: sch,
  3535. strictSchema: true,
  3536. dataTypes: [],
  3537. schemaPath: codegen_1.nil,
  3538. topSchemaRef: schName,
  3539. errSchemaPath: schema,
  3540. }, valid);
  3541. cxt.mergeEvaluated(schCxt);
  3542. cxt.ok(valid);
  3543. }
  3544. },
  3545. };
  3546. function getValidate(cxt, sch) {
  3547. const { gen } = cxt;
  3548. return sch.validate
  3549. ? gen.scopeValue("validate", { ref: sch.validate })
  3550. : codegen_1._ `${gen.scopeValue("wrapper", { ref: sch })}.validate`;
  3551. }
  3552. exports.getValidate = getValidate;
  3553. function callRef(cxt, v, sch, $async) {
  3554. const { gen, it } = cxt;
  3555. const { allErrors, schemaEnv: env, opts } = it;
  3556. const passCxt = opts.passContext ? names_1.default.this : codegen_1.nil;
  3557. if ($async)
  3558. callAsyncRef();
  3559. else
  3560. callSyncRef();
  3561. function callAsyncRef() {
  3562. if (!env.$async)
  3563. throw new Error("async schema referenced by sync schema");
  3564. const valid = gen.let("valid");
  3565. gen.try(() => {
  3566. gen.code(codegen_1._ `await ${code_1.callValidateCode(cxt, v, passCxt)}`);
  3567. addEvaluatedFrom(v); // TODO will not work with async, it has to be returned with the result
  3568. if (!allErrors)
  3569. gen.assign(valid, true);
  3570. }, (e) => {
  3571. gen.if(codegen_1._ `!(${e} instanceof ${it.ValidationError})`, () => gen.throw(e));
  3572. addErrorsFrom(e);
  3573. if (!allErrors)
  3574. gen.assign(valid, false);
  3575. });
  3576. cxt.ok(valid);
  3577. }
  3578. function callSyncRef() {
  3579. cxt.result(code_1.callValidateCode(cxt, v, passCxt), () => addEvaluatedFrom(v), () => addErrorsFrom(v));
  3580. }
  3581. function addErrorsFrom(source) {
  3582. const errs = codegen_1._ `${source}.errors`;
  3583. gen.assign(names_1.default.vErrors, codegen_1._ `${names_1.default.vErrors} === null ? ${errs} : ${names_1.default.vErrors}.concat(${errs})`); // TODO tagged
  3584. gen.assign(names_1.default.errors, codegen_1._ `${names_1.default.vErrors}.length`);
  3585. }
  3586. function addEvaluatedFrom(source) {
  3587. var _a;
  3588. if (!it.opts.unevaluated)
  3589. return;
  3590. const schEvaluated = (_a = sch === null || sch === void 0 ? void 0 : sch.validate) === null || _a === void 0 ? void 0 : _a.evaluated;
  3591. // TODO refactor
  3592. if (it.props !== true) {
  3593. if (schEvaluated && !schEvaluated.dynamicProps) {
  3594. if (schEvaluated.props !== undefined) {
  3595. it.props = util_1.mergeEvaluated.props(gen, schEvaluated.props, it.props);
  3596. }
  3597. }
  3598. else {
  3599. const props = gen.var("props", codegen_1._ `${source}.evaluated.props`);
  3600. it.props = util_1.mergeEvaluated.props(gen, props, it.props, codegen_1.Name);
  3601. }
  3602. }
  3603. if (it.items !== true) {
  3604. if (schEvaluated && !schEvaluated.dynamicItems) {
  3605. if (schEvaluated.items !== undefined) {
  3606. it.items = util_1.mergeEvaluated.items(gen, schEvaluated.items, it.items);
  3607. }
  3608. }
  3609. else {
  3610. const items = gen.var("items", codegen_1._ `${source}.evaluated.items`);
  3611. it.items = util_1.mergeEvaluated.items(gen, items, it.items, codegen_1.Name);
  3612. }
  3613. }
  3614. }
  3615. }
  3616. exports.callRef = callRef;
  3617. exports.default = def;
  3618. //# sourceMappingURL=ref.js.map
  3619. }, function(modId) { var map = {"../../compile/error_classes":1609944441836,"../code":1609944441832,"../../compile/codegen":1609944441822,"../../compile/names":1609944441825,"../../compile":1609944441837,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  3620. __DEFINE__(1609944441843, function(require, module, exports) {
  3621. Object.defineProperty(exports, "__esModule", { value: true });
  3622. const limitNumber_1 = require("./limitNumber");
  3623. const multipleOf_1 = require("./multipleOf");
  3624. const limitLength_1 = require("./limitLength");
  3625. const pattern_1 = require("./pattern");
  3626. const limitProperties_1 = require("./limitProperties");
  3627. const required_1 = require("./required");
  3628. const limitItems_1 = require("./limitItems");
  3629. const uniqueItems_1 = require("./uniqueItems");
  3630. const const_1 = require("./const");
  3631. const enum_1 = require("./enum");
  3632. const validation = [
  3633. // number
  3634. limitNumber_1.default,
  3635. multipleOf_1.default,
  3636. // string
  3637. limitLength_1.default,
  3638. pattern_1.default,
  3639. // object
  3640. limitProperties_1.default,
  3641. required_1.default,
  3642. // array
  3643. limitItems_1.default,
  3644. uniqueItems_1.default,
  3645. // any
  3646. { keyword: "nullable", schemaType: "boolean" },
  3647. const_1.default,
  3648. enum_1.default,
  3649. ];
  3650. exports.default = validation;
  3651. //# sourceMappingURL=index.js.map
  3652. }, function(modId) { var map = {"./limitNumber":1609944441844,"./multipleOf":1609944441845,"./limitLength":1609944441846,"./pattern":1609944441848,"./limitProperties":1609944441849,"./required":1609944441850,"./limitItems":1609944441851,"./uniqueItems":1609944441852,"./const":1609944441853,"./enum":1609944441854}; return __REQUIRE__(map[modId], modId); })
  3653. __DEFINE__(1609944441844, function(require, module, exports) {
  3654. Object.defineProperty(exports, "__esModule", { value: true });
  3655. const codegen_1 = require("../../compile/codegen");
  3656. const ops = codegen_1.operators;
  3657. const KWDs = {
  3658. maximum: { okStr: "<=", ok: ops.LTE, fail: ops.GT },
  3659. minimum: { okStr: ">=", ok: ops.GTE, fail: ops.LT },
  3660. exclusiveMaximum: { okStr: "<", ok: ops.LT, fail: ops.GTE },
  3661. exclusiveMinimum: { okStr: ">", ok: ops.GT, fail: ops.LTE },
  3662. };
  3663. const error = {
  3664. message: ({ keyword, schemaCode }) => codegen_1.str `should be ${KWDs[keyword].okStr} ${schemaCode}`,
  3665. params: ({ keyword, schemaCode }) => codegen_1._ `{comparison: ${KWDs[keyword].okStr}, limit: ${schemaCode}}`,
  3666. };
  3667. const def = {
  3668. keyword: Object.keys(KWDs),
  3669. type: "number",
  3670. schemaType: "number",
  3671. $data: true,
  3672. error,
  3673. code(cxt) {
  3674. const { keyword, data, schemaCode } = cxt;
  3675. cxt.fail$data(codegen_1._ `${data} ${KWDs[keyword].fail} ${schemaCode} || isNaN(${data})`);
  3676. },
  3677. };
  3678. exports.default = def;
  3679. //# sourceMappingURL=limitNumber.js.map
  3680. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3681. __DEFINE__(1609944441845, function(require, module, exports) {
  3682. Object.defineProperty(exports, "__esModule", { value: true });
  3683. const codegen_1 = require("../../compile/codegen");
  3684. const error = {
  3685. message: ({ schemaCode }) => codegen_1.str `should be multiple of ${schemaCode}`,
  3686. params: ({ schemaCode }) => codegen_1._ `{multipleOf: ${schemaCode}}`,
  3687. };
  3688. const def = {
  3689. keyword: "multipleOf",
  3690. type: "number",
  3691. schemaType: "number",
  3692. $data: true,
  3693. error,
  3694. code(cxt) {
  3695. const { gen, data, schemaCode, it } = cxt;
  3696. // const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
  3697. const prec = it.opts.multipleOfPrecision;
  3698. const res = gen.let("res");
  3699. const invalid = prec
  3700. ? codegen_1._ `Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}`
  3701. : codegen_1._ `${res} !== parseInt(${res})`;
  3702. cxt.fail$data(codegen_1._ `(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid}))`);
  3703. },
  3704. };
  3705. exports.default = def;
  3706. //# sourceMappingURL=multipleOf.js.map
  3707. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3708. __DEFINE__(1609944441846, function(require, module, exports) {
  3709. Object.defineProperty(exports, "__esModule", { value: true });
  3710. const codegen_1 = require("../../compile/codegen");
  3711. const ucs2length_1 = require("../../compile/ucs2length");
  3712. const error = {
  3713. message({ keyword, schemaCode }) {
  3714. const comp = keyword === "maxLength" ? "more" : "fewer";
  3715. return codegen_1.str `should NOT have ${comp} than ${schemaCode} characters`;
  3716. },
  3717. params: ({ schemaCode }) => codegen_1._ `{limit: ${schemaCode}}`,
  3718. };
  3719. const def = {
  3720. keyword: ["maxLength", "minLength"],
  3721. type: "string",
  3722. schemaType: "number",
  3723. $data: true,
  3724. error,
  3725. code(cxt) {
  3726. const { keyword, data, schemaCode, it } = cxt;
  3727. const op = keyword === "maxLength" ? codegen_1.operators.GT : codegen_1.operators.LT;
  3728. let len;
  3729. if (it.opts.unicode === false) {
  3730. len = codegen_1._ `${data}.length`;
  3731. }
  3732. else {
  3733. const u2l = cxt.gen.scopeValue("func", {
  3734. ref: ucs2length_1.default,
  3735. code: codegen_1._ `require("ajv/dist/compile/ucs2length").default`,
  3736. });
  3737. len = codegen_1._ `${u2l}(${data})`;
  3738. }
  3739. cxt.fail$data(codegen_1._ `${len} ${op} ${schemaCode}`);
  3740. },
  3741. };
  3742. exports.default = def;
  3743. //# sourceMappingURL=limitLength.js.map
  3744. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/ucs2length":1609944441847}; return __REQUIRE__(map[modId], modId); })
  3745. __DEFINE__(1609944441847, function(require, module, exports) {
  3746. Object.defineProperty(exports, "__esModule", { value: true });
  3747. // https://mathiasbynens.be/notes/javascript-encoding
  3748. // https://github.com/bestiejs/punycode.js - punycode.ucs2.decode
  3749. function ucs2length(str) {
  3750. const len = str.length;
  3751. let length = 0;
  3752. let pos = 0;
  3753. let value;
  3754. while (pos < len) {
  3755. length++;
  3756. value = str.charCodeAt(pos++);
  3757. if (value >= 0xd800 && value <= 0xdbff && pos < len) {
  3758. // high surrogate, and there is a next character
  3759. value = str.charCodeAt(pos);
  3760. if ((value & 0xfc00) === 0xdc00)
  3761. pos++; // low surrogate
  3762. }
  3763. }
  3764. return length;
  3765. }
  3766. exports.default = ucs2length;
  3767. //# sourceMappingURL=ucs2length.js.map
  3768. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  3769. __DEFINE__(1609944441848, function(require, module, exports) {
  3770. Object.defineProperty(exports, "__esModule", { value: true });
  3771. const code_1 = require("../code");
  3772. const codegen_1 = require("../../compile/codegen");
  3773. const error = {
  3774. message: ({ schemaCode }) => codegen_1.str `should match pattern "${schemaCode}"`,
  3775. params: ({ schemaCode }) => codegen_1._ `{pattern: ${schemaCode}}`,
  3776. };
  3777. const def = {
  3778. keyword: "pattern",
  3779. type: "string",
  3780. schemaType: "string",
  3781. $data: true,
  3782. error,
  3783. code(cxt) {
  3784. const { gen, data, $data, schema, schemaCode } = cxt;
  3785. const regExp = $data ? codegen_1._ `(new RegExp(${schemaCode}, "u"))` : code_1.usePattern(gen, schema); // TODO regexp should be wrapped in try/catch
  3786. cxt.fail$data(codegen_1._ `!${regExp}.test(${data})`);
  3787. },
  3788. };
  3789. exports.default = def;
  3790. //# sourceMappingURL=pattern.js.map
  3791. }, function(modId) { var map = {"../code":1609944441832,"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3792. __DEFINE__(1609944441849, function(require, module, exports) {
  3793. Object.defineProperty(exports, "__esModule", { value: true });
  3794. const codegen_1 = require("../../compile/codegen");
  3795. const error = {
  3796. message({ keyword, schemaCode }) {
  3797. const comp = keyword === "maxProperties" ? "more" : "fewer";
  3798. return codegen_1.str `should NOT have ${comp} than ${schemaCode} items`;
  3799. },
  3800. params: ({ schemaCode }) => codegen_1._ `{limit: ${schemaCode}}`,
  3801. };
  3802. const def = {
  3803. keyword: ["maxProperties", "minProperties"],
  3804. type: "object",
  3805. schemaType: "number",
  3806. $data: true,
  3807. error,
  3808. code(cxt) {
  3809. const { keyword, data, schemaCode } = cxt;
  3810. const op = keyword === "maxProperties" ? codegen_1.operators.GT : codegen_1.operators.LT;
  3811. cxt.fail$data(codegen_1._ `Object.keys(${data}).length ${op} ${schemaCode}`);
  3812. },
  3813. };
  3814. exports.default = def;
  3815. //# sourceMappingURL=limitProperties.js.map
  3816. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3817. __DEFINE__(1609944441850, function(require, module, exports) {
  3818. Object.defineProperty(exports, "__esModule", { value: true });
  3819. const code_1 = require("../code");
  3820. const codegen_1 = require("../../compile/codegen");
  3821. const error = {
  3822. message: ({ params: { missingProperty } }) => codegen_1.str `should have required property '${missingProperty}'`,
  3823. params: ({ params: { missingProperty } }) => codegen_1._ `{missingProperty: ${missingProperty}}`,
  3824. };
  3825. const def = {
  3826. keyword: "required",
  3827. type: "object",
  3828. schemaType: "array",
  3829. $data: true,
  3830. error,
  3831. code(cxt) {
  3832. const { gen, schema, schemaCode, data, $data, it } = cxt;
  3833. const { opts } = it;
  3834. if (!$data && schema.length === 0)
  3835. return;
  3836. const useLoop = schema.length >= opts.loopRequired;
  3837. if (it.allErrors)
  3838. allErrorsMode();
  3839. else
  3840. exitOnErrorMode();
  3841. function allErrorsMode() {
  3842. if (useLoop || $data) {
  3843. cxt.block$data(codegen_1.nil, loopAllRequired);
  3844. }
  3845. else {
  3846. for (const prop of schema) {
  3847. code_1.checkReportMissingProp(cxt, prop);
  3848. }
  3849. }
  3850. }
  3851. function exitOnErrorMode() {
  3852. const missing = gen.let("missing");
  3853. if (useLoop || $data) {
  3854. const valid = gen.let("valid", true);
  3855. cxt.block$data(valid, () => loopUntilMissing(missing, valid));
  3856. cxt.ok(valid);
  3857. }
  3858. else {
  3859. gen.if(code_1.checkMissingProp(cxt, schema, missing));
  3860. code_1.reportMissingProp(cxt, missing);
  3861. gen.else();
  3862. }
  3863. }
  3864. function loopAllRequired() {
  3865. gen.forOf("prop", schemaCode, (prop) => {
  3866. cxt.setParams({ missingProperty: prop });
  3867. gen.if(code_1.noPropertyInData(data, prop, opts.ownProperties), () => cxt.error());
  3868. });
  3869. }
  3870. function loopUntilMissing(missing, valid) {
  3871. cxt.setParams({ missingProperty: missing });
  3872. gen.forOf(missing, schemaCode, () => {
  3873. gen.assign(valid, code_1.propertyInData(data, missing, opts.ownProperties));
  3874. gen.if(codegen_1.not(valid), () => {
  3875. cxt.error();
  3876. gen.break();
  3877. });
  3878. }, codegen_1.nil);
  3879. }
  3880. },
  3881. };
  3882. exports.default = def;
  3883. //# sourceMappingURL=required.js.map
  3884. }, function(modId) { var map = {"../code":1609944441832,"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3885. __DEFINE__(1609944441851, function(require, module, exports) {
  3886. Object.defineProperty(exports, "__esModule", { value: true });
  3887. const codegen_1 = require("../../compile/codegen");
  3888. const error = {
  3889. message({ keyword, schemaCode }) {
  3890. const comp = keyword === "maxItems" ? "more" : "fewer";
  3891. return codegen_1.str `should NOT have ${comp} than ${schemaCode} items`;
  3892. },
  3893. params: ({ schemaCode }) => codegen_1._ `{limit: ${schemaCode}}`,
  3894. };
  3895. const def = {
  3896. keyword: ["maxItems", "minItems"],
  3897. type: "array",
  3898. schemaType: "number",
  3899. $data: true,
  3900. error,
  3901. code(cxt) {
  3902. const { keyword, data, schemaCode } = cxt;
  3903. const op = keyword === "maxItems" ? codegen_1.operators.GT : codegen_1.operators.LT;
  3904. cxt.fail$data(codegen_1._ `${data}.length ${op} ${schemaCode}`);
  3905. },
  3906. };
  3907. exports.default = def;
  3908. //# sourceMappingURL=limitItems.js.map
  3909. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3910. __DEFINE__(1609944441852, function(require, module, exports) {
  3911. Object.defineProperty(exports, "__esModule", { value: true });
  3912. const dataType_1 = require("../../compile/validate/dataType");
  3913. const codegen_1 = require("../../compile/codegen");
  3914. const equal = require("fast-deep-equal");
  3915. const error = {
  3916. message: ({ params: { i, j } }) => codegen_1.str `should NOT have duplicate items (items ## ${j} and ${i} are identical)`,
  3917. params: ({ params: { i, j } }) => codegen_1._ `{i: ${i}, j: ${j}}`,
  3918. };
  3919. const def = {
  3920. keyword: "uniqueItems",
  3921. type: "array",
  3922. schemaType: "boolean",
  3923. $data: true,
  3924. error,
  3925. code(cxt) {
  3926. const { gen, data, $data, schema, parentSchema, schemaCode, it } = cxt;
  3927. if (!$data && !schema)
  3928. return;
  3929. const valid = gen.let("valid");
  3930. const itemTypes = parentSchema.items ? dataType_1.getSchemaTypes(parentSchema.items) : [];
  3931. cxt.block$data(valid, validateUniqueItems, codegen_1._ `${schemaCode} === false`);
  3932. cxt.ok(valid);
  3933. function validateUniqueItems() {
  3934. const i = gen.let("i", codegen_1._ `${data}.length`);
  3935. const j = gen.let("j");
  3936. cxt.setParams({ i, j });
  3937. gen.assign(valid, true);
  3938. gen.if(codegen_1._ `${i} > 1`, () => (canOptimize() ? loopN : loopN2)(i, j));
  3939. }
  3940. function canOptimize() {
  3941. return itemTypes.length > 0 && !itemTypes.some((t) => t === "object" || t === "array");
  3942. }
  3943. function loopN(i, j) {
  3944. const item = gen.name("item");
  3945. const wrongType = dataType_1.checkDataTypes(itemTypes, item, it.opts.strict, dataType_1.DataType.Wrong);
  3946. const indices = gen.const("indices", codegen_1._ `{}`);
  3947. gen.for(codegen_1._ `;${i}--;`, () => {
  3948. gen.let(item, codegen_1._ `${data}[${i}]`);
  3949. gen.if(wrongType, codegen_1._ `continue`);
  3950. if (itemTypes.length > 1)
  3951. gen.if(codegen_1._ `typeof ${item} == "string"`, codegen_1._ `${item} += "_"`);
  3952. gen
  3953. .if(codegen_1._ `typeof ${indices}[${item}] == "number"`, () => {
  3954. gen.assign(j, codegen_1._ `${indices}[${item}]`);
  3955. cxt.error();
  3956. gen.assign(valid, false).break();
  3957. })
  3958. .code(codegen_1._ `${indices}[${item}] = ${i}`);
  3959. });
  3960. }
  3961. function loopN2(i, j) {
  3962. const eql = cxt.gen.scopeValue("func", {
  3963. ref: equal,
  3964. code: codegen_1._ `require("ajv/dist/compile/equal")`,
  3965. });
  3966. const outer = gen.name("outer");
  3967. gen.label(outer).for(codegen_1._ `;${i}--;`, () => gen.for(codegen_1._ `${j} = ${i}; ${j}--;`, () => gen.if(codegen_1._ `${eql}(${data}[${i}], ${data}[${j}])`, () => {
  3968. cxt.error();
  3969. gen.assign(valid, false).break(outer);
  3970. })));
  3971. }
  3972. },
  3973. };
  3974. exports.default = def;
  3975. //# sourceMappingURL=uniqueItems.js.map
  3976. }, function(modId) { var map = {"../../compile/validate/dataType":1609944441818,"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  3977. __DEFINE__(1609944441853, function(require, module, exports) {
  3978. Object.defineProperty(exports, "__esModule", { value: true });
  3979. const codegen_1 = require("../../compile/codegen");
  3980. const equal = require("fast-deep-equal");
  3981. const error = {
  3982. message: "should be equal to constant",
  3983. params: ({ schemaCode }) => codegen_1._ `{allowedValue: ${schemaCode}}`,
  3984. };
  3985. const def = {
  3986. keyword: "const",
  3987. $data: true,
  3988. error,
  3989. code(cxt) {
  3990. const eql = cxt.gen.scopeValue("func", {
  3991. ref: equal,
  3992. code: codegen_1._ `require("ajv/dist/compile/equal")`,
  3993. });
  3994. // TODO optimize for scalar values in schema
  3995. cxt.fail$data(codegen_1._ `!${eql}(${cxt.data}, ${cxt.schemaCode})`);
  3996. },
  3997. };
  3998. exports.default = def;
  3999. //# sourceMappingURL=const.js.map
  4000. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  4001. __DEFINE__(1609944441854, function(require, module, exports) {
  4002. Object.defineProperty(exports, "__esModule", { value: true });
  4003. const codegen_1 = require("../../compile/codegen");
  4004. const equal = require("fast-deep-equal");
  4005. const error = {
  4006. message: "should be equal to one of the allowed values",
  4007. params: ({ schemaCode }) => codegen_1._ `{allowedValues: ${schemaCode}}`,
  4008. };
  4009. const def = {
  4010. keyword: "enum",
  4011. schemaType: "array",
  4012. $data: true,
  4013. error,
  4014. code(cxt) {
  4015. const { gen, data, $data, schema, schemaCode, it } = cxt;
  4016. if (!$data && schema.length === 0)
  4017. throw new Error("enum must have non-empty array");
  4018. const useLoop = schema.length >= it.opts.loopEnum;
  4019. const eql = cxt.gen.scopeValue("func", {
  4020. ref: equal,
  4021. code: codegen_1._ `require("ajv/dist/compile/equal")`,
  4022. });
  4023. let valid;
  4024. if (useLoop || $data) {
  4025. valid = gen.let("valid");
  4026. cxt.block$data(valid, loopEnum);
  4027. }
  4028. else {
  4029. /* istanbul ignore if */
  4030. if (!Array.isArray(schema))
  4031. throw new Error("ajv implementation error");
  4032. const vSchema = gen.const("vSchema", schemaCode);
  4033. valid = codegen_1.or(...schema.map((_x, i) => equalCode(vSchema, i)));
  4034. }
  4035. cxt.pass(valid);
  4036. function loopEnum() {
  4037. gen.assign(valid, false);
  4038. gen.forOf("v", schemaCode, (v) => gen.if(codegen_1._ `${eql}(${data}, ${v})`, () => gen.assign(valid, true).break()));
  4039. }
  4040. function equalCode(vSchema, i) {
  4041. const sch = schema[i];
  4042. return sch && typeof sch === "object"
  4043. ? codegen_1._ `${eql}(${data}, ${vSchema}[${i}])`
  4044. : codegen_1._ `${data} === ${sch}`;
  4045. }
  4046. },
  4047. };
  4048. exports.default = def;
  4049. //# sourceMappingURL=enum.js.map
  4050. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  4051. __DEFINE__(1609944441855, function(require, module, exports) {
  4052. Object.defineProperty(exports, "__esModule", { value: true });
  4053. const additionalItems_1 = require("./additionalItems");
  4054. const items_1 = require("./items");
  4055. const contains_1 = require("./contains");
  4056. const dependencies_1 = require("./dependencies");
  4057. const propertyNames_1 = require("./propertyNames");
  4058. const additionalProperties_1 = require("./additionalProperties");
  4059. const properties_1 = require("./properties");
  4060. const patternProperties_1 = require("./patternProperties");
  4061. const not_1 = require("./not");
  4062. const anyOf_1 = require("./anyOf");
  4063. const oneOf_1 = require("./oneOf");
  4064. const allOf_1 = require("./allOf");
  4065. const if_1 = require("./if");
  4066. const thenElse_1 = require("./thenElse");
  4067. const applicator = [
  4068. // any
  4069. not_1.default,
  4070. anyOf_1.default,
  4071. oneOf_1.default,
  4072. allOf_1.default,
  4073. if_1.default,
  4074. thenElse_1.default,
  4075. // array
  4076. additionalItems_1.default,
  4077. items_1.default,
  4078. contains_1.default,
  4079. // object
  4080. propertyNames_1.default,
  4081. additionalProperties_1.default,
  4082. dependencies_1.default,
  4083. properties_1.default,
  4084. patternProperties_1.default,
  4085. ];
  4086. exports.default = applicator;
  4087. //# sourceMappingURL=index.js.map
  4088. }, function(modId) { var map = {"./additionalItems":1609944441856,"./items":1609944441857,"./contains":1609944441858,"./dependencies":1609944441859,"./propertyNames":1609944441860,"./additionalProperties":1609944441861,"./properties":1609944441862,"./patternProperties":1609944441863,"./not":1609944441864,"./anyOf":1609944441865,"./oneOf":1609944441866,"./allOf":1609944441867,"./if":1609944441868,"./thenElse":1609944441869}; return __REQUIRE__(map[modId], modId); })
  4089. __DEFINE__(1609944441856, function(require, module, exports) {
  4090. Object.defineProperty(exports, "__esModule", { value: true });
  4091. const codegen_1 = require("../../compile/codegen");
  4092. const subschema_1 = require("../../compile/subschema");
  4093. const util_1 = require("../../compile/util");
  4094. const validate_1 = require("../../compile/validate");
  4095. const error = {
  4096. message: ({ params: { len } }) => codegen_1.str `should NOT have more than ${len} items`,
  4097. params: ({ params: { len } }) => codegen_1._ `{limit: ${len}}`,
  4098. };
  4099. const def = {
  4100. keyword: "additionalItems",
  4101. type: "array",
  4102. schemaType: ["boolean", "object"],
  4103. before: "uniqueItems",
  4104. error,
  4105. code(cxt) {
  4106. const { gen, schema, parentSchema, data, it } = cxt;
  4107. const { items } = parentSchema;
  4108. if (!Array.isArray(items)) {
  4109. validate_1.checkStrictMode(it, '"additionalItems" is ignored when "items" is not an array of schemas');
  4110. return;
  4111. }
  4112. it.items = true;
  4113. const len = gen.const("len", codegen_1._ `${data}.length`);
  4114. if (schema === false) {
  4115. cxt.setParams({ len: items.length });
  4116. cxt.pass(codegen_1._ `${len} <= ${items.length}`);
  4117. }
  4118. else if (typeof schema == "object" && !util_1.alwaysValidSchema(it, schema)) {
  4119. const valid = gen.var("valid", codegen_1._ `${len} <= ${items.length}`); // TODO var
  4120. gen.if(codegen_1.not(valid), () => validateItems(valid));
  4121. cxt.ok(valid);
  4122. }
  4123. function validateItems(valid) {
  4124. gen.forRange("i", items.length, len, (i) => {
  4125. cxt.subschema({ keyword: "additionalItems", dataProp: i, dataPropType: subschema_1.Type.Num }, valid);
  4126. if (!it.allErrors)
  4127. gen.if(codegen_1.not(valid), () => gen.break());
  4128. });
  4129. }
  4130. },
  4131. };
  4132. exports.default = def;
  4133. //# sourceMappingURL=additionalItems.js.map
  4134. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/subschema":1609944441834,"../../compile/util":1609944441826,"../../compile/validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  4135. __DEFINE__(1609944441857, function(require, module, exports) {
  4136. Object.defineProperty(exports, "__esModule", { value: true });
  4137. const codegen_1 = require("../../compile/codegen");
  4138. const subschema_1 = require("../../compile/subschema");
  4139. const util_1 = require("../../compile/util");
  4140. const validate_1 = require("../../compile/validate");
  4141. const def = {
  4142. keyword: "items",
  4143. type: "array",
  4144. schemaType: ["object", "array", "boolean"],
  4145. before: "uniqueItems",
  4146. code(cxt) {
  4147. const { gen, schema, parentSchema, data, it } = cxt;
  4148. const len = gen.const("len", codegen_1._ `${data}.length`);
  4149. if (Array.isArray(schema)) {
  4150. if (it.opts.unevaluated && schema.length && it.items !== true) {
  4151. it.items = util_1.mergeEvaluated.items(gen, schema.length, it.items);
  4152. }
  4153. validateTuple(schema);
  4154. }
  4155. else {
  4156. it.items = true;
  4157. if (!util_1.alwaysValidSchema(it, schema))
  4158. validateArray();
  4159. }
  4160. function validateTuple(schArr) {
  4161. if (it.opts.strictTuples && !fullTupleSchema(schema.length, parentSchema)) {
  4162. const msg = `"items" is ${schArr.length}-tuple, but minItems or maxItems/additionalItems are not specified or different`;
  4163. validate_1.checkStrictMode(it, msg, it.opts.strictTuples);
  4164. }
  4165. const valid = gen.name("valid");
  4166. schArr.forEach((sch, i) => {
  4167. if (util_1.alwaysValidSchema(it, sch))
  4168. return;
  4169. gen.if(codegen_1._ `${len} > ${i}`, () => cxt.subschema({
  4170. keyword: "items",
  4171. schemaProp: i,
  4172. dataProp: i,
  4173. strictSchema: it.strictSchema,
  4174. }, valid));
  4175. cxt.ok(valid);
  4176. });
  4177. }
  4178. function validateArray() {
  4179. const valid = gen.name("valid");
  4180. gen.forRange("i", 0, len, (i) => {
  4181. cxt.subschema({
  4182. keyword: "items",
  4183. dataProp: i,
  4184. dataPropType: subschema_1.Type.Num,
  4185. strictSchema: it.strictSchema,
  4186. }, valid);
  4187. if (!it.allErrors)
  4188. gen.if(codegen_1.not(valid), () => gen.break());
  4189. });
  4190. cxt.ok(valid);
  4191. }
  4192. },
  4193. };
  4194. function fullTupleSchema(len, sch) {
  4195. return len === sch.minItems && (len === sch.maxItems || sch.additionalItems === false);
  4196. }
  4197. exports.default = def;
  4198. //# sourceMappingURL=items.js.map
  4199. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/subschema":1609944441834,"../../compile/util":1609944441826,"../../compile/validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  4200. __DEFINE__(1609944441858, function(require, module, exports) {
  4201. Object.defineProperty(exports, "__esModule", { value: true });
  4202. const codegen_1 = require("../../compile/codegen");
  4203. const subschema_1 = require("../../compile/subschema");
  4204. const util_1 = require("../../compile/util");
  4205. const validate_1 = require("../../compile/validate");
  4206. const error = {
  4207. message: ({ params: { min, max } }) => max === undefined
  4208. ? codegen_1.str `should contain at least ${min} valid item(s)`
  4209. : codegen_1.str `should contain at least ${min} and no more than ${max} valid item(s)`,
  4210. params: ({ params: { min, max } }) => max === undefined ? codegen_1._ `{minContains: ${min}}` : codegen_1._ `{minContains: ${min}, maxContains: ${max}}`,
  4211. };
  4212. const def = {
  4213. keyword: "contains",
  4214. type: "array",
  4215. schemaType: ["object", "boolean"],
  4216. before: "uniqueItems",
  4217. trackErrors: true,
  4218. error,
  4219. code(cxt) {
  4220. const { gen, schema, parentSchema, data, it } = cxt;
  4221. let min;
  4222. let max;
  4223. const { minContains, maxContains } = parentSchema;
  4224. if (it.opts.next) {
  4225. min = minContains === undefined ? 1 : minContains;
  4226. max = maxContains;
  4227. }
  4228. else {
  4229. min = 1;
  4230. }
  4231. const len = gen.const("len", codegen_1._ `${data}.length`);
  4232. cxt.setParams({ min, max });
  4233. if (max === undefined && min === 0) {
  4234. validate_1.checkStrictMode(it, `"minContains" == 0 without "maxContains": "contains" keyword ignored`);
  4235. return;
  4236. }
  4237. if (max !== undefined && min > max) {
  4238. validate_1.checkStrictMode(it, `"minContains" > "maxContains" is always invalid`);
  4239. cxt.fail();
  4240. return;
  4241. }
  4242. if (util_1.alwaysValidSchema(it, schema)) {
  4243. let cond = codegen_1._ `${len} >= ${min}`;
  4244. if (max !== undefined)
  4245. cond = codegen_1._ `${cond} && ${len} <= ${max}`;
  4246. cxt.pass(cond);
  4247. return;
  4248. }
  4249. it.items = true;
  4250. const valid = gen.name("valid");
  4251. if (max === undefined && min === 1) {
  4252. validateItems(valid, () => gen.if(valid, () => gen.break()));
  4253. }
  4254. else {
  4255. gen.let(valid, false);
  4256. const schValid = gen.name("_valid");
  4257. const count = gen.let("count", 0);
  4258. validateItems(schValid, () => gen.if(schValid, () => checkLimits(count)));
  4259. }
  4260. cxt.result(valid, () => cxt.reset());
  4261. function validateItems(_valid, block) {
  4262. gen.forRange("i", 0, len, (i) => {
  4263. cxt.subschema({
  4264. keyword: "contains",
  4265. dataProp: i,
  4266. dataPropType: subschema_1.Type.Num,
  4267. compositeRule: true,
  4268. }, _valid);
  4269. block();
  4270. });
  4271. }
  4272. function checkLimits(count) {
  4273. gen.code(codegen_1._ `${count}++`);
  4274. if (max === undefined) {
  4275. gen.if(codegen_1._ `${count} >= ${min}`, () => gen.assign(valid, true).break());
  4276. }
  4277. else {
  4278. gen.if(codegen_1._ `${count} > ${max}`, () => gen.assign(valid, false).break());
  4279. if (min === 1)
  4280. gen.assign(valid, true);
  4281. else
  4282. gen.if(codegen_1._ `${count} >= ${min}`, () => gen.assign(valid, true));
  4283. }
  4284. }
  4285. },
  4286. };
  4287. exports.default = def;
  4288. //# sourceMappingURL=contains.js.map
  4289. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/subschema":1609944441834,"../../compile/util":1609944441826,"../../compile/validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  4290. __DEFINE__(1609944441859, function(require, module, exports) {
  4291. Object.defineProperty(exports, "__esModule", { value: true });
  4292. exports.validateSchemaDeps = exports.validatePropertyDeps = exports.error = void 0;
  4293. const codegen_1 = require("../../compile/codegen");
  4294. const util_1 = require("../../compile/util");
  4295. const code_1 = require("../code");
  4296. exports.error = {
  4297. message: ({ params: { property, depsCount, deps } }) => {
  4298. const property_ies = depsCount === 1 ? "property" : "properties";
  4299. return codegen_1.str `should have ${property_ies} ${deps} when property ${property} is present`;
  4300. },
  4301. params: ({ params: { property, depsCount, deps, missingProperty } }) => codegen_1._ `{property: ${property},
  4302. missingProperty: ${missingProperty},
  4303. depsCount: ${depsCount},
  4304. deps: ${deps}}`,
  4305. };
  4306. const def = {
  4307. keyword: "dependencies",
  4308. type: "object",
  4309. schemaType: "object",
  4310. error: exports.error,
  4311. code(cxt) {
  4312. const [propDeps, schDeps] = splitDependencies(cxt);
  4313. validatePropertyDeps(cxt, propDeps);
  4314. validateSchemaDeps(cxt, schDeps);
  4315. },
  4316. };
  4317. function splitDependencies({ schema }) {
  4318. const propertyDeps = {};
  4319. const schemaDeps = {};
  4320. for (const key in schema) {
  4321. if (key === "__proto__")
  4322. continue;
  4323. const deps = Array.isArray(schema[key]) ? propertyDeps : schemaDeps;
  4324. deps[key] = schema[key];
  4325. }
  4326. return [propertyDeps, schemaDeps];
  4327. }
  4328. function validatePropertyDeps(cxt, propertyDeps = cxt.schema) {
  4329. const { gen, data, it } = cxt;
  4330. if (Object.keys(propertyDeps).length === 0)
  4331. return;
  4332. const missing = gen.let("missing");
  4333. for (const prop in propertyDeps) {
  4334. const deps = propertyDeps[prop];
  4335. if (deps.length === 0)
  4336. continue;
  4337. const hasProperty = code_1.propertyInData(data, prop, it.opts.ownProperties);
  4338. cxt.setParams({
  4339. property: prop,
  4340. depsCount: deps.length,
  4341. deps: deps.join(", "),
  4342. });
  4343. if (it.allErrors) {
  4344. gen.if(hasProperty, () => {
  4345. for (const depProp of deps) {
  4346. code_1.checkReportMissingProp(cxt, depProp);
  4347. }
  4348. });
  4349. }
  4350. else {
  4351. gen.if(codegen_1._ `${hasProperty} && (${code_1.checkMissingProp(cxt, deps, missing)})`);
  4352. code_1.reportMissingProp(cxt, missing);
  4353. gen.else();
  4354. }
  4355. }
  4356. }
  4357. exports.validatePropertyDeps = validatePropertyDeps;
  4358. function validateSchemaDeps(cxt, schemaDeps = cxt.schema) {
  4359. const { gen, data, keyword, it } = cxt;
  4360. const valid = gen.name("valid");
  4361. for (const prop in schemaDeps) {
  4362. if (util_1.alwaysValidSchema(it, schemaDeps[prop]))
  4363. continue;
  4364. gen.if(code_1.propertyInData(data, prop, it.opts.ownProperties), () => {
  4365. const schCxt = cxt.subschema({ keyword, schemaProp: prop }, valid);
  4366. cxt.mergeValidEvaluated(schCxt, valid);
  4367. }, () => gen.var(valid, true) // TODO var
  4368. );
  4369. cxt.ok(valid);
  4370. }
  4371. }
  4372. exports.validateSchemaDeps = validateSchemaDeps;
  4373. exports.default = def;
  4374. //# sourceMappingURL=dependencies.js.map
  4375. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/util":1609944441826,"../code":1609944441832}; return __REQUIRE__(map[modId], modId); })
  4376. __DEFINE__(1609944441860, function(require, module, exports) {
  4377. Object.defineProperty(exports, "__esModule", { value: true });
  4378. const codegen_1 = require("../../compile/codegen");
  4379. const util_1 = require("../../compile/util");
  4380. const error = {
  4381. message: ({ params }) => codegen_1.str `property name '${params.propertyName}' is invalid`,
  4382. params: ({ params }) => codegen_1._ `{propertyName: ${params.propertyName}}`,
  4383. };
  4384. const def = {
  4385. keyword: "propertyNames",
  4386. type: "object",
  4387. schemaType: ["object", "boolean"],
  4388. error,
  4389. code(cxt) {
  4390. const { gen, schema, data, it } = cxt;
  4391. if (util_1.alwaysValidSchema(it, schema))
  4392. return;
  4393. const valid = gen.name("valid");
  4394. gen.forIn("key", data, (key) => {
  4395. cxt.setParams({ propertyName: key });
  4396. cxt.subschema({
  4397. keyword: "propertyNames",
  4398. data: key,
  4399. dataTypes: ["string"],
  4400. propertyName: key,
  4401. compositeRule: true,
  4402. strictSchema: it.strictSchema,
  4403. }, valid);
  4404. gen.if(codegen_1.not(valid), () => {
  4405. cxt.error(true);
  4406. if (!it.allErrors)
  4407. gen.break();
  4408. });
  4409. });
  4410. cxt.ok(valid);
  4411. },
  4412. };
  4413. exports.default = def;
  4414. //# sourceMappingURL=propertyNames.js.map
  4415. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4416. __DEFINE__(1609944441861, function(require, module, exports) {
  4417. Object.defineProperty(exports, "__esModule", { value: true });
  4418. const code_1 = require("../code");
  4419. const codegen_1 = require("../../compile/codegen");
  4420. const names_1 = require("../../compile/names");
  4421. const subschema_1 = require("../../compile/subschema");
  4422. const util_1 = require("../../compile/util");
  4423. const error = {
  4424. message: "should NOT have additional properties",
  4425. params: ({ params }) => codegen_1._ `{additionalProperty: ${params.additionalProperty}}`,
  4426. };
  4427. const def = {
  4428. keyword: "additionalProperties",
  4429. type: ["object"],
  4430. schemaType: ["boolean", "object"],
  4431. allowUndefined: true,
  4432. trackErrors: true,
  4433. error,
  4434. code(cxt) {
  4435. const { gen, schema, parentSchema, data, errsCount, it } = cxt;
  4436. /* istanbul ignore if */
  4437. if (!errsCount)
  4438. throw new Error("ajv implementation error");
  4439. const { allErrors, opts } = it;
  4440. it.props = true;
  4441. if (opts.removeAdditional !== "all" && util_1.alwaysValidSchema(it, schema))
  4442. return;
  4443. const props = code_1.allSchemaProperties(parentSchema.properties);
  4444. const patProps = code_1.allSchemaProperties(parentSchema.patternProperties);
  4445. checkAdditionalProperties();
  4446. cxt.ok(codegen_1._ `${errsCount} === ${names_1.default.errors}`);
  4447. function checkAdditionalProperties() {
  4448. gen.forIn("key", data, (key) => {
  4449. if (!props.length && !patProps.length)
  4450. additionalPropertyCode(key);
  4451. else
  4452. gen.if(isAdditional(key), () => additionalPropertyCode(key));
  4453. });
  4454. }
  4455. function isAdditional(key) {
  4456. let definedProp;
  4457. if (props.length > 8) {
  4458. // TODO maybe an option instead of hard-coded 8?
  4459. const propsSchema = util_1.schemaRefOrVal(it, parentSchema.properties, "properties");
  4460. definedProp = codegen_1._ `${propsSchema}.hasOwnProperty(${key})`;
  4461. }
  4462. else if (props.length) {
  4463. definedProp = codegen_1.or(...props.map((p) => codegen_1._ `${key} === ${p}`));
  4464. }
  4465. else {
  4466. definedProp = codegen_1.nil;
  4467. }
  4468. if (patProps.length) {
  4469. definedProp = codegen_1.or(definedProp, ...patProps.map((p) => codegen_1._ `${code_1.usePattern(gen, p)}.test(${key})`));
  4470. }
  4471. return codegen_1._ `!(${definedProp})`;
  4472. }
  4473. function deleteAdditional(key) {
  4474. gen.code(codegen_1._ `delete ${data}[${key}]`);
  4475. }
  4476. function additionalPropertyCode(key) {
  4477. if (opts.removeAdditional === "all" || (opts.removeAdditional && schema === false)) {
  4478. deleteAdditional(key);
  4479. return;
  4480. }
  4481. if (schema === false) {
  4482. cxt.setParams({ additionalProperty: key });
  4483. cxt.error();
  4484. if (!allErrors)
  4485. gen.break();
  4486. return;
  4487. }
  4488. if (typeof schema == "object" && !util_1.alwaysValidSchema(it, schema)) {
  4489. const valid = gen.name("valid");
  4490. if (opts.removeAdditional === "failing") {
  4491. applyAdditionalSchema(key, valid, false);
  4492. gen.if(codegen_1.not(valid), () => {
  4493. cxt.reset();
  4494. deleteAdditional(key);
  4495. });
  4496. }
  4497. else {
  4498. applyAdditionalSchema(key, valid);
  4499. if (!allErrors)
  4500. gen.if(codegen_1.not(valid), () => gen.break());
  4501. }
  4502. }
  4503. }
  4504. function applyAdditionalSchema(key, valid, errors) {
  4505. const subschema = {
  4506. keyword: "additionalProperties",
  4507. dataProp: key,
  4508. dataPropType: subschema_1.Type.Str,
  4509. strictSchema: it.strictSchema,
  4510. };
  4511. if (errors === false) {
  4512. Object.assign(subschema, {
  4513. compositeRule: true,
  4514. createErrors: false,
  4515. allErrors: false,
  4516. });
  4517. }
  4518. cxt.subschema(subschema, valid);
  4519. }
  4520. },
  4521. };
  4522. exports.default = def;
  4523. //# sourceMappingURL=additionalProperties.js.map
  4524. }, function(modId) { var map = {"../code":1609944441832,"../../compile/codegen":1609944441822,"../../compile/names":1609944441825,"../../compile/subschema":1609944441834,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4525. __DEFINE__(1609944441862, function(require, module, exports) {
  4526. Object.defineProperty(exports, "__esModule", { value: true });
  4527. const context_1 = require("../../compile/context");
  4528. const code_1 = require("../code");
  4529. const util_1 = require("../../compile/util");
  4530. const additionalProperties_1 = require("./additionalProperties");
  4531. const def = {
  4532. keyword: "properties",
  4533. type: "object",
  4534. schemaType: "object",
  4535. code(cxt) {
  4536. const { gen, schema, parentSchema, data, it } = cxt;
  4537. if (it.opts.removeAdditional === "all" && parentSchema.additionalProperties === undefined) {
  4538. additionalProperties_1.default.code(new context_1.default(it, additionalProperties_1.default, "additionalProperties"));
  4539. }
  4540. const allProps = code_1.allSchemaProperties(schema);
  4541. if (it.opts.unevaluated && allProps.length && it.props !== true) {
  4542. it.props = util_1.mergeEvaluated.props(gen, util_1.toHash(allProps), it.props);
  4543. }
  4544. const properties = allProps.filter((p) => !util_1.alwaysValidSchema(it, schema[p]));
  4545. if (properties.length === 0)
  4546. return;
  4547. const valid = gen.name("valid");
  4548. for (const prop of properties) {
  4549. if (hasDefault(prop)) {
  4550. applyPropertySchema(prop);
  4551. }
  4552. else {
  4553. gen.if(code_1.propertyInData(data, prop, it.opts.ownProperties));
  4554. applyPropertySchema(prop);
  4555. if (!it.allErrors)
  4556. gen.else().var(valid, true);
  4557. gen.endIf();
  4558. }
  4559. cxt.ok(valid);
  4560. }
  4561. function hasDefault(prop) {
  4562. return it.opts.useDefaults && !it.compositeRule && schema[prop].default !== undefined;
  4563. }
  4564. function applyPropertySchema(prop) {
  4565. cxt.subschema({
  4566. keyword: "properties",
  4567. schemaProp: prop,
  4568. dataProp: prop,
  4569. strictSchema: it.strictSchema,
  4570. }, valid);
  4571. }
  4572. },
  4573. };
  4574. exports.default = def;
  4575. //# sourceMappingURL=properties.js.map
  4576. }, function(modId) { var map = {"../../compile/context":1609944441817,"../code":1609944441832,"../../compile/util":1609944441826,"./additionalProperties":1609944441861}; return __REQUIRE__(map[modId], modId); })
  4577. __DEFINE__(1609944441863, function(require, module, exports) {
  4578. Object.defineProperty(exports, "__esModule", { value: true });
  4579. const code_1 = require("../code");
  4580. const codegen_1 = require("../../compile/codegen");
  4581. const subschema_1 = require("../../compile/subschema");
  4582. const validate_1 = require("../../compile/validate");
  4583. const util_1 = require("../../compile/util");
  4584. const def = {
  4585. keyword: "patternProperties",
  4586. type: "object",
  4587. schemaType: "object",
  4588. code(cxt) {
  4589. const { gen, schema, data, parentSchema, it } = cxt;
  4590. const { opts } = it;
  4591. const patterns = code_1.schemaProperties(it, schema);
  4592. // TODO mark properties matching patterns with always valid schemas as evaluated
  4593. if (patterns.length === 0)
  4594. return;
  4595. const checkProperties = opts.strict && !opts.allowMatchingProperties && parentSchema.properties;
  4596. const valid = gen.name("valid");
  4597. if (it.props !== true && !(it.props instanceof codegen_1.Name)) {
  4598. it.props = util_1.evaluatedPropsToName(gen, it.props);
  4599. }
  4600. const { props } = it;
  4601. validatePatternProperties();
  4602. function validatePatternProperties() {
  4603. for (const pat of patterns) {
  4604. if (checkProperties)
  4605. checkMatchingProperties(pat);
  4606. if (it.allErrors) {
  4607. validateProperties(pat);
  4608. }
  4609. else {
  4610. gen.var(valid, true); // TODO var
  4611. validateProperties(pat);
  4612. gen.if(valid);
  4613. }
  4614. }
  4615. }
  4616. function checkMatchingProperties(pat) {
  4617. for (const prop in checkProperties) {
  4618. if (new RegExp(pat).test(prop)) {
  4619. validate_1.checkStrictMode(it, `property ${prop} matches pattern ${pat} (use allowMatchingProperties)`);
  4620. }
  4621. }
  4622. }
  4623. function validateProperties(pat) {
  4624. gen.forIn("key", data, (key) => {
  4625. gen.if(codegen_1._ `${code_1.usePattern(gen, pat)}.test(${key})`, () => {
  4626. cxt.subschema({
  4627. keyword: "patternProperties",
  4628. schemaProp: pat,
  4629. dataProp: key,
  4630. dataPropType: subschema_1.Type.Str,
  4631. strictSchema: it.strictSchema,
  4632. }, valid);
  4633. if (it.opts.unevaluated && props !== true) {
  4634. gen.assign(codegen_1._ `${props}[${key}]`, true);
  4635. }
  4636. else if (!it.allErrors) {
  4637. // can short-circuit if `unevaluatedProperties` is not supported (opts.next === false)
  4638. // or if all properties were evaluated (props === true)
  4639. gen.if(codegen_1.not(valid), () => gen.break());
  4640. }
  4641. });
  4642. });
  4643. }
  4644. },
  4645. };
  4646. exports.default = def;
  4647. //# sourceMappingURL=patternProperties.js.map
  4648. }, function(modId) { var map = {"../code":1609944441832,"../../compile/codegen":1609944441822,"../../compile/subschema":1609944441834,"../../compile/validate":1609944441827,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4649. __DEFINE__(1609944441864, function(require, module, exports) {
  4650. Object.defineProperty(exports, "__esModule", { value: true });
  4651. const util_1 = require("../../compile/util");
  4652. const def = {
  4653. keyword: "not",
  4654. schemaType: ["object", "boolean"],
  4655. trackErrors: true,
  4656. code(cxt) {
  4657. const { gen, schema, it } = cxt;
  4658. if (util_1.alwaysValidSchema(it, schema)) {
  4659. cxt.fail();
  4660. return;
  4661. }
  4662. const valid = gen.name("valid");
  4663. cxt.subschema({
  4664. keyword: "not",
  4665. compositeRule: true,
  4666. createErrors: false,
  4667. allErrors: false,
  4668. }, valid);
  4669. cxt.result(valid, () => cxt.error(), () => cxt.reset());
  4670. },
  4671. error: {
  4672. message: "should NOT be valid",
  4673. },
  4674. };
  4675. exports.default = def;
  4676. //# sourceMappingURL=not.js.map
  4677. }, function(modId) { var map = {"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4678. __DEFINE__(1609944441865, function(require, module, exports) {
  4679. Object.defineProperty(exports, "__esModule", { value: true });
  4680. const codegen_1 = require("../../compile/codegen");
  4681. const util_1 = require("../../compile/util");
  4682. const def = {
  4683. keyword: "anyOf",
  4684. schemaType: "array",
  4685. trackErrors: true,
  4686. code(cxt) {
  4687. const { gen, schema, it } = cxt;
  4688. /* istanbul ignore if */
  4689. if (!Array.isArray(schema))
  4690. throw new Error("ajv implementation error");
  4691. const alwaysValid = schema.some((sch) => util_1.alwaysValidSchema(it, sch));
  4692. if (alwaysValid && !it.opts.unevaluated)
  4693. return;
  4694. const valid = gen.let("valid", false);
  4695. const schValid = gen.name("_valid");
  4696. gen.block(() => schema.forEach((_sch, i) => {
  4697. const schCxt = cxt.subschema({
  4698. keyword: "anyOf",
  4699. schemaProp: i,
  4700. compositeRule: true,
  4701. }, schValid);
  4702. gen.assign(valid, codegen_1._ `${valid} || ${schValid}`);
  4703. const merged = cxt.mergeValidEvaluated(schCxt, schValid);
  4704. // can short-circuit if `unevaluatedProperties/Items` not supported (opts.unevaluated !== true)
  4705. // or if all properties and items were evaluated (it.props === true && it.items === true)
  4706. if (!merged)
  4707. gen.if(codegen_1.not(valid));
  4708. }));
  4709. cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
  4710. },
  4711. error: {
  4712. message: "should match some schema in anyOf",
  4713. },
  4714. };
  4715. exports.default = def;
  4716. //# sourceMappingURL=anyOf.js.map
  4717. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4718. __DEFINE__(1609944441866, function(require, module, exports) {
  4719. Object.defineProperty(exports, "__esModule", { value: true });
  4720. const codegen_1 = require("../../compile/codegen");
  4721. const util_1 = require("../../compile/util");
  4722. const error = {
  4723. message: "should match exactly one schema in oneOf",
  4724. params: ({ params }) => codegen_1._ `{passingSchemas: ${params.passing}}`,
  4725. };
  4726. const def = {
  4727. keyword: "oneOf",
  4728. schemaType: "array",
  4729. trackErrors: true,
  4730. error,
  4731. code(cxt) {
  4732. const { gen, schema, it } = cxt;
  4733. /* istanbul ignore if */
  4734. if (!Array.isArray(schema))
  4735. throw new Error("ajv implementation error");
  4736. const schArr = schema;
  4737. const valid = gen.let("valid", false);
  4738. const passing = gen.let("passing", null);
  4739. const schValid = gen.name("_valid");
  4740. cxt.setParams({ passing });
  4741. // TODO possibly fail straight away (with warning or exception) if there are two empty always valid schemas
  4742. gen.block(validateOneOf);
  4743. cxt.result(valid, () => cxt.reset(), () => cxt.error(true));
  4744. function validateOneOf() {
  4745. schArr.forEach((sch, i) => {
  4746. let schCxt;
  4747. if (util_1.alwaysValidSchema(it, sch)) {
  4748. gen.var(schValid, true);
  4749. }
  4750. else {
  4751. schCxt = cxt.subschema({
  4752. keyword: "oneOf",
  4753. schemaProp: i,
  4754. compositeRule: true,
  4755. }, schValid);
  4756. }
  4757. if (i > 0) {
  4758. gen
  4759. .if(codegen_1._ `${schValid} && ${valid}`)
  4760. .assign(valid, false)
  4761. .assign(passing, codegen_1._ `[${passing}, ${i}]`)
  4762. .else();
  4763. }
  4764. gen.if(schValid, () => {
  4765. gen.assign(valid, true);
  4766. gen.assign(passing, i);
  4767. if (schCxt)
  4768. cxt.mergeEvaluated(schCxt, codegen_1.Name);
  4769. });
  4770. });
  4771. }
  4772. },
  4773. };
  4774. exports.default = def;
  4775. //# sourceMappingURL=oneOf.js.map
  4776. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4777. __DEFINE__(1609944441867, function(require, module, exports) {
  4778. Object.defineProperty(exports, "__esModule", { value: true });
  4779. const util_1 = require("../../compile/util");
  4780. const def = {
  4781. keyword: "allOf",
  4782. schemaType: "array",
  4783. code(cxt) {
  4784. const { gen, schema, it } = cxt;
  4785. /* istanbul ignore if */
  4786. if (!Array.isArray(schema))
  4787. throw new Error("ajv implementation error");
  4788. const valid = gen.name("valid");
  4789. schema.forEach((sch, i) => {
  4790. if (util_1.alwaysValidSchema(it, sch))
  4791. return;
  4792. const schCxt = cxt.subschema({ keyword: "allOf", schemaProp: i }, valid);
  4793. cxt.ok(valid);
  4794. cxt.mergeEvaluated(schCxt);
  4795. });
  4796. },
  4797. };
  4798. exports.default = def;
  4799. //# sourceMappingURL=allOf.js.map
  4800. }, function(modId) { var map = {"../../compile/util":1609944441826}; return __REQUIRE__(map[modId], modId); })
  4801. __DEFINE__(1609944441868, function(require, module, exports) {
  4802. Object.defineProperty(exports, "__esModule", { value: true });
  4803. const codegen_1 = require("../../compile/codegen");
  4804. const util_1 = require("../../compile/util");
  4805. const validate_1 = require("../../compile/validate");
  4806. const error = {
  4807. message: ({ params }) => codegen_1.str `should match "${params.ifClause}" schema`,
  4808. params: ({ params }) => codegen_1._ `{failingKeyword: ${params.ifClause}}`,
  4809. };
  4810. const def = {
  4811. keyword: "if",
  4812. schemaType: ["object", "boolean"],
  4813. trackErrors: true,
  4814. error,
  4815. code(cxt) {
  4816. const { gen, parentSchema, it } = cxt;
  4817. if (parentSchema.then === undefined && parentSchema.else === undefined) {
  4818. validate_1.checkStrictMode(it, '"if" without "then" and "else" is ignored');
  4819. }
  4820. const hasThen = hasSchema(it, "then");
  4821. const hasElse = hasSchema(it, "else");
  4822. if (!hasThen && !hasElse)
  4823. return;
  4824. const valid = gen.let("valid", true);
  4825. const schValid = gen.name("_valid");
  4826. validateIf();
  4827. cxt.reset();
  4828. if (hasThen && hasElse) {
  4829. const ifClause = gen.let("ifClause");
  4830. cxt.setParams({ ifClause });
  4831. gen.if(schValid, validateClause("then", ifClause), validateClause("else", ifClause));
  4832. }
  4833. else if (hasThen) {
  4834. gen.if(schValid, validateClause("then"));
  4835. }
  4836. else {
  4837. gen.if(codegen_1.not(schValid), validateClause("else"));
  4838. }
  4839. cxt.pass(valid, () => cxt.error(true));
  4840. function validateIf() {
  4841. const schCxt = cxt.subschema({
  4842. keyword: "if",
  4843. compositeRule: true,
  4844. createErrors: false,
  4845. allErrors: false,
  4846. }, schValid);
  4847. cxt.mergeEvaluated(schCxt);
  4848. }
  4849. function validateClause(keyword, ifClause) {
  4850. return () => {
  4851. const schCxt = cxt.subschema({ keyword }, schValid);
  4852. gen.assign(valid, schValid);
  4853. cxt.mergeValidEvaluated(schCxt, valid);
  4854. if (ifClause)
  4855. gen.assign(ifClause, codegen_1._ `${keyword}`);
  4856. else
  4857. cxt.setParams({ ifClause: keyword });
  4858. };
  4859. }
  4860. },
  4861. };
  4862. function hasSchema(it, keyword) {
  4863. const schema = it.schema[keyword];
  4864. return schema !== undefined && !util_1.alwaysValidSchema(it, schema);
  4865. }
  4866. exports.default = def;
  4867. //# sourceMappingURL=if.js.map
  4868. }, function(modId) { var map = {"../../compile/codegen":1609944441822,"../../compile/util":1609944441826,"../../compile/validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  4869. __DEFINE__(1609944441869, function(require, module, exports) {
  4870. Object.defineProperty(exports, "__esModule", { value: true });
  4871. const validate_1 = require("../../compile/validate");
  4872. const def = {
  4873. keyword: ["then", "else"],
  4874. schemaType: ["object", "boolean"],
  4875. code({ keyword, parentSchema, it }) {
  4876. if (parentSchema.if === undefined)
  4877. validate_1.checkStrictMode(it, `"${keyword}" without "if" is ignored`);
  4878. },
  4879. };
  4880. exports.default = def;
  4881. //# sourceMappingURL=thenElse.js.map
  4882. }, function(modId) { var map = {"../../compile/validate":1609944441827}; return __REQUIRE__(map[modId], modId); })
  4883. __DEFINE__(1609944441870, function(require, module, exports) {
  4884. Object.defineProperty(exports, "__esModule", { value: true });
  4885. const format_1 = require("./format");
  4886. const format = [format_1.default];
  4887. exports.default = format;
  4888. //# sourceMappingURL=index.js.map
  4889. }, function(modId) { var map = {"./format":1609944441871}; return __REQUIRE__(map[modId], modId); })
  4890. __DEFINE__(1609944441871, function(require, module, exports) {
  4891. Object.defineProperty(exports, "__esModule", { value: true });
  4892. const codegen_1 = require("../../compile/codegen");
  4893. const error = {
  4894. message: ({ schemaCode }) => codegen_1.str `should match format "${schemaCode}"`,
  4895. params: ({ schemaCode }) => codegen_1._ `{format: ${schemaCode}}`,
  4896. };
  4897. const def = {
  4898. keyword: "format",
  4899. type: ["number", "string"],
  4900. schemaType: "string",
  4901. $data: true,
  4902. error,
  4903. code(cxt, ruleType) {
  4904. const { gen, data, $data, schema, schemaCode, it } = cxt;
  4905. const { opts, errSchemaPath, schemaEnv, self } = it;
  4906. if (!opts.validateFormats)
  4907. return;
  4908. if ($data)
  4909. validate$DataFormat();
  4910. else
  4911. validateFormat();
  4912. function validate$DataFormat() {
  4913. const fmts = gen.scopeValue("formats", {
  4914. ref: self.formats,
  4915. code: opts.code.formats,
  4916. });
  4917. const fDef = gen.const("fDef", codegen_1._ `${fmts}[${schemaCode}]`);
  4918. const fType = gen.let("fType");
  4919. const format = gen.let("format");
  4920. // TODO simplify
  4921. gen.if(codegen_1._ `typeof ${fDef} == "object" && !(${fDef} instanceof RegExp)`, () => gen.assign(fType, codegen_1._ `${fDef}.type || "string"`).assign(format, codegen_1._ `${fDef}.validate`), () => gen.assign(fType, codegen_1._ `"string"`).assign(format, fDef));
  4922. cxt.fail$data(codegen_1.or(unknownFmt(), invalidFmt()));
  4923. function unknownFmt() {
  4924. if (opts.strict === false)
  4925. return codegen_1.nil;
  4926. return codegen_1._ `${schemaCode} && !${format}`;
  4927. }
  4928. function invalidFmt() {
  4929. const callFormat = schemaEnv.$async
  4930. ? codegen_1._ `(${fDef}.async ? await ${format}(${data}) : ${format}(${data}))`
  4931. : codegen_1._ `${format}(${data})`;
  4932. const validData = codegen_1._ `(typeof ${format} == "function" ? ${callFormat} : ${format}.test(${data}))`;
  4933. return codegen_1._ `${format} && ${format} !== true && ${fType} === ${ruleType} && !${validData}`;
  4934. }
  4935. }
  4936. function validateFormat() {
  4937. const formatDef = self.formats[schema];
  4938. if (!formatDef) {
  4939. unknownFormat();
  4940. return;
  4941. }
  4942. if (formatDef === true)
  4943. return;
  4944. const [fmtType, format, fmtRef] = getFormat(formatDef);
  4945. if (fmtType === ruleType)
  4946. cxt.pass(validCondition());
  4947. function unknownFormat() {
  4948. if (opts.strict === false) {
  4949. self.logger.warn(unknownMsg());
  4950. return;
  4951. }
  4952. throw new Error(unknownMsg());
  4953. function unknownMsg() {
  4954. return `unknown format "${schema}" ignored in schema at path "${errSchemaPath}"`;
  4955. }
  4956. }
  4957. function getFormat(fmtDef) {
  4958. const fmt = gen.scopeValue("formats", {
  4959. key: schema,
  4960. ref: fmtDef,
  4961. code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(schema)}` : undefined,
  4962. });
  4963. if (typeof fmtDef == "object" && !(fmtDef instanceof RegExp)) {
  4964. return [fmtDef.type || "string", fmtDef.validate, codegen_1._ `${fmt}.validate`];
  4965. }
  4966. return ["string", fmtDef, fmt];
  4967. }
  4968. function validCondition() {
  4969. if (typeof formatDef == "object" && !(formatDef instanceof RegExp) && formatDef.async) {
  4970. if (!schemaEnv.$async)
  4971. throw new Error("async format in sync schema");
  4972. return codegen_1._ `await ${fmtRef}(${data})`;
  4973. }
  4974. return typeof format == "function" ? codegen_1._ `${fmtRef}(${data})` : codegen_1._ `${fmtRef}.test(${data})`;
  4975. }
  4976. }
  4977. },
  4978. };
  4979. exports.default = def;
  4980. //# sourceMappingURL=format.js.map
  4981. }, function(modId) { var map = {"../../compile/codegen":1609944441822}; return __REQUIRE__(map[modId], modId); })
  4982. __DEFINE__(1609944441872, function(require, module, exports) {
  4983. Object.defineProperty(exports, "__esModule", { value: true });
  4984. exports.contentVocabulary = exports.metadataVocabulary = void 0;
  4985. exports.metadataVocabulary = [
  4986. "title",
  4987. "description",
  4988. "default",
  4989. "deprecated",
  4990. "readOnly",
  4991. "writeOnly",
  4992. "examples",
  4993. ];
  4994. exports.contentVocabulary = [
  4995. "contentMediaType",
  4996. "contentEncoding",
  4997. "contentSchema",
  4998. ];
  4999. //# sourceMappingURL=metadata.js.map
  5000. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  5001. __DEFINE__(1609944441873, function(require, module, exports) {
  5002. module.exports = {
  5003. "$schema": "http://json-schema.org/draft-07/schema#",
  5004. "$id": "http://json-schema.org/draft-07/schema#",
  5005. "title": "Core schema meta-schema",
  5006. "definitions": {
  5007. "schemaArray": {
  5008. "type": "array",
  5009. "minItems": 1,
  5010. "items": {"$ref": "#"}
  5011. },
  5012. "nonNegativeInteger": {
  5013. "type": "integer",
  5014. "minimum": 0
  5015. },
  5016. "nonNegativeIntegerDefault0": {
  5017. "allOf": [{"$ref": "#/definitions/nonNegativeInteger"}, {"default": 0}]
  5018. },
  5019. "simpleTypes": {
  5020. "enum": ["array", "boolean", "integer", "null", "number", "object", "string"]
  5021. },
  5022. "stringArray": {
  5023. "type": "array",
  5024. "items": {"type": "string"},
  5025. "uniqueItems": true,
  5026. "default": []
  5027. }
  5028. },
  5029. "type": ["object", "boolean"],
  5030. "properties": {
  5031. "$id": {
  5032. "type": "string",
  5033. "format": "uri-reference"
  5034. },
  5035. "$schema": {
  5036. "type": "string",
  5037. "format": "uri"
  5038. },
  5039. "$ref": {
  5040. "type": "string",
  5041. "format": "uri-reference"
  5042. },
  5043. "$comment": {
  5044. "type": "string"
  5045. },
  5046. "title": {
  5047. "type": "string"
  5048. },
  5049. "description": {
  5050. "type": "string"
  5051. },
  5052. "default": true,
  5053. "readOnly": {
  5054. "type": "boolean",
  5055. "default": false
  5056. },
  5057. "examples": {
  5058. "type": "array",
  5059. "items": true
  5060. },
  5061. "multipleOf": {
  5062. "type": "number",
  5063. "exclusiveMinimum": 0
  5064. },
  5065. "maximum": {
  5066. "type": "number"
  5067. },
  5068. "exclusiveMaximum": {
  5069. "type": "number"
  5070. },
  5071. "minimum": {
  5072. "type": "number"
  5073. },
  5074. "exclusiveMinimum": {
  5075. "type": "number"
  5076. },
  5077. "maxLength": {"$ref": "#/definitions/nonNegativeInteger"},
  5078. "minLength": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
  5079. "pattern": {
  5080. "type": "string",
  5081. "format": "regex"
  5082. },
  5083. "additionalItems": {"$ref": "#"},
  5084. "items": {
  5085. "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/schemaArray"}],
  5086. "default": true
  5087. },
  5088. "maxItems": {"$ref": "#/definitions/nonNegativeInteger"},
  5089. "minItems": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
  5090. "uniqueItems": {
  5091. "type": "boolean",
  5092. "default": false
  5093. },
  5094. "contains": {"$ref": "#"},
  5095. "maxProperties": {"$ref": "#/definitions/nonNegativeInteger"},
  5096. "minProperties": {"$ref": "#/definitions/nonNegativeIntegerDefault0"},
  5097. "required": {"$ref": "#/definitions/stringArray"},
  5098. "additionalProperties": {"$ref": "#"},
  5099. "definitions": {
  5100. "type": "object",
  5101. "additionalProperties": {"$ref": "#"},
  5102. "default": {}
  5103. },
  5104. "properties": {
  5105. "type": "object",
  5106. "additionalProperties": {"$ref": "#"},
  5107. "default": {}
  5108. },
  5109. "patternProperties": {
  5110. "type": "object",
  5111. "additionalProperties": {"$ref": "#"},
  5112. "propertyNames": {"format": "regex"},
  5113. "default": {}
  5114. },
  5115. "dependencies": {
  5116. "type": "object",
  5117. "additionalProperties": {
  5118. "anyOf": [{"$ref": "#"}, {"$ref": "#/definitions/stringArray"}]
  5119. }
  5120. },
  5121. "propertyNames": {"$ref": "#"},
  5122. "const": true,
  5123. "enum": {
  5124. "type": "array",
  5125. "items": true,
  5126. "minItems": 1,
  5127. "uniqueItems": true
  5128. },
  5129. "type": {
  5130. "anyOf": [
  5131. {"$ref": "#/definitions/simpleTypes"},
  5132. {
  5133. "type": "array",
  5134. "items": {"$ref": "#/definitions/simpleTypes"},
  5135. "minItems": 1,
  5136. "uniqueItems": true
  5137. }
  5138. ]
  5139. },
  5140. "format": {"type": "string"},
  5141. "contentMediaType": {"type": "string"},
  5142. "contentEncoding": {"type": "string"},
  5143. "if": {"$ref": "#"},
  5144. "then": {"$ref": "#"},
  5145. "else": {"$ref": "#"},
  5146. "allOf": {"$ref": "#/definitions/schemaArray"},
  5147. "anyOf": {"$ref": "#/definitions/schemaArray"},
  5148. "oneOf": {"$ref": "#/definitions/schemaArray"},
  5149. "not": {"$ref": "#"}
  5150. },
  5151. "default": true
  5152. }
  5153. }, function(modId) { var map = {}; return __REQUIRE__(map[modId], modId); })
  5154. return __REQUIRE__(1609944441816);
  5155. })()
  5156. //# sourceMappingURL=index.js.map