1+ import { RequestError } from '../http/errors' ;
12import { ExtractPathParams , HttpMethod } from '../http/types' ;
23import { WithOptional } from '../types/utils' ;
3- import { HttpMutationBuilder } from './HttpMutationBuilder' ;
4- import { MutationBuilder } from './MutationBuilder' ;
54import { QueryBuilder , QueryBuilderConfig } from './QueryBuilder' ;
6- import { MiddlewareFn } from './createMiddlewareFunction' ;
7- import { PreprocessorFn } from './createPreprocessorFunction' ;
8- import {
9- HttpBaseHeaders ,
10- HttpBaseParams ,
11- HttpBaseSearch ,
12- HttpBuilderTypeTemplate ,
13- SetAllTypes ,
14- SetDataType ,
15- SetErrorType ,
16- } from './types' ;
17- import { AppendVarsType } from './types' ;
18- import { createHttpQueryFn , createHttpQueryHashFn , mergeHttpVars } from './utils' ;
5+ import { HttpBaseHeaders , HttpBaseParams , HttpBaseSearch , HttpBuilderVars } from './types' ;
6+ import { createHttpMergeVarsFn , createHttpQueryFn , createHttpQueryHashFn } from './utils' ;
197
20- export class HttpQueryBuilder < T extends HttpBuilderTypeTemplate = HttpBuilderTypeTemplate > extends QueryBuilder < T > {
21- constructor ( config ?: WithOptional < QueryBuilderConfig < T > , 'queryFn' > ) {
22- const mergeVars = config ?. mergeVars || mergeHttpVars ;
23- const queryFn = config ?. queryFn || createHttpQueryFn < T > ( mergeVars ) ;
8+ export class HttpQueryBuilder <
9+ TParam = unknown ,
10+ TSearch = unknown ,
11+ TBody = unknown ,
12+ THeader = unknown ,
13+ TMeta = unknown ,
14+ TData = unknown ,
15+ TError = RequestError ,
16+ TKey extends [ HttpBuilderVars ] = [ HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > ] ,
17+ > extends QueryBuilder < HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > , TData , TError , TKey > {
18+ protected declare _vars : HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > ;
19+
20+ constructor (
21+ config ?: WithOptional <
22+ QueryBuilderConfig < HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > , TData , TError , TKey > ,
23+ 'queryFn'
24+ > ,
25+ ) {
26+ const mergeVars = config ?. mergeVars || createHttpMergeVarsFn ( ) ;
27+ const queryFn = config ?. queryFn || createHttpQueryFn ( mergeVars ) ;
2428 const queryKeyHashFn = config ?. queryKeyHashFn || createHttpQueryHashFn ( ) ;
2529 super ( { mergeVars, queryFn, queryKeyHashFn, ...config } ) ;
2630 }
2731
28- withBody < TBody > ( body ?: TBody ) : HttpQueryBuilder < AppendVarsType < T , { body : TBody } > > {
32+ withBody < TBody$ > ( body ?: TBody$ ) : HttpQueryBuilder < TParam , TSearch , TBody$ , THeader , TMeta , TData , TError , TKey > {
2933 if ( ! body ) return this as any ;
3034 return this . withVars ( { body } ) as any ;
3135 }
3236
33- withHeaders < THeaders extends HttpBaseHeaders > (
34- headers ?: THeaders ,
35- ) : HttpQueryBuilder < AppendVarsType < T , { headers : THeaders } > > {
37+ withHeaders < THeaders$ extends HttpBaseHeaders > (
38+ headers ?: THeaders$ ,
39+ ) : HttpQueryBuilder < TParam , TSearch , TBody , THeaders$ , TMeta , TData , TError , TKey > {
3640 if ( ! headers ) return this as any ;
3741 return this . withVars ( { headers } ) as any ;
3842 }
3943
40- withParams < TParams extends HttpBaseParams > (
41- params ?: TParams ,
42- ) : HttpQueryBuilder < AppendVarsType < T , { params : TParams } > > {
44+ withParams < TParams$ extends HttpBaseParams > (
45+ params ?: TParams$ ,
46+ ) : HttpQueryBuilder < TParams$ , TSearch , TBody , THeader , TMeta , TData , TError , TKey > {
4347 if ( ! params ) return this as any ;
4448 return this . withVars ( { params } ) as any ;
4549 }
4650
47- withSearch < TSearch extends HttpBaseSearch > (
48- search ?: TSearch ,
49- ) : HttpQueryBuilder < AppendVarsType < T , { search : TSearch } > > {
51+ withSearch < TSearch$ extends HttpBaseSearch > (
52+ search ?: TSearch$ ,
53+ ) : HttpQueryBuilder < TParam , TSearch$ , TBody , THeader , TMeta , TData , TError , TKey > {
5054 if ( ! search ) return this as any ;
5155 return this . withVars ( { search } ) as any ;
5256 }
5357
54- withMeta < TMeta > ( meta ?: TMeta ) : HttpQueryBuilder < AppendVarsType < T , { meta : TMeta } > > {
58+ withMeta < TMeta$ > ( meta ?: TMeta$ ) : HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta$ , TData , TError , TKey > {
5559 if ( ! meta ) return this as any ;
5660 return this . withVars ( { meta } ) as any ;
5761 }
5862
59- withPath < const TPath extends string > (
60- path : TPath ,
61- ) : ExtractPathParams < TPath > extends void
63+ withPath < const TPath$ extends string > (
64+ path : TPath$ ,
65+ ) : ExtractPathParams < TPath$ > extends void
6266 ? this
63- : HttpQueryBuilder < AppendVarsType < T , { params : ExtractPathParams < TPath > } > > {
67+ : HttpQueryBuilder < ExtractPathParams < TPath$ > , TSearch , TBody , THeader , TMeta , TData , TError , TKey > {
6468 return this . withVars ( { path } ) as any ;
6569 }
6670
@@ -72,21 +76,6 @@ export class HttpQueryBuilder<T extends HttpBuilderTypeTemplate = HttpBuilderTyp
7276 return this . withVars ( { method } ) as any ;
7377 }
7478
75- declare withData : < TData > ( ) => HttpQueryBuilder < SetDataType < T , TData > > ;
76- declare withError : < TError > ( ) => HttpQueryBuilder < SetErrorType < T , TError > > ;
77- declare withVars : < TVars = T [ 'vars' ] , const TReset extends boolean = false > (
78- vars ?: TVars ,
79- reset ?: TReset ,
80- ) => HttpQueryBuilder < AppendVarsType < T , Partial < TVars > , TReset > > ;
81-
82- declare withPreprocessor : < TVars = T [ 'vars' ] > (
83- preprocessor : PreprocessorFn < TVars , T [ 'vars' ] > ,
84- ) => HttpQueryBuilder < AppendVarsType < T , TVars , true , true > > ;
85-
86- declare withMiddleware : < TVars = T [ 'vars' ] , TData = T [ 'data' ] , TError = T [ 'error' ] > (
87- middleware : MiddlewareFn < TVars , TData , TError , T > ,
88- ) => HttpQueryBuilder < SetAllTypes < T , TData , TError , TVars , true > > ;
89-
90- declare asMutationBuilder : ( ) => HttpMutationBuilder < T > ;
91- protected override MutationBuilderConstructor : typeof MutationBuilder = HttpMutationBuilder as typeof MutationBuilder ;
79+ declare withData : < TData$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData$ , TError , TKey > ;
80+ declare withError : < TError$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData , TError$ , TKey > ;
9281}
0 commit comments