@@ -39,7 +39,10 @@ export type BaseOptions<S extends RecursiveRecord = RecursiveRecord, R extends R
39
39
cacheStore ?: CacheStore < R > ;
40
40
} ;
41
41
42
- export type BaseTemplateOptions = {
42
+ export type BaseTemplateOptions <
43
+ T extends string | number | symbol = string | number | symbol ,
44
+ V extends boolean | symbol | string = boolean | symbol | string ,
45
+ > = {
43
46
/**
44
47
* Enables caching of requests (defaults to true).
45
48
* If a number is provided, it will be used as the retention time in milliseconds.
@@ -48,20 +51,25 @@ export type BaseTemplateOptions = {
48
51
/** Boolean record or required (truthy) or optional parameters (falsy) */
49
52
parameters ?: {
50
53
/** Boolean record or required (truthy) or optional path parameters (falsy) */
51
- path ?: Record < string , boolean | 'vip' > ;
54
+ path ?: Partial < Record < T , V > > ;
52
55
/** Boolean record or required (truthy) or optional query parameters (falsy) */
53
- query ?: Record < string , boolean | 'vip' > ;
56
+ query ?: Partial < Record < T , V > > ;
54
57
} ;
55
58
} ;
56
59
57
60
export type BaseInit = Omit < Partial < BaseRequest [ 'init' ] > , 'method' > ;
58
61
62
+ export type BaseBody <
63
+ T extends string | number | symbol = string | number | symbol ,
64
+ V extends boolean | symbol | string = boolean | symbol | string ,
65
+ > = Partial < Record < T , V > > ;
66
+
59
67
export type BaseTemplate < P extends RecursiveRecord = RecursiveRecord , O extends BaseTemplateOptions = BaseTemplateOptions > = {
60
68
method : HttpMethods ;
61
69
url : string ;
62
70
opts ?: O ;
63
71
/** Boolean record or required (truthy) or optional fields (falsy) */
64
- body ?: Record < string , boolean > ;
72
+ body ?: BaseBody < string | keyof P > ;
65
73
/** Partial fetch request init */
66
74
init ?: BaseInit ;
67
75
/** Validate the parameters before performing request */
@@ -101,7 +109,7 @@ export class ClientEndpoint<
101
109
method : HttpMethods ;
102
110
url : string ;
103
111
opts : Option ;
104
- body ?: Record < string , boolean > ;
112
+ body ?: BaseBody < string | keyof Parameter > ;
105
113
init ?: BaseInit ;
106
114
validate ?: ( param : Parameter ) => boolean ;
107
115
cached : Cache extends true ? Omit < this, 'cached' > & ClientEndpointCache < Parameter , Response > : never ;
@@ -381,7 +389,7 @@ export abstract class BaseClient<
381
389
* @protected
382
390
* @abstract
383
391
*/
384
- protected abstract _parseBody < T extends RecursiveRecord = RecursiveRecord > ( body : Record < string , string | boolean > , params : T ) : BodyInit ;
392
+ protected abstract _parseBody < T extends RecursiveRecord = RecursiveRecord > ( body : BaseBody < string | keyof T > , params : T ) : BodyInit ;
385
393
386
394
/**
387
395
* Parses the response from the API before returning from the call.
@@ -406,7 +414,7 @@ export abstract class BaseClient<
406
414
*
407
415
* @returns {BodyInit } The parsed request body.
408
416
*/
409
- export const parseBody = < T extends RecursiveRecord = RecursiveRecord > ( template : Record < string , string | boolean > = { } , params : T ) : BodyInit => {
417
+ export const parseBody = < T extends RecursiveRecord = RecursiveRecord > ( template : BaseBody < string | keyof T > = { } , params : T ) : BodyInit => {
410
418
const _body : Record < string , string > = { } ;
411
419
412
420
Object . entries ( params ) . forEach ( ( [ key , value ] ) => {
0 commit comments