11import { RequestError } from '../http/errors' ;
22import { ExtractPathParams , HttpMethod } from '../http/types' ;
33import { WithOptional } from '../types/utils' ;
4+ import { HttpMutationBuilder } from './HttpMutationBuilder' ;
5+ import { MutationBuilder } from './MutationBuilder' ;
46import { QueryBuilder } from './QueryBuilder' ;
57import { QueryBuilderConfig } from './QueryBuilderFrozen' ;
68import { HttpBaseHeaders , HttpBaseParams , HttpBaseSearch , HttpBuilderVars } from './types' ;
@@ -14,10 +16,9 @@ export class HttpQueryBuilder<
1416 TMeta = unknown ,
1517 TData = unknown ,
1618 TError = RequestError ,
19+ TTags extends Record < string , unknown > = Record < string , unknown > ,
1720 TKey extends [ HttpBuilderVars ] = [ HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > ] ,
18- > extends QueryBuilder < HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > , TData , TError , TKey > {
19- protected declare _vars : HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > ;
20-
21+ > extends QueryBuilder < HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > , TData , TError , TKey , TTags > {
2122 constructor (
2223 config ?: WithOptional < QueryBuilderConfig < HttpBuilderVars < TParam , TSearch , TBody , THeader , TMeta > , TData , TError , TKey > , 'queryFn' > ,
2324 ) {
@@ -27,33 +28,33 @@ export class HttpQueryBuilder<
2728 super ( { mergeVars, queryFn, queryKeyHashFn, ...config } ) ;
2829 }
2930
30- withBody < TBody$ > ( body ?: TBody$ ) : HttpQueryBuilder < TParam , TSearch , TBody$ , THeader , TMeta , TData , TError , TKey > {
31+ withBody < TBody$ > ( body ?: TBody$ ) : HttpQueryBuilder < TParam , TSearch , TBody$ , THeader , TMeta , TData , TError , TTags > {
3132 if ( ! body ) return this as any ;
3233 return this . withVars ( { body } ) as any ;
3334 }
3435
3536 withHeaders < THeaders$ extends HttpBaseHeaders > (
3637 headers ?: THeaders$ ,
37- ) : HttpQueryBuilder < TParam , TSearch , TBody , THeaders$ , TMeta , TData , TError , TKey > {
38+ ) : HttpQueryBuilder < TParam , TSearch , TBody , THeaders$ , TMeta , TData , TError , TTags > {
3839 if ( ! headers ) return this as any ;
3940 return this . withVars ( { headers } ) as any ;
4041 }
4142
4243 withParams < TParams$ extends HttpBaseParams > (
4344 params ?: TParams$ ,
44- ) : HttpQueryBuilder < TParams$ , TSearch , TBody , THeader , TMeta , TData , TError , TKey > {
45+ ) : HttpQueryBuilder < TParams$ , TSearch , TBody , THeader , TMeta , TData , TError , TTags > {
4546 if ( ! params ) return this as any ;
4647 return this . withVars ( { params } ) as any ;
4748 }
4849
4950 withSearch < TSearch$ extends HttpBaseSearch > (
5051 search ?: TSearch$ ,
51- ) : HttpQueryBuilder < TParam , TSearch$ , TBody , THeader , TMeta , TData , TError , TKey > {
52+ ) : HttpQueryBuilder < TParam , TSearch$ , TBody , THeader , TMeta , TData , TError , TTags > {
5253 if ( ! search ) return this as any ;
5354 return this . withVars ( { search } ) as any ;
5455 }
5556
56- withMeta < TMeta$ > ( meta ?: TMeta$ ) : HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta$ , TData , TError , TKey > {
57+ withMeta < TMeta$ > ( meta ?: TMeta$ ) : HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta$ , TData , TError , TTags > {
5758 if ( ! meta ) return this as any ;
5859 return this . withVars ( { meta } ) as any ;
5960 }
@@ -62,7 +63,7 @@ export class HttpQueryBuilder<
6263 path : TPath$ ,
6364 ) : ExtractPathParams < TPath$ > extends void
6465 ? this
65- : HttpQueryBuilder < ExtractPathParams < TPath$ > , TSearch , TBody , THeader , TMeta , TData , TError , TKey > {
66+ : HttpQueryBuilder < ExtractPathParams < TPath$ > , TSearch , TBody , THeader , TMeta , TData , TError , TTags > {
6667 return this . withVars ( { path } ) as any ;
6768 }
6869
@@ -74,6 +75,39 @@ export class HttpQueryBuilder<
7475 return this . withVars ( { method } ) as any ;
7576 }
7677
77- declare withData : < TData$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData$ , TError , TKey > ;
78- declare withError : < TError$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData , TError$ , TKey > ;
78+ declare withData : < TData$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData$ , TError , TTags , TKey > ;
79+ declare withError : < TError$ > ( ) => HttpQueryBuilder < TParam , TSearch , TBody , THeader , TMeta , TData , TError$ , TTags , TKey > ;
80+
81+ withTagTypes < TTag extends string , T = unknown > ( ) : HttpQueryBuilder <
82+ TParam ,
83+ TSearch ,
84+ TBody ,
85+ THeader ,
86+ TMeta ,
87+ TData ,
88+ TError ,
89+ TTags & Record < TTag , T > ,
90+ TKey
91+ > ;
92+ withTagTypes < TTags$ extends Record < string , unknown > > ( ) : HttpQueryBuilder <
93+ TParam ,
94+ TSearch ,
95+ TBody ,
96+ THeader ,
97+ TMeta ,
98+ TData ,
99+ TError ,
100+ TTags$ ,
101+ TKey
102+ > ;
103+ withTagTypes ( ) : this {
104+ return this as any ;
105+ }
106+
107+ protected MutationBuilderConstructor = HttpMutationBuilder as typeof MutationBuilder ;
108+
109+ asMutationBuilder ( ) : HttpMutationBuilder < TParam , TSearch , TBody , THeader , TMeta , TData , TError , TTags , TKey > {
110+ const { options, ...restConfig } = this . config ;
111+ return new this . MutationBuilderConstructor ( restConfig ) as any ;
112+ }
79113}
0 commit comments