diff --git a/src/extractors/scopes.ts b/src/extractors/scopes.ts index d7c04b9..84eb0bd 100644 --- a/src/extractors/scopes.ts +++ b/src/extractors/scopes.ts @@ -1,4 +1,6 @@ -export default (line: string): string[] => { +import { BlockMode } from '../../types/interfaces'; + +export default (line: string): ['request' | 'req', BlockMode, string?] => { const matches = []; const cases = { SCOPE: 0, @@ -105,5 +107,5 @@ export default (line: string): string[] => { matches.push(rebuild); } - return matches; + return matches as ['request' | 'req', BlockMode, string?]; }; diff --git a/src/finders/request/body.ts b/src/finders/request/body.ts index d464909..3c7ad59 100644 --- a/src/finders/request/body.ts +++ b/src/finders/request/body.ts @@ -23,7 +23,8 @@ export default function requestModeBodyFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'body' }; } if (_key.includes('getBodyField(')) { @@ -34,7 +35,8 @@ export default function requestModeBodyFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'body' }; } if (_key === 'body' && extracted[1].charAt(0) === '{') { @@ -50,7 +52,8 @@ export default function requestModeBodyFinder( link, linked: false, line_index: index, - key + key, + mode: 'body' }; } if (_key === 'body') { @@ -58,7 +61,8 @@ export default function requestModeBodyFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'body' }; } } diff --git a/src/finders/request/cookies.ts b/src/finders/request/cookies.ts index 4f3e734..d05dd5f 100644 --- a/src/finders/request/cookies.ts +++ b/src/finders/request/cookies.ts @@ -23,7 +23,8 @@ export default function requestModeCookiesFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'cookies' }; } if (_key.includes('cookie(')) { @@ -34,7 +35,8 @@ export default function requestModeCookiesFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'cookies' }; } if (_key === 'cookies' && extracted[1].charAt(0) === '{') { @@ -50,7 +52,8 @@ export default function requestModeCookiesFinder( link, linked: false, line_index: index, - key + key, + mode: 'cookies' }; } if (_key === 'cookies') { @@ -58,7 +61,8 @@ export default function requestModeCookiesFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'cookies' }; } } diff --git a/src/finders/request/headers.ts b/src/finders/request/headers.ts index 040eef4..4d248af 100644 --- a/src/finders/request/headers.ts +++ b/src/finders/request/headers.ts @@ -23,7 +23,8 @@ export default function requestModeHeadersFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'headers' }; } if (_key.includes('header(')) { @@ -34,7 +35,8 @@ export default function requestModeHeadersFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'headers' }; } if (_key.includes('getHeader(')) { @@ -54,7 +56,8 @@ export default function requestModeHeadersFinder( link, linked: false, line_index: index, - key + key, + mode: 'headers' }; } if (_key === 'headers') { @@ -62,7 +65,8 @@ export default function requestModeHeadersFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'headers' }; } } diff --git a/src/finders/request/index.ts b/src/finders/request/index.ts index 6749fa3..84b985f 100644 --- a/src/finders/request/index.ts +++ b/src/finders/request/index.ts @@ -31,25 +31,19 @@ export default function caseRequestModeFinder( linked: false, line_index: index, key: _skey, - mode: _key as any + mode: _key }; } // Headers matching res = requestModeHeadersFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'headers'; - } return res; } // Cookies matching res = requestModeCookiesFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'cookies'; - } return res; } @@ -57,36 +51,24 @@ export default function caseRequestModeFinder( res = requestModeParamsFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'params'; - } return res; } // Params matching res = requestModeQueryFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'query'; - } return res; } // Body matching res = requestModeBodyFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'body'; - } return res; } // Method matching res = requestMethodFinder(_, _key, line, index); if (res !== undefined) { - if (res !== null) { - res.mode = 'property'; - } return res; } } else { @@ -100,7 +82,6 @@ export default function caseRequestModeFinder( index ); if (res) { - res.mode = 'property'; return res; } } diff --git a/src/finders/request/params.ts b/src/finders/request/params.ts index f187641..961311b 100644 --- a/src/finders/request/params.ts +++ b/src/finders/request/params.ts @@ -23,7 +23,8 @@ export default function requestModeParamsFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'params' }; } if (_key.includes('param(')) { @@ -34,7 +35,8 @@ export default function requestModeParamsFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'params' }; } if (_key.includes('getParameter(')) { @@ -54,7 +56,8 @@ export default function requestModeParamsFinder( link, linked: false, line_index: index, - key + key, + mode: 'params' }; } if (_key === 'params') { @@ -62,7 +65,8 @@ export default function requestModeParamsFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'params' }; } } diff --git a/src/finders/request/property.ts b/src/finders/request/property.ts index 6ce56c3..e6cafec 100644 --- a/src/finders/request/property.ts +++ b/src/finders/request/property.ts @@ -23,7 +23,8 @@ export default function requestMethodFinder( link: extracted[1], linked: false, line_index: index, - key: _key + key: _key, + mode: 'property' }; } if (_key.includes('getMethod(') || _key.includes('getUrl(')) { @@ -46,7 +47,8 @@ export default function requestMethodFinder( link, linked: false, line_index: index, - key + key, + mode: 'property' }; } if (_key.endsWith('req') || _key.endsWith('request')) { @@ -54,7 +56,8 @@ export default function requestMethodFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'property' }; } diff --git a/src/finders/request/query.ts b/src/finders/request/query.ts index ea7a8f3..ed9aa6a 100644 --- a/src/finders/request/query.ts +++ b/src/finders/request/query.ts @@ -23,7 +23,8 @@ export default function requestModeQueryFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'query' }; } if (_key.includes('getQuery(')) { @@ -34,7 +35,8 @@ export default function requestModeQueryFinder( link: extracted[1], linked: false, line_index: index, - key + key, + mode: 'query' }; } if (_key === 'query' && extracted[1].charAt(0) === '{') { @@ -50,7 +52,8 @@ export default function requestModeQueryFinder( link, linked: false, line_index: index, - key + key, + mode: 'query' }; } if (_key === 'query') { @@ -58,7 +61,8 @@ export default function requestModeQueryFinder( link: extracted[1], linked: false, line_index: index, - key: '*' + key: '*', + mode: 'query' }; } } diff --git a/types/interfaces.d.ts b/types/interfaces.d.ts index e70e422..05d249b 100644 --- a/types/interfaces.d.ts +++ b/types/interfaces.d.ts @@ -1,7 +1,9 @@ +export type BlockMode ='headers' | 'cookies' | 'params' | 'query' | 'body' | 'property' + export interface IBlock { link: string; linked: boolean; line_index: number; key: string | '*'; - mode?: 'headers' | 'cookies' | 'params' | 'query' | 'body' | 'property'; + mode: BlockMode; }