From c5b7a8fb1f9c64027363bfa8dd99126a7a0ab836 Mon Sep 17 00:00:00 2001 From: Anton Bessonov Date: Tue, 14 May 2024 21:40:17 +0000 Subject: [PATCH] fix mapToNumVal typings otherwise the returned type is never --- dist/examples/node.js | 2 +- dist/matchers/EndpointMatcher.d.ts | 14 ++++++------ dist/matchers/EndpointMatcher.js.map | 2 +- dist/matchers/QueryStringMatcher.d.ts | 16 +++++++------- dist/matchers/QueryStringMatcher.js.map | 2 +- dist/matchers/RegExpPathnameMatcher.d.ts | 16 +++++++------- dist/matchers/RegExpPathnameMatcher.js.map | 2 +- dist/matchers/index.d.ts | 2 +- dist/matchers/index.js.map | 2 +- dist/validators.d.ts | 5 +++-- dist/validators.js.map | 2 +- src/examples/node.ts | 2 +- src/matchers/EndpointMatcher.ts | 22 +++++++++---------- src/matchers/QueryStringMatcher.ts | 25 ++++++++++++---------- src/matchers/RegExpPathnameMatcher.ts | 25 ++++++++++++---------- src/matchers/index.ts | 4 ++-- src/validators.ts | 8 ++++--- 17 files changed, 80 insertions(+), 71 deletions(-) diff --git a/dist/examples/node.js b/dist/examples/node.js index edbb97c..00bd35e 100644 --- a/dist/examples/node.js +++ b/dist/examples/node.js @@ -4,7 +4,7 @@ import { NodeHttpRouter, } from '../node/NodeHttpRouter.js'; import { chain, getNthVal, requiredVal, } from '../validators.js'; /* -Demo how to use router with native node native http server +Demo how to use router with node's native http server run with: diff --git a/dist/matchers/EndpointMatcher.d.ts b/dist/matchers/EndpointMatcher.d.ts index 0cfc929..43ba1c9 100644 --- a/dist/matchers/EndpointMatcher.d.ts +++ b/dist/matchers/EndpointMatcher.d.ts @@ -1,21 +1,21 @@ -import { type Matcher, type MatchResult, type Method, type QueryMatch, type QueryResult, type QueryStringMatcherInput } from './index.js'; -import type { RegExpMatch, RegExpResult } from './RegExpPathnameMatcher.js'; +import { type Matcher, type MatchResult, type Method, type QueryStringMatch, type QueryStringMatcherInput, type QueryStringResult } from './index.js'; +import type { RegExpPathnameMatch, RegExpPathnameResult } from './RegExpPathnameMatcher.js'; export interface EndpointMatcherInput { req: { url: string; method: string; }; } -export type EndpointMatchResult = MatchResult<{ +export type EndpointMatchResult = MatchResult<{ method: Method; - pathname: RegExpResult; - query: QueryResult; + pathname: RegExpPathnameResult; + query: QueryStringResult; }>; /** * higher order matcher which is combine matching of method * with regular expression */ -export declare class EndpointMatcher implements Matcher, P> { +export declare class EndpointMatcher implements Matcher, P> { private readonly matcher; constructor(methods: Method | Method[], urls: RegExp | string | (RegExp | string)[], params?: { url?: R; @@ -23,4 +23,4 @@ export declare class EndpointMatcher; } -export declare function endpoint(...args: ConstructorParameters>): EndpointMatcher; +export declare function endpoint(...args: ConstructorParameters>): EndpointMatcher; diff --git a/dist/matchers/EndpointMatcher.js.map b/dist/matchers/EndpointMatcher.js.map index c9cc748..7dc9963 100644 --- a/dist/matchers/EndpointMatcher.js.map +++ b/dist/matchers/EndpointMatcher.js.map @@ -1 +1 @@ -{"version":3,"file":"EndpointMatcher.js","sourceRoot":"","sources":["../../src/matchers/EndpointMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EAKH,MAAM,EAIN,WAAW,EAGX,cAAc,GAEd,MAAM,YAAY,CAAA;AAwBnB,8GAA8G;AAC9G,MAAM,aAAa,GAAG,wBAAwB,CAAA;AAC9C,SAAS,WAAW,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,eAAe;IAc3B,YACC,OAA0B,EAC1B,IAA2C,EAC3C,MAGC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACtD,GAAG,C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KAAK;SACd,CAAA;IACF,CAAC;CACD;AAED,MAAM,UAAU,QAAQ,CAMvB,GAAG,IAAgE;IAEnE,OAAO,IAAI,eAAe,CAAC,GAAG,IAAI,CAAC,CAAA;AACpC,CAAC"} \ No newline at end of file +{"version":3,"file":"EndpointMatcher.js","sourceRoot":"","sources":["../../src/matchers/EndpointMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EAKH,MAAM,EAEN,WAAW,EAKX,cAAc,GAEd,MAAM,YAAY,CAAA;AAwBnB,8GAA8G;AAC9G,MAAM,aAAa,GAAG,wBAAwB,CAAA;AAC9C,SAAS,WAAW,CAAC,MAAc;IAClC,OAAO,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,CAAC,CAAA;AAC7C,CAAC;AAED;;;GAGG;AACH,MAAM,OAAO,eAAe;IAc3B,YACC,OAA0B,EAC1B,IAA2C,EAC3C,MAGC;QAED,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,MAAM,UAAU,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACtD,GAAG,CAAC,GAAG,CAAC,EAAE;YACV,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC7B,OAAO,IAAI,MAAM,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;YAC3C,CAAC;YACD,OAAO,GAAG,CAAA;QACX,CAAC,CAAC,CAAA;QACH,mBAAmB;QACnB,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC;YAClB,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;YACpD,cAAc,CAAO,UAAU,EAAE,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,GAAG,CAAC;YAC7C,GAAG,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,KAAK,EAAC,CAAC,CAAC,CAAC,WAAW,CAAQ,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;SACnE,CAAC,CAAA;IACH,CAAC;IAED,KAAK,CAAC,MAA4B;QACjC,mBAAmB;QACnB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAEzC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;YACpB,MAAM,CAAC,YAAY,EAAE,SAAS,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAA;YAChE,OAAO;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,kBACL,MAAM,EAAE,YAAY,CAAC,MAAM,CAAC,MAAM,EAClC,QAAQ,EAAE,SAAS,CAAC,MAAM,CAAC,QAAQ,IAChC,WAAW,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CACzD;aAC4B,CAAA;QAC/B,CAAC;QAED,OAAO;YACN,OAAO,EAAE,KAAK;SACd,CAAA;IACF,CAAC;CACD;AAED,MAAM,UAAU,QAAQ,CAMvB,GAAG,IAAgE;IAEnE,OAAO,IAAI,eAAe,CAAC,GAAG,IAAI,CAAC,CAAA;AACpC,CAAC"} \ No newline at end of file diff --git a/dist/matchers/QueryStringMatcher.d.ts b/dist/matchers/QueryStringMatcher.d.ts index aedc792..cc47ae8 100644 --- a/dist/matchers/QueryStringMatcher.d.ts +++ b/dist/matchers/QueryStringMatcher.d.ts @@ -1,4 +1,4 @@ -import type { AnyValidator, Validator } from '../validators.js'; +import type { FirstValidator, ValidatorReturnType } from '../validators.js'; import type { Matcher } from './Matcher.js'; import type { MatchResult } from './MatchResult.js'; export interface QueryStringMatcherInput { @@ -6,17 +6,17 @@ export interface QueryStringMatcherInput { url: string; }; } -export type QueryMatch = Record; -export type QueryResult = { - [P in keyof T]: T[P] extends Validator ? O : never; +export type QueryStringMatch = Record>; +export type QueryStringResult = { + [P in keyof T]: ValidatorReturnType; }; -export type QueryStringMatchResult = MatchResult<{ - query: QueryResult; +export type QueryStringMatchResult = MatchResult<{ + query: QueryStringResult; }>; -declare class QueryStringMatcher implements Matcher, P> { +declare class QueryStringMatcher implements Matcher, P> { private readonly listConfig; constructor(config: U); match: ({ req }: P) => QueryStringMatchResult; } -export declare function queryString(config: U): QueryStringMatcher; +export declare function queryString(config: U): QueryStringMatcher; export {}; diff --git a/dist/matchers/QueryStringMatcher.js.map b/dist/matchers/QueryStringMatcher.js.map index 7d39eb3..d6e2946 100644 --- a/dist/matchers/QueryStringMatcher.js.map +++ b/dist/matchers/QueryStringMatcher.js.map @@ -1 +1 @@ -{"version":3,"file":"QueryStringMatcher.js","sourceRoot":"","sources":["../../src/matchers/QueryStringMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AA4BxB,MAAM,kBAAkB;IAMvB,YAAY,MAAS;QAIrB,UAAK,GAAG,CAAC,EAAE,GAAG,EAAK,EAA6B,EAAE;;YACjD,6CAA6C;YAC7C,MAAM,MAAM,GAAG,MAAA,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,mCAAI,EAAE,CAAA;YAC9C,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;YAE/C,MAAM,WAAW,GAAG,EAAoB,CAAA;YACxC,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBACzE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;gBAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC1B,OAAO;wBACN,OAAO,EAAE,KAAK;qBACd,CAAA;gBACF,CAAC;gBACD,mBAAmB;gBACnB,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;YAClC,CAAC;YAED,OAAO;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACP,KAAK,EAAE,WAAW;iBAClB;aACD,CAAA;QACF,CAAC,CAAA;QA3BA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CA2BD;AAED,MAAM,UAAU,WAAW,CAGzB,MAAS;IACV,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAA;AACtC,CAAC"} \ No newline at end of file +{"version":3,"file":"QueryStringMatcher.js","sourceRoot":"","sources":["../../src/matchers/QueryStringMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AA+BxB,MAAM,kBAAkB;IAMvB,YAAY,MAAS;QAIrB,UAAK,GAAG,CAAC,EAAE,GAAG,EAAK,EAA6B,EAAE;;YACjD,6CAA6C;YAC7C,MAAM,MAAM,GAAG,MAAA,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,MAAM,mCAAI,EAAE,CAAA;YAC9C,MAAM,WAAW,GAAG,IAAI,eAAe,CAAC,MAAM,CAAC,CAAA;YAE/C,MAAM,WAAW,GAAG,EAA0B,CAAA;YAC9C,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAG,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;gBACzE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;gBAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC1B,OAAO;wBACN,OAAO,EAAE,KAAK;qBACd,CAAA;gBACF,CAAC;gBACD,mBAAmB;gBACnB,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;YAClC,CAAC;YAED,OAAO;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACP,KAAK,EAAE,WAAW;iBAClB;aACD,CAAA;QACF,CAAC,CAAA;QA3BA,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACzC,CAAC;CA2BD;AAED,MAAM,UAAU,WAAW,CAGzB,MAAS;IACV,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,CAAA;AACtC,CAAC"} \ No newline at end of file diff --git a/dist/matchers/RegExpPathnameMatcher.d.ts b/dist/matchers/RegExpPathnameMatcher.d.ts index 63114af..0584339 100644 --- a/dist/matchers/RegExpPathnameMatcher.d.ts +++ b/dist/matchers/RegExpPathnameMatcher.d.ts @@ -1,4 +1,4 @@ -import type { AnyValidator, Validator } from '../index.js'; +import type { FirstValidator, ValidatorReturnType } from '../index.js'; import type { Matcher } from './Matcher.js'; import type { MatchResult } from './MatchResult.js'; export interface RegExpPathnameMatcherInput { @@ -6,21 +6,21 @@ export interface RegExpPathnameMatcherInput { url: string; }; } -export type RegExpMatch = Record; -export type RegExpResult = { +export type RegExpPathnameMatch = Record>; +export type RegExpPathnameResult = { url: string; params: { - [P in keyof T]: T[P] extends Validator ? O : never; + [P in keyof T]: ValidatorReturnType; }; }; -export type RegExpPathnameMatchResult = MatchResult<{ - pathname: RegExpResult; +export type RegExpPathnameMatchResult = MatchResult<{ + pathname: RegExpPathnameResult; }>; -declare class RegExpPathnameMatcher implements Matcher, P> { +declare class RegExpPathnameMatcher implements Matcher, P> { private readonly urls; private readonly listConfig; constructor(urls: RegExp[], config?: R); match({ req }: RegExpPathnameMatcherInput): RegExpPathnameMatchResult; } -export declare function regExpPathname(urls: RegExp[], config?: R): RegExpPathnameMatcher; +export declare function regExpPathname(urls: RegExp[], config?: R): RegExpPathnameMatcher; export {}; diff --git a/dist/matchers/RegExpPathnameMatcher.js.map b/dist/matchers/RegExpPathnameMatcher.js.map index 12949c0..8579461 100644 --- a/dist/matchers/RegExpPathnameMatcher.js.map +++ b/dist/matchers/RegExpPathnameMatcher.js.map @@ -1 +1 @@ -{"version":3,"file":"RegExpPathnameMatcher.js","sourceRoot":"","sources":["../../src/matchers/RegExpPathnameMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AA+BxB,MAAM,qBAAqB;IAM1B,YAA6B,IAAc,EAAE,MAAU;QAA1B,SAAI,GAAJ,IAAI,CAAU;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,aAAN,MAAM,cAAN,MAAM,GAAI,EAAE,CAAC,CAAA;IAC/C,CAAC;IAED,KAAK,CAAC,EAAE,GAAG,EAA8B;;QACxC,gDAAgD;QAChD,MAAM,QAAQ,GAAG,MAAA,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,QAAQ,mCAAI,GAAG,CAAA;QACnD,OAAO,EAAE,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACtC,MAAM,eAAe,GAA6B,EAAE,CAAA;YACpD,IAAI,CAAyB,CAAA;YAC7B,IAAI,UAA8B,CAAA;YAClC,IAAI,SAAS,GAAG,CAAC,CAAA;YACjB,0CAA0C;YAC1C,OAAO,CAAC,CAAC,GAAG,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,C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YACD,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO;oBACN,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE;wBACP,QAAQ,EAAE;4BACT,GAAG,EAAE,UAAU;yBACf;qBACD;iBAC+B,CAAA;YAClC,CAAC;YACD,MAAM,WAAW,GAAG,EAA+B,CAAA;YACnD,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBAC9C,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;gBACnC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;gBAC9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;oBAC1B,SAAS,OAAO,CAAA;gBACjB,CAAC;gBACD,mBAAmB;gBACnB,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAA;YAC5B,CAAC;YAED,OAAO;gBACN,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE;oBACP,QAAQ,EAAE;wBACT,GAAG,EAAE,UAAU;wBACf,MAAM,EAAE,WAAW;qBACnB;iBACD;aACD,CAAA;QACF,CAAC;QAED,OAAO;YACN,OAAO,EAAE,KAAK;SACd,CAAA;IACF,CAAC;CACD;AAED,MAAM,UAAU,cAAc,CAG5B,IAAc,EAAE,MAAU;IAC3B,OAAO,IAAI,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC/C,CAAC"} \ No newline at end of file +{"version":3,"file":"RegExpPathnameMatcher.js","sourceRoot":"","sources":["../../src/matchers/RegExpPathnameMatcher.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,QAAQ,CAAA;AAkCxB,MAAM,qBAAqB;IAM1B,YAA6B,IAAc,EAAE,MAAU;QAA1B,SAAI,GAAJ,IAAI,CAAU;QAC1C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,C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,MAAM,EAAE;oBACP,QAAQ,EAAE;wBACT,GAAG,EAAE,UAAU;wBACf,MAAM,EAAE,WAAW;qBACnB;iBACD;aACD,CAAA;QACF,CAAC;QAED,OAAO;YACN,OAAO,EAAE,KAAK;SACd,CAAA;IACF,CAAC;CACD;AAED,MAAM,UAAU,cAAc,CAG5B,IAAc,EAAE,MAAU;IAC3B,OAAO,IAAI,qBAAqB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;AAC/C,CAAC"} \ No newline at end of file diff --git a/dist/matchers/index.d.ts b/dist/matchers/index.d.ts index 0084b40..88a6ce4 100644 --- a/dist/matchers/index.d.ts +++ b/dist/matchers/index.d.ts @@ -7,6 +7,6 @@ export { type ExtractMatchResult, type Matcher, } from './Matcher.js'; export { isMatched, type Matched, type MatchedResult, type MatchResult, type MatchResultAny, type UnmatchedResult, } from './MatchResult.js'; export { type Method, method, MethodMatcher, type MethodMatcherInput, type MethodMatchResult, } from './MethodMatcher.js'; export { or, OrMatcher, type OrMatcherResult, } from './OrMatcher.js'; -export { type QueryMatch, type QueryResult, queryString, type QueryStringMatcherInput, type QueryStringMatchResult, } from './QueryStringMatcher.js'; +export { queryString, type QueryStringMatch, type QueryStringMatcherInput, type QueryStringMatchResult, type QueryStringResult, } from './QueryStringMatcher.js'; export { regExpPathname, type RegExpPathnameMatcherInput, type RegExpPathnameMatchResult, } from './RegExpPathnameMatcher.js'; export { RegExpUrlMatcher, type RegExpUrlMatcherInput, type RegExpUrlMatchResult, } from './RegExpUrlMatcher.js'; diff --git a/dist/matchers/index.js.map b/dist/matchers/index.js.map index f9e6fbc..5611cea 100644 --- a/dist/matchers/index.js.map +++ b/dist/matchers/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EACH,UAAU,GAEV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,IAAI,EACJ,cAAc,GACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACN,QAAQ,EACR,eAAe,GAEf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACN,UAAU,EACV,iBAAiB,GACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACN,gBAAgB,EAChB,uBAAuB,GAGvB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAGN,MAAM,cAAc,CAAA;AACrB,OAAO,EACN,SAAS,GAMT,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAEN,MAAM,EACN,aAAa,GAGb,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACN,EAAE,EACF,SAAS,GAET,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAGN,WAAW,GAGX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,cAAc,GAGd,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACN,gBAAgB,GAGhB,MAAM,uBAAuB,CAAA"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/matchers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,GAAG,EACH,UAAU,GAEV,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,IAAI,EACJ,cAAc,GACd,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACN,QAAQ,EACR,eAAe,GAEf,MAAM,sBAAsB,CAAA;AAC7B,OAAO,EACN,UAAU,EACV,iBAAiB,GACjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACN,gBAAgB,EAChB,uBAAuB,GAGvB,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAGN,MAAM,cAAc,CAAA;AACrB,OAAO,EACN,SAAS,GAMT,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAEN,MAAM,EACN,aAAa,GAGb,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EACN,EAAE,EACF,SAAS,GAET,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACN,WAAW,GAKX,MAAM,yBAAyB,CAAA;AAChC,OAAO,EACN,cAAc,GAGd,MAAM,4BAA4B,CAAA;AACnC,OAAO,EACN,gBAAgB,GAGhB,MAAM,uBAAuB,CAAA"} \ No newline at end of file diff --git a/dist/validators.d.ts b/dist/validators.d.ts index d517c2c..d3166bd 100644 --- a/dist/validators.d.ts +++ b/dist/validators.d.ts @@ -1,5 +1,6 @@ type Any = any; -export type AnyValidator = Validator; +export type FirstValidator = Validator; +export type ValidatorReturnType = V extends Validator ? O : never; export type Getter = (() => O) | undefined; export type Undefined = undefined | null | void; export interface Validator { @@ -24,7 +25,7 @@ export declare function getNthVal(num?: number): Validator(): Validator>; +export declare function mapToNumVal(): NoInfer>; /** * Ensures that a single value can be converted to a number. */ diff --git a/dist/validators.js.map b/dist/validators.js.map index f98f4d6..5bd5eb4 100644 --- a/dist/validators.js.map +++ b/dist/validators.js.map @@ -1 +1 @@ -{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAaA,SAAS,WAAW,CAAC,KAAa;IACjC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC;AAED;;;GAGG;AACH,uEAAuE;AACvE,MAAM,UAAU,OAAO;IACtB,OAAO,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAc,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW;IAC1B,OAAO,CAAC,KAAoB,EAA0B,EAAE;QACvD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,OAAO,GAAG,EAAE,CAAC,KAAK,CAAA;IACnB,CAAC,CAAA;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAI,MAA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,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YAClE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAA;QACnB,CAAC;QACD,OAAO,SAAS,CAAA;IACjB,CAAC,CAAA;AACF,CAAC;AA8BD,MAAM,UAAU,KAAK,CAAC,GAAG,UAAiC;IACzD,OAAO,KAAK,CAAC,EAAE;QACd,IAAI,kBAAkB,GAAG,KAAK,CAAA;QAC9B,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;YAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,OAAO,SAAS,CAAA;YACjB,CAAC;YACD,kBAAkB,GAAG,MAAM,EAAE,CAAA;QAC9B,CAAC;QACD,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAA;IAChC,CAAC,CAAA;AACF,CAAC"} \ No newline at end of file +{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAeA,SAAS,WAAW,CAAC,KAAa;IACjC,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACrB,CAAC;IACD,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;AACrB,CAAC;AAED;;;GAGG;AACH,uEAAuE;AACvE,MAAM,UAAU,OAAO;IACtB,OAAO,CAAC,KAAe,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,KAAK,CAAc,CAAA;AACvD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,WAAW;IAC1B,OAAO,CAAC,KAAoB,EAA0B,EAAE;QACvD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAA;QACjB,CAAC;QACD,OAA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AC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAC1B,GAAW;IAEX,OAAO,CAAC,KAAsB,EAAe,EAAE;QAC9C,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;YAClE,OAAO,GAAG,EAAE,CAAC,KAAK,CAAA;QACnB,CAAC;QACD,OAAO,SAAS,CAAA;IACjB,CAAC,CAAA;AACF,CAAC;AA8BD,MAAM,UAAU,KAAK,CAAC,GAAG,UAAiC;IACzD,OAAO,KAAK,CAAC,EAAE;QACd,IAAI,kBAAkB,GAAG,KAAK,CAAA;QAC9B,KAAK,MAAM,OAAO,IAAI,UAAU,EAAE,CAAC;YAClC,MAAM,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAA;YAC1C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBAC1B,OAAO,SAAS,CAAA;YACjB,CAAC;YACD,kBAAkB,GAAG,MAAM,EAAE,CAAA;QAC9B,CAAC;QACD,OAAO,GAAG,EAAE,CAAC,kBAAkB,CAAA;IAChC,CAAC,CAAA;AACF,CAAC"} \ No newline at end of file diff --git a/src/examples/node.ts b/src/examples/node.ts index 984a7f1..3c69cf3 100644 --- a/src/examples/node.ts +++ b/src/examples/node.ts @@ -15,7 +15,7 @@ import { /* -Demo how to use router with native node native http server +Demo how to use router with node's native http server run with: diff --git a/src/matchers/EndpointMatcher.ts b/src/matchers/EndpointMatcher.ts index 8e7ec59..d335df1 100644 --- a/src/matchers/EndpointMatcher.ts +++ b/src/matchers/EndpointMatcher.ts @@ -6,17 +6,17 @@ import { type Method, method, type MethodMatchResult, - type QueryMatch, - type QueryResult, queryString, + type QueryStringMatch, type QueryStringMatcherInput, type QueryStringMatchResult, + type QueryStringResult, regExpPathname, type RegExpPathnameMatchResult, } from './index.js' import type { - RegExpMatch, - RegExpResult, + RegExpPathnameMatch, + RegExpPathnameResult, } from './RegExpPathnameMatcher.js' // waiting for @@ -31,10 +31,10 @@ export interface EndpointMatcherInput { } } -export type EndpointMatchResult = MatchResult<{ +export type EndpointMatchResult = MatchResult<{ method: Method - pathname: RegExpResult - query: QueryResult + pathname: RegExpPathnameResult + query: QueryStringResult }> // https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript/3561711#3561711 @@ -48,9 +48,9 @@ function escapeRegex(string: string) { * with regular expression */ export class EndpointMatcher< - R extends RegExpMatch, + R extends RegExpPathnameMatch, P extends EndpointMatcherInput = EndpointMatcherInput, - U extends QueryMatch = QueryMatch, + U extends QueryStringMatch = QueryStringMatch, QP extends QueryStringMatcherInput = QueryStringMatcherInput, > implements Matcher, P> { private readonly matcher: AndMatcher< @@ -108,9 +108,9 @@ export class EndpointMatcher< } export function endpoint< - R extends RegExpMatch, + R extends RegExpPathnameMatch, P extends EndpointMatcherInput = EndpointMatcherInput, - U extends QueryMatch = QueryMatch, + U extends QueryStringMatch = QueryStringMatch, QP extends QueryStringMatcherInput = QueryStringMatcherInput, >( ...args: ConstructorParameters> diff --git a/src/matchers/QueryStringMatcher.ts b/src/matchers/QueryStringMatcher.ts index 39f151e..66b6900 100644 --- a/src/matchers/QueryStringMatcher.ts +++ b/src/matchers/QueryStringMatcher.ts @@ -1,7 +1,10 @@ import Url from 'urlite' import type { - AnyValidator, - Validator, + ObjectToArray, +} from '../TypeUtils.js' +import type { + FirstValidator, + ValidatorReturnType, } from '../validators.js' import type { Matcher, @@ -16,21 +19,21 @@ export interface QueryStringMatcherInput { } } -export type QueryMatch = Record +export type QueryStringMatch = Record> -export type QueryResult = { - [P in keyof T]: T[P] extends Validator ? O : never +export type QueryStringResult = { + [P in keyof T]: ValidatorReturnType } -export type QueryStringMatchResult = MatchResult<{ - query: QueryResult +export type QueryStringMatchResult = MatchResult<{ + query: QueryStringResult }> class QueryStringMatcher< - U extends QueryMatch, + U extends QueryStringMatch, P extends QueryStringMatcherInput, > implements Matcher, P> { - private readonly listConfig: [string, AnyValidator][] + private readonly listConfig: ObjectToArray constructor(config: U) { this.listConfig = Object.entries(config) @@ -41,7 +44,7 @@ class QueryStringMatcher< const search = Url.parse(req.url).search ?? '' const queryParams = new URLSearchParams(search) - const queryResult = {} as QueryResult + const queryResult = {} as QueryStringResult for (const [key, matcher] of this.listConfig) { const params = queryParams.has(key) ? queryParams.getAll(key) : undefined const getter = matcher(params) @@ -64,7 +67,7 @@ class QueryStringMatcher< } export function queryString< - U extends QueryMatch, + U extends QueryStringMatch, P extends QueryStringMatcherInput, >(config: U): QueryStringMatcher { return new QueryStringMatcher(config) diff --git a/src/matchers/RegExpPathnameMatcher.ts b/src/matchers/RegExpPathnameMatcher.ts index 2bae0ef..7a16a6f 100644 --- a/src/matchers/RegExpPathnameMatcher.ts +++ b/src/matchers/RegExpPathnameMatcher.ts @@ -1,8 +1,11 @@ import Url from 'urlite' import type { - AnyValidator, - Validator, + FirstValidator, + ValidatorReturnType, } from '../index.js' +import type { + ObjectToArray, +} from '../TypeUtils.js' import type { Matcher, } from './Matcher.js' @@ -16,24 +19,24 @@ export interface RegExpPathnameMatcherInput { } } -export type RegExpMatch = Record +export type RegExpPathnameMatch = Record> -export type RegExpResult = { +export type RegExpPathnameResult = { url: string params: { - [P in keyof T]: T[P] extends Validator ? O : never + [P in keyof T]: ValidatorReturnType } } -export type RegExpPathnameMatchResult = MatchResult<{ - pathname: RegExpResult +export type RegExpPathnameMatchResult = MatchResult<{ + pathname: RegExpPathnameResult }> class RegExpPathnameMatcher< - R extends RegExpMatch, + R extends RegExpPathnameMatch, P extends RegExpPathnameMatcherInput = RegExpPathnameMatcherInput, > implements Matcher, P> { - private readonly listConfig: [string, AnyValidator][] + private readonly listConfig: ObjectToArray constructor(private readonly urls: RegExp[], config?: R) { this.match = this.match.bind(this) @@ -86,7 +89,7 @@ class RegExpPathnameMatcher< }, } as RegExpPathnameMatchResult } - const matchResult = {} as RegExpResult['params'] + const matchResult = {} as RegExpPathnameResult['params'] for (const [key, matcher] of this.listConfig) { const params = extractedValues[key] const getter = matcher(params) @@ -115,7 +118,7 @@ class RegExpPathnameMatcher< } export function regExpPathname< - R extends RegExpMatch, + R extends RegExpPathnameMatch, P extends RegExpPathnameMatcherInput = RegExpPathnameMatcherInput, >(urls: RegExp[], config?: R): RegExpPathnameMatcher { return new RegExpPathnameMatcher(urls, config) diff --git a/src/matchers/index.ts b/src/matchers/index.ts index 3dd987c..0d08eac 100644 --- a/src/matchers/index.ts +++ b/src/matchers/index.ts @@ -47,11 +47,11 @@ export { type OrMatcherResult, } from './OrMatcher.js' export { - type QueryMatch, - type QueryResult, queryString, + type QueryStringMatch, type QueryStringMatcherInput, type QueryStringMatchResult, + type QueryStringResult, } from './QueryStringMatcher.js' export { regExpPathname, diff --git a/src/validators.ts b/src/validators.ts index 18df55f..1315a1c 100644 --- a/src/validators.ts +++ b/src/validators.ts @@ -1,7 +1,9 @@ -// eslint-disable-next-line @typescript-eslint/no-explicit-any +// eslint-disable-next-line @typescript-eslint/no-explicit-any type Any = any -export type AnyValidator = Validator +export type FirstValidator = Validator + +export type ValidatorReturnType = V extends Validator ? O : never export type Getter = (() => O) | undefined @@ -69,7 +71,7 @@ export function getNthVal(num: number = 0): Validator(): Validator> { +>(): NoInfer> { return (values: string[] | Undefined): Getter => { if (values === undefined || values === null) { return (() => undefined) as Getter