Skip to content

Commit

Permalink
allow a string in endpoint and regExpUrl matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
Bessonov committed Apr 20, 2024
1 parent 70ee60d commit bab99c2
Show file tree
Hide file tree
Showing 17 changed files with 117 additions and 35 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Features
- `AndMatcher` and `OrMatcher` supports now up to five matchers instead of two.
- Every matcher can be instantiated with a shortcut function now. For example, `and`, `or`, `method`, `endpoint`, etc.
- `ExactQueryMatcher` is now deprecated and will be replaced with the new `queryString` matcher. It comes with a set of validators, which can also convert values and supports PHP style arrays such as `users[]=1&users[]=2`.
- `regExpUrl` and `endpoint` supports now `RegExp`, `string`, and array of them for the url matching.

What's next?
------------
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,8 @@ router.addRoute({
})
```

Both, `RegExpUrlMatcher` and `EndpointMatcher` can be used with a string for an exact match instead of a RegExp.

### Middlewares

**This whole section is highly experimental!**
Expand Down
8 changes: 3 additions & 5 deletions dist/matchers/EndpointMatcher.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { type Method } from './index.js';
import type { Matcher } from './Matcher.js';
import type { MatchResult } from './MatchResult.js';
import { type Matcher, type MatchResult, type Method } from './index.js';
import type { RegExpExecGroupArray } from './RegExpUrlMatcher.js';
export interface EndpointMatcherInput {
req: {
Expand All @@ -18,7 +16,7 @@ export type EndpointMatchResult<R extends object> = MatchResult<{
*/
export declare class EndpointMatcher<R extends object, P extends EndpointMatcherInput = EndpointMatcherInput> implements Matcher<EndpointMatchResult<R>, P> {
private readonly matcher;
constructor(methods: Method | Method[], url: RegExp);
constructor(methods: Method | Method[], urls: RegExp | string | (RegExp | string)[]);
match(params: EndpointMatcherInput): EndpointMatchResult<R>;
}
export declare function endpoint<R extends object, P extends EndpointMatcherInput = EndpointMatcherInput>(methods: Method | Method[], url: RegExp): EndpointMatcher<R, P>;
export declare function endpoint<R extends object, P extends EndpointMatcherInput = EndpointMatcherInput>(...args: ConstructorParameters<typeof EndpointMatcher<R, P>>): EndpointMatcher<R, P>;
10 changes: 5 additions & 5 deletions dist/matchers/EndpointMatcher.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/matchers/EndpointMatcher.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions dist/matchers/RegExpUrlMatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export type RegExpUrlMatchResult<R extends object> = MatchResult<{
}>;
export declare class RegExpUrlMatcher<R extends object, P extends RegExpUrlMatcherInput = RegExpUrlMatcherInput> implements Matcher<RegExpUrlMatchResult<R>, P> {
private readonly urls;
constructor(urls: RegExp[]);
readonly regExps: RegExp[];
constructor(urls: (RegExp | string)[]);
match({ req }: RegExpUrlMatcherInput): RegExpUrlMatchResult<R>;
}
export declare function regExpUrl<R extends object, P extends RegExpUrlMatcherInput = RegExpUrlMatcherInput>(urls: RegExp[]): RegExpUrlMatcher<R, P>;
export declare function regExpUrl<R extends object, P extends RegExpUrlMatcherInput = RegExpUrlMatcherInput>(urls: (RegExp | string)[]): RegExpUrlMatcher<R, P>;
13 changes: 12 additions & 1 deletion dist/matchers/RegExpUrlMatcher.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/matchers/RegExpUrlMatcher.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions dist/matchers/__tests__/EndpointMatcher.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/matchers/__tests__/EndpointMatcher.test.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions dist/matchers/__tests__/RegExpUrlMatcher.test.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bab99c2

Please sign in to comment.