Skip to content

Commit

Permalink
fix(typescript): fixes and improvements to typings for better stability
Browse files Browse the repository at this point in the history
  • Loading branch information
dalisoft committed Oct 17, 2021
1 parent 841bc91 commit f9487ab
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 46 deletions.
6 changes: 4 additions & 2 deletions src/extractors/scopes.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -105,5 +107,5 @@ export default (line: string): string[] => {
matches.push(rebuild);
}

return matches;
return matches as ['request' | 'req', BlockMode, string?];
};
12 changes: 8 additions & 4 deletions src/finders/request/body.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function requestModeBodyFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'body'
};
}
if (_key.includes('getBodyField(')) {
Expand All @@ -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) === '{') {
Expand All @@ -50,15 +52,17 @@ export default function requestModeBodyFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'body'
};
}
if (_key === 'body') {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'body'
};
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/finders/request/cookies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function requestModeCookiesFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'cookies'
};
}
if (_key.includes('cookie(')) {
Expand All @@ -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) === '{') {
Expand All @@ -50,15 +52,17 @@ export default function requestModeCookiesFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'cookies'
};
}
if (_key === 'cookies') {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'cookies'
};
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/finders/request/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function requestModeHeadersFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'headers'
};
}
if (_key.includes('header(')) {
Expand All @@ -34,7 +35,8 @@ export default function requestModeHeadersFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'headers'
};
}
if (_key.includes('getHeader(')) {
Expand All @@ -54,15 +56,17 @@ export default function requestModeHeadersFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'headers'
};
}
if (_key === 'headers') {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'headers'
};
}
}
Expand Down
21 changes: 1 addition & 20 deletions src/finders/request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,62 +31,44 @@ 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;
}

// Params matching
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 {
Expand All @@ -100,7 +82,6 @@ export default function caseRequestModeFinder(
index
);
if (res) {
res.mode = 'property';
return res;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/finders/request/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function requestModeParamsFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'params'
};
}
if (_key.includes('param(')) {
Expand All @@ -34,7 +35,8 @@ export default function requestModeParamsFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'params'
};
}
if (_key.includes('getParameter(')) {
Expand All @@ -54,15 +56,17 @@ export default function requestModeParamsFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'params'
};
}
if (_key === 'params') {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'params'
};
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/finders/request/property.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(')) {
Expand All @@ -46,15 +47,17 @@ export default function requestMethodFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'property'
};
}
if (_key.endsWith('req') || _key.endsWith('request')) {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'property'
};
}

Expand Down
12 changes: 8 additions & 4 deletions src/finders/request/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export default function requestModeQueryFinder(
link: extracted[1],
linked: false,
line_index: index,
key
key,
mode: 'query'
};
}
if (_key.includes('getQuery(')) {
Expand All @@ -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) === '{') {
Expand All @@ -50,15 +52,17 @@ export default function requestModeQueryFinder(
link,
linked: false,
line_index: index,
key
key,
mode: 'query'
};
}
if (_key === 'query') {
return {
link: extracted[1],
linked: false,
line_index: index,
key: '*'
key: '*',
mode: 'query'
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion types/interfaces.d.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f9487ab

Please sign in to comment.