Skip to content

Commit

Permalink
add QueryStringMatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Bessonov committed Apr 20, 2024
1 parent e9d74ec commit 8159bc3
Show file tree
Hide file tree
Showing 29 changed files with 988 additions and 8 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ What's next?
Some ideas:
- `RegExpUrlMatcher` and `EndpointMatcher` will probably get an additional parameter to describe the data instead of do it with type arguments and get only string. This parameter probably will looks like `{userId: numberValidator()}`.
- `ExactQueryMatcher` will probably get validators too. This will improve extensibility and powerfulness a lot. In addition, it will probably handle PHP style arrays such as `users[]=1&users[]=2`.
- Addition of some sort of `ajv`-based JSON Schema Matcher.

Trying out
----------
While this state is highly experimental, you can try it out with `pnpm add github:Bessonov/node-http-router#next`.

After that, you can update to the latest version with `pnpm update -r @bessonovs/node-http-router`.
2 changes: 1 addition & 1 deletion dist/Router.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Matched, type Matcher } from './matchers/index.js';
import { type MatchResult, type MatchResultAny } from './matchers/MatchResult.js';
import type { MatchResult, MatchResultAny } from './matchers/MatchResult.js';
interface HandlerParams<MR extends MatchResultAny, D> {
match: Matched<MR>;
data: D;
Expand Down
1 change: 0 additions & 1 deletion dist/Router.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/Router.js.map

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

1 change: 1 addition & 0 deletions dist/__tests__/validators.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
107 changes: 107 additions & 0 deletions dist/__tests__/validators.test.js

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

1 change: 1 addition & 0 deletions dist/__tests__/validators.test.js.map

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

1 change: 1 addition & 0 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './middlewares/index.js';
export { type Handler, type Route, type MatchedHandler, Router, } from './Router.js';
export { type ServerRequest, toServerRequest, } from './node/ServerRequest.js';
export { NodeHttpRouter, type NodeHttpRouterParams, } from './node/NodeHttpRouter.js';
export * from './validators.js';
1 change: 1 addition & 0 deletions dist/index.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/index.js.map

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

23 changes: 23 additions & 0 deletions dist/matchers/QueryStringMatcher.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Matcher } from './Matcher.js';
import type { MatchResult } from './MatchResult.js';
import type { Validator } from '../validators.js';
export interface QueryStringMatcherInput {
req: {
url: string;
};
}
type AnyValidator = Validator<string[], any>;
type QueryMatch = Record<string, AnyValidator>;
type QueryResult<T extends QueryMatch> = {
[P in keyof T]: T[P] extends Validator<string[], infer O> ? O : never;
};
export type QueryStringMatchResult<U extends QueryMatch> = MatchResult<{
query: QueryResult<U>;
}>;
declare class QueryStringMatcher<U extends QueryMatch, P extends QueryStringMatcherInput> implements Matcher<QueryStringMatchResult<U>, P> {
private readonly listConfig;
constructor(config: U);
match: ({ req }: P) => QueryStringMatchResult<U>;
}
export declare function queryString<U extends QueryMatch, P extends QueryStringMatcherInput>(config: U): QueryStringMatcher<U, P>;
export {};
34 changes: 34 additions & 0 deletions dist/matchers/QueryStringMatcher.js

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

1 change: 1 addition & 0 deletions dist/matchers/QueryStringMatcher.js.map

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

1 change: 1 addition & 0 deletions dist/matchers/__tests__/QueryStringMatcher.test.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Loading

0 comments on commit 8159bc3

Please sign in to comment.