@altostra/core
Version:
Core library for shared types and logic
1 lines • 1.37 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0}),exports.getConflictingPathParams=exports.getDuplicateEndpoints=void 0;const from_1=require("@reactivex/ix-es2015-cjs/iterable/from"),Common_1=require("../../../Common"),lowerCaseHttpMethods=Common_1.realHttpMethods.map(t=>t.toLowerCase());function getDuplicateEndpoints(t){return(0,from_1.from)({*[Symbol.iterator](){const o={};for(const e of t){const t=e.method.toLowerCase(),r=e.path.toLowerCase(),n="any"!==t?[t]:lowerCaseHttpMethods;for(const t of n)o[t]?o[t][r]?o[t][r].push(e):o[t][r]=[e]:o[t]={[r]:[e]}}for(const t of Object.values(o))if(t)for(const o of Object.values(t))o&&o.length>=2&&(yield o)}})}function getConflictingPathParams(t){return(0,from_1.from)({*[Symbol.iterator](){const o={};for(const e of t){const t=getRouteParams(e.path);for(const r of t)o[r.route]?o[r.route][r.name]?o[r.route][r.name].push(e):o[r.route][r.name]=[e]:o[r.route]={[r.name]:[e]};for(const[t,e]of Object.entries(o))e&&Object.keys(e).length>1&&(yield{route:t,params:e})}}})}exports.getDuplicateEndpoints=getDuplicateEndpoints,exports.getConflictingPathParams=getConflictingPathParams;const paramRX=/^\{(.+)\}$/;function getRouteParams(t){const o=t.split("/");return o.shift(),{*[Symbol.iterator](){let t="";for(const e of o){const o=paramRX.exec(e);if(o){const e=o[1];yield{name:e,route:t||"/"}}t+="/"+e}}}}