@data-client/rest 0.7.4 → 0.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,468 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/ban-types */
2
- import type {
3
- EndpointExtraOptions,
4
- EndpointInstanceInterface,
5
- Schema,
6
- FetchFunction,
7
- ResolveType,
8
- } from '@data-client/endpoint';
9
-
10
- import type { ExtractCollection } from './extractCollection.js';
11
- import {
12
- OptionsToBodyArgument,
13
- OptionsToFunction,
14
- } from './OptionsToFunction.js';
15
- import { PathArgs } from './pathTypes.js';
16
- import { EndpointUpdateFunction } from './RestEndpointTypeHelp.js';
17
-
18
- export interface RestInstanceBase<
19
- F extends FetchFunction = FetchFunction,
20
- S extends Schema | undefined = any,
21
- M extends true | undefined = true | undefined,
22
- O extends {
23
- path: string;
24
- body?: any;
25
- searchParams?: any;
26
- method?: string;
27
- } = { path: string },
28
- > extends EndpointInstanceInterface<F, S, M> {
29
- /** @see https://resthooks.io/rest/api/RestEndpoint#body */
30
- readonly body?: 'body' extends keyof O ? O['body'] : any;
31
- /** @see https://resthooks.io/rest/api/RestEndpoint#searchParams */
32
- readonly searchParams?: 'searchParams' extends keyof O
33
- ? O['searchParams']
34
- : // unknown is identity with '&' type operator
35
- unknown;
36
-
37
- /** Pattern to construct url based on Url Parameters
38
- * @see https://resthooks.io/rest/api/RestEndpoint#path
39
- */
40
- readonly path: O['path'];
41
- /** Prepended to all urls
42
- * @see https://resthooks.io/rest/api/RestEndpoint#urlPrefix
43
- */
44
- readonly urlPrefix: string;
45
- readonly requestInit: RequestInit;
46
- /** @see https://resthooks.io/rest/api/RestEndpoint#method */
47
- readonly method: (O & { method: string })['method'];
48
- readonly signal: AbortSignal | undefined;
49
- readonly paginationField?: string;
50
-
51
- /* fetch lifecycles */
52
- /* before-fetch */
53
- url(...args: Parameters<F>): string;
54
- /** @see https://resthooks.io/rest/api/RestEndpoint#getRequestInit */
55
- getRequestInit(
56
- this: any,
57
- body?: RequestInit['body'] | Record<string, unknown>,
58
- ): Promise<RequestInit> | RequestInit;
59
- /** @see https://resthooks.io/rest/api/RestEndpoint#getHeaders */
60
- getHeaders(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
61
- /* after-fetch */
62
- /** @see https://resthooks.io/rest/api/RestEndpoint#fetchResponse */
63
- fetchResponse(input: RequestInfo, init: RequestInit): Promise<Response>;
64
- /** @see https://resthooks.io/rest/api/RestEndpoint#parseResponse */
65
- parseResponse(response: Response): Promise<any>;
66
- /** @see https://resthooks.io/rest/api/RestEndpoint#process */
67
- process(value: any, ...args: Parameters<F>): ResolveType<F>;
68
-
69
- /* utilities */
70
- /** @see https://resthooks.io/rest/api/RestEndpoint#testKey */
71
- testKey(key: string): boolean;
72
-
73
- /* extenders */
74
- // TODO: figure out better way than wrapping whole options in Readonly<> + making O extend from {}
75
- // this is just a hack to handle when no members of PartialRestGenerics are present
76
- // Note: Using overloading (like paginated did) struggles because typescript does not have a clear way of distinguishing one
77
- // should be used from the other (due to same problem with every member being partial)
78
- /** Creates a child endpoint that inherits from this while overriding provided `options`.
79
- * @see https://dataclient.io/rest/api/RestEndpoint#extend
80
- */
81
- extend<
82
- E extends RestInstanceBase,
83
- ExtendOptions extends PartialRestGenerics | {},
84
- >(
85
- this: E,
86
- options: Readonly<
87
- RestEndpointExtendOptions<ExtendOptions, E, F> & ExtendOptions
88
- >,
89
- ): RestExtendedEndpoint<ExtendOptions, E>;
90
- }
91
-
92
- export interface RestInstance<
93
- F extends FetchFunction = FetchFunction,
94
- S extends Schema | undefined = any,
95
- M extends true | undefined = true | undefined,
96
- O extends {
97
- path: string;
98
- body?: any;
99
- searchParams?: any;
100
- method?: string;
101
- paginationField?: string;
102
- } = { path: string },
103
- > extends RestInstanceBase<F, S, M, O> {
104
- /** Creates an Endpoint to append the next page extending a list for pagination
105
- * @see https://dataclient.io/rest/api/RestEndpoint#paginated
106
- */
107
- paginated<
108
- E extends RestInstanceBase<FetchFunction, any, undefined>,
109
- A extends any[],
110
- >(
111
- this: E,
112
- removeCursor: (...args: A) => readonly [...Parameters<E>],
113
- ): PaginationEndpoint<E, A>;
114
- paginated<
115
- E extends RestInstanceBase<FetchFunction, any, undefined>,
116
- C extends string,
117
- >(
118
- this: E,
119
- cursorField: C,
120
- ): PaginationFieldEndpoint<E, C>;
121
- /** Endpoint to append the next page extending a list for pagination
122
- * @see https://dataclient.io/rest/api/RestEndpoint#getPage
123
- */
124
- getPage: 'paginationField' extends keyof O
125
- ? O['paginationField'] extends string
126
- ? PaginationFieldEndpoint<
127
- F & { schema: S; sideEffect: M } & O,
128
- O['paginationField']
129
- >
130
- : undefined
131
- : undefined;
132
- /** Endpoint that pushes (place at end) a newly created entity to this Collection
133
- * @see https://dataclient.io/rest/api/RestEndpoint#push
134
- */
135
- push: AddEndpoint<
136
- F,
137
- ExtractCollection<S>['push'],
138
- Exclude<O, 'body' | 'method'> & {
139
- body:
140
- | OptionsToAdderBodyArgument<O>
141
- | OptionsToAdderBodyArgument<O>[]
142
- | FormData;
143
- }
144
- >;
145
- /** Endpoint that unshifts (place at start) a newly created entity to this Collection
146
- * @see https://dataclient.io/rest/api/RestEndpoint#unshift
147
- */
148
- unshift: AddEndpoint<
149
- F,
150
- ExtractCollection<S>['unshift'],
151
- Exclude<O, 'body' | 'method'> & {
152
- body:
153
- | OptionsToAdderBodyArgument<O>
154
- | OptionsToAdderBodyArgument<O>[]
155
- | FormData;
156
- }
157
- >;
158
- /** Endpoint that assigns newly created entities to their respective keys in this Collection
159
- * @see https://dataclient.io/rest/api/RestEndpoint#assign
160
- */
161
- assign: AddEndpoint<
162
- F,
163
- ExtractCollection<S>,
164
- Exclude<O, 'body' | 'method'> & {
165
- body: Record<string, OptionsToAdderBodyArgument<O>> | FormData;
166
- }
167
- >;
168
- }
169
-
170
- export type RestEndpointExtendOptions<
171
- O extends PartialRestGenerics,
172
- E extends { body?: any; path?: string; schema?: Schema; method?: string },
173
- F extends FetchFunction,
174
- > = RestEndpointOptions<
175
- OptionsToFunction<O, E, F>,
176
- 'schema' extends keyof O
177
- ? Extract<O['schema'], Schema | undefined>
178
- : E['schema']
179
- > &
180
- Partial<
181
- Omit<
182
- E,
183
- KeyofRestEndpoint | keyof PartialRestGenerics | keyof RestEndpointOptions
184
- >
185
- >;
186
-
187
- type OptionsToRestEndpoint<
188
- O extends PartialRestGenerics,
189
- E extends RestInstanceBase & { body?: any; paginationField?: string },
190
- F extends FetchFunction,
191
- > = 'path' extends keyof O
192
- ? RestType<
193
- 'searchParams' extends keyof O
194
- ? O['searchParams'] extends undefined
195
- ? PathArgs<Exclude<O['path'], undefined>>
196
- : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
197
- : PathArgs<Exclude<O['path'], undefined>>,
198
- OptionsToBodyArgument<
199
- 'body' extends keyof O ? O : E,
200
- 'method' extends keyof O ? O['method'] : E['method']
201
- >,
202
- 'schema' extends keyof O ? O['schema'] : E['schema'],
203
- 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
204
- O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
205
- {
206
- path: Exclude<O['path'], undefined>;
207
- body: 'body' extends keyof O ? O['body'] : E['body'];
208
- searchParams: 'searchParams' extends keyof O
209
- ? O['searchParams']
210
- : E['searchParams'];
211
- method: 'method' extends keyof O ? O['method'] : E['method'];
212
- paginationField: 'paginationField' extends keyof O
213
- ? O['paginationField']
214
- : E['paginationField'];
215
- }
216
- >
217
- : 'body' extends keyof O
218
- ? RestType<
219
- 'searchParams' extends keyof O
220
- ? O['searchParams'] extends undefined
221
- ? PathArgs<Exclude<O['path'], undefined>>
222
- : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
223
- : PathArgs<Exclude<E['path'], undefined>>,
224
- OptionsToBodyArgument<
225
- O,
226
- 'method' extends keyof O ? O['method'] : E['method']
227
- >,
228
- 'schema' extends keyof O ? O['schema'] : E['schema'],
229
- 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
230
- O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
231
- {
232
- path: E['path'];
233
- body: O['body'];
234
- searchParams: 'searchParams' extends keyof O
235
- ? O['searchParams']
236
- : E['searchParams'];
237
- method: 'method' extends keyof O ? O['method'] : E['method'];
238
- paginationField: 'paginationField' extends keyof O
239
- ? O['paginationField']
240
- : Extract<E['paginationField'], string>;
241
- }
242
- >
243
- : 'searchParams' extends keyof O
244
- ? RestType<
245
- O['searchParams'] extends undefined
246
- ? PathArgs<Exclude<O['path'], undefined>>
247
- : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
248
- OptionsToBodyArgument<
249
- E,
250
- 'method' extends keyof O ? O['method'] : E['method']
251
- >,
252
- 'schema' extends keyof O ? O['schema'] : E['schema'],
253
- 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
254
- O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
255
- {
256
- path: E['path'];
257
- body: E['body'];
258
- searchParams: O['searchParams'];
259
- method: 'method' extends keyof O ? O['method'] : E['method'];
260
- paginationField: 'paginationField' extends keyof O
261
- ? O['paginationField']
262
- : Extract<E['paginationField'], string>;
263
- }
264
- >
265
- : RestInstance<
266
- F,
267
- 'schema' extends keyof O ? O['schema'] : E['schema'],
268
- 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
269
- {
270
- path: 'path' extends keyof O
271
- ? Exclude<O['path'], undefined>
272
- : E['path'];
273
- body: 'body' extends keyof O ? O['body'] : E['body'];
274
- searchParams: 'searchParams' extends keyof O
275
- ? O['searchParams']
276
- : E['searchParams'];
277
- method: 'method' extends keyof O ? O['method'] : E['method'];
278
- paginationField: 'paginationField' extends keyof O
279
- ? O['paginationField']
280
- : E['paginationField'];
281
- }
282
- >;
283
-
284
- export type RestExtendedEndpoint<
285
- O extends PartialRestGenerics,
286
- E extends RestInstanceBase & { getPage?: unknown },
287
- > = OptionsToRestEndpoint<
288
- O,
289
- E &
290
- (E extends { getPage: { paginationField: string } }
291
- ? { paginationField: E['getPage']['paginationField'] }
292
- : unknown),
293
- RestInstance<
294
- (
295
- ...args: Parameters<E>
296
- ) => O['process'] extends {}
297
- ? Promise<ReturnType<O['process']>>
298
- : ReturnType<E>,
299
- 'schema' extends keyof O ? O['schema'] : E['schema'],
300
- 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']
301
- >
302
- > &
303
- Omit<O, KeyofRestEndpoint> &
304
- Omit<E, KeyofRestEndpoint | keyof O>;
305
-
306
- export interface PartialRestGenerics {
307
- /** @see https://resthooks.io/rest/api/RestEndpoint#path */
308
- readonly path?: string;
309
- /** @see https://resthooks.io/rest/api/RestEndpoint#schema */
310
- readonly schema?: Schema | undefined;
311
- /** @see https://resthooks.io/rest/api/RestEndpoint#method */
312
- readonly method?: string;
313
- /** Only used for types */
314
- /** @see https://dataclient.io/rest/api/RestEndpoint#body */
315
- body?: any;
316
- /** Only used for types */
317
- /** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
318
- searchParams?: any;
319
- /** @see https://dataclient.io/rest/api/RestEndpoint#paginationfield */
320
- readonly paginationField?: string;
321
- /** @see https://resthooks.io/rest/api/RestEndpoint#process */
322
- process?(value: any, ...args: any): any;
323
- }
324
- export interface RestGenerics extends PartialRestGenerics {
325
- readonly path: string;
326
- }
327
-
328
- export type PaginationEndpoint<
329
- E extends FetchFunction & RestGenerics & { sideEffect?: true | undefined },
330
- A extends any[],
331
- > = RestInstanceBase<
332
- ParamFetchNoBody<A[0], ResolveType<E>>,
333
- E['schema'],
334
- E['sideEffect'],
335
- Pick<E, 'path' | 'searchParams' | 'body'> & {
336
- searchParams: Omit<A[0], keyof PathArgs<E['path']>>;
337
- }
338
- >;
339
- export type PaginationFieldEndpoint<
340
- E extends FetchFunction & RestGenerics & { sideEffect?: true | undefined },
341
- C extends string,
342
- > = RestInstanceBase<
343
- ParamFetchNoBody<
344
- { [K in C]: string | number | boolean } & E['searchParams'] &
345
- PathArgs<Exclude<E['path'], undefined>>,
346
- ResolveType<E>
347
- >,
348
- E['schema'],
349
- E['sideEffect'],
350
- Pick<E, 'path' | 'searchParams' | 'body'> & {
351
- searchParams: { [K in C]: string | number | boolean } & E['searchParams'];
352
- }
353
- > & { paginationField: C };
354
- export type AddEndpoint<
355
- F extends FetchFunction = FetchFunction,
356
- S extends Schema | undefined = any,
357
- O extends {
358
- path: string;
359
- body: any;
360
- searchParams?: any;
361
- } = { path: string; body: any },
362
- > = RestInstanceBase<
363
- RestFetch<
364
- 'searchParams' extends keyof O
365
- ? O['searchParams'] extends undefined
366
- ? PathArgs<Exclude<O['path'], undefined>>
367
- : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
368
- : PathArgs<Exclude<O['path'], undefined>>,
369
- O['body'],
370
- ResolveType<F>
371
- >,
372
- S,
373
- true,
374
- Omit<O, 'method'> & { method: 'POST' }
375
- >;
376
-
377
- type OptionsBodyDefault<O extends RestGenerics> = 'body' extends keyof O
378
- ? O
379
- : O['method'] extends 'POST' | 'PUT' | 'PATCH'
380
- ? O & { body: any }
381
- : O & { body: undefined };
382
-
383
- type OptionsToAdderBodyArgument<O extends { body?: any }> =
384
- 'body' extends keyof O ? O['body'] : any;
385
-
386
- export interface RestEndpointOptions<
387
- F extends FetchFunction = FetchFunction,
388
- S extends Schema | undefined = undefined,
389
- > extends EndpointExtraOptions<F> {
390
- urlPrefix?: string;
391
- requestInit?: RequestInit;
392
- getHeaders?(headers: HeadersInit): Promise<HeadersInit> | HeadersInit;
393
- getRequestInit?(body: any): Promise<RequestInit> | RequestInit;
394
- fetchResponse?(input: RequestInfo, init: RequestInit): Promise<any>;
395
- parseResponse?(response: Response): Promise<any>;
396
-
397
- sideEffect?: true | undefined;
398
- name?: string;
399
- signal?: AbortSignal;
400
- fetch?: F;
401
- key?(...args: Parameters<F>): string;
402
- url?(...args: Parameters<F>): string;
403
- update?: EndpointUpdateFunction<F, S>;
404
- }
405
-
406
- export type RestEndpointConstructorOptions<O extends RestGenerics = any> =
407
- RestEndpointOptions<
408
- RestFetch<
409
- 'searchParams' extends keyof O
410
- ? O['searchParams'] extends undefined
411
- ? PathArgs<O['path']>
412
- : O['searchParams'] & PathArgs<O['path']>
413
- : PathArgs<O['path']>,
414
- OptionsToBodyArgument<
415
- O,
416
- 'method' extends keyof O
417
- ? O['method']
418
- : O extends { sideEffect: true }
419
- ? 'POST'
420
- : 'GET'
421
- >,
422
- O['process'] extends {}
423
- ? ReturnType<O['process']>
424
- : any /*Denormalize<O['schema']>*/
425
- >,
426
- O['schema']
427
- >;
428
-
429
- export interface RestEndpointConstructor {
430
- new <O extends RestGenerics = any>({
431
- method,
432
- sideEffect,
433
- name,
434
- ...options
435
- }: RestEndpointConstructorOptions<O> & Readonly<O>): RestInstance<
436
- RestFetch<
437
- 'searchParams' extends keyof O
438
- ? O['searchParams'] extends undefined
439
- ? PathArgs<O['path']>
440
- : O['searchParams'] & PathArgs<O['path']>
441
- : PathArgs<O['path']>,
442
- OptionsToBodyArgument<
443
- O,
444
- 'method' extends keyof O
445
- ? O['method']
446
- : O extends { sideEffect: true }
447
- ? 'POST'
448
- : 'GET'
449
- >,
450
- O['process'] extends {}
451
- ? ReturnType<O['process']>
452
- : any /*Denormalize<O['schema']>*/
453
- >,
454
- 'schema' extends keyof O ? O['schema'] : undefined,
455
- 'sideEffect' extends keyof O
456
- ? Extract<O['sideEffect'], undefined | true>
457
- : MethodToSide<O['method']>,
458
- 'method' extends keyof O
459
- ? O
460
- : O & {
461
- method: O extends { sideEffect: true } ? 'POST' : 'GET';
462
- }
463
- >;
464
- readonly prototype: RestInstanceBase;
465
- }
2
+ import type { RestEndpointConstructor } from './RestEndpointTypes.js';
3
+ export * from './RestEndpointTypes.js';
466
4
 
467
5
  /** Simplifies endpoint definitions that follow REST patterns
468
6
  *
@@ -470,197 +8,3 @@ export interface RestEndpointConstructor {
470
8
  */
471
9
  export declare let RestEndpoint: RestEndpointConstructor;
472
10
  export default RestEndpoint;
473
-
474
- export type MethodToSide<M> = M extends string
475
- ? M extends 'GET'
476
- ? undefined
477
- : true
478
- : undefined;
479
-
480
- /** RestEndpoint types simplified */
481
- export type RestType<
482
- UrlParams = any,
483
- Body = any,
484
- S extends Schema | undefined = Schema | undefined,
485
- M extends true | undefined = true | undefined,
486
- R = any,
487
- O extends {
488
- path: string;
489
- body?: any;
490
- searchParams?: any;
491
- paginationField?: string;
492
- } = { path: string; paginationField: string },
493
- // eslint-disable-next-line @typescript-eslint/ban-types
494
- > = IfTypeScriptLooseNull<
495
- RestInstance<
496
- keyof UrlParams extends never
497
- ? (this: EndpointInstanceInterface, body?: Body) => Promise<R>
498
- : // even with loose null, this will only be true when all members are optional
499
- {} extends UrlParams
500
- ?
501
- | ((this: EndpointInstanceInterface, body?: Body) => Promise<R>)
502
- | ((
503
- this: EndpointInstanceInterface,
504
- params: UrlParams,
505
- body?: Body,
506
- ) => Promise<R>)
507
- : (
508
- this: EndpointInstanceInterface,
509
- params: UrlParams,
510
- body?: Body,
511
- ) => Promise<R>,
512
- S,
513
- M,
514
- O
515
- >,
516
- Body extends {}
517
- ? RestTypeWithBody<UrlParams, S, M, Body, R, O>
518
- : RestTypeNoBody<UrlParams, S, M, R, O>
519
- >;
520
-
521
- export type RestTypeWithBody<
522
- UrlParams = any,
523
- S extends Schema | undefined = Schema | undefined,
524
- M extends true | undefined = true | undefined,
525
- Body = any,
526
- R = any /*Denormalize<S>*/,
527
- O extends {
528
- path: string;
529
- body?: any;
530
- searchParams?: any;
531
- } = { path: string; body: any },
532
- > = RestInstance<ParamFetchWithBody<UrlParams, Body, R>, S, M, O>;
533
-
534
- export type RestTypeNoBody<
535
- UrlParams = any,
536
- S extends Schema | undefined = Schema | undefined,
537
- M extends true | undefined = true | undefined,
538
- R = any /*Denormalize<S>*/,
539
- O extends {
540
- path: string;
541
- body?: undefined;
542
- searchParams?: any;
543
- } = { path: string; body: undefined },
544
- > = RestInstance<ParamFetchNoBody<UrlParams, R>, S, M, O>;
545
-
546
- /** Simple parameters, and body fetch functions */
547
- export type RestFetch<
548
- UrlParams,
549
- // eslint-disable-next-line @typescript-eslint/ban-types
550
- Body = {},
551
- Resolve = any,
552
- > = IfTypeScriptLooseNull<
553
- | ParamFetchNoBody<UrlParams, Resolve>
554
- | ParamFetchWithBody<UrlParams, Body, Resolve>,
555
- Body extends {}
556
- ? ParamFetchWithBody<UrlParams, Body, Resolve>
557
- : ParamFetchNoBody<UrlParams, Resolve>
558
- >;
559
-
560
- export type ParamFetchWithBody<P, B = {}, R = any> =
561
- // we must always allow undefined in a union and give it a type without params
562
- P extends undefined
563
- ? (this: EndpointInstanceInterface, body: B) => Promise<R>
564
- : // even with loose null, this will only be true when all members are optional
565
- {} extends P
566
- ? // this safely handles PathArgs with no members that results in a simple `unknown` type
567
- keyof P extends never
568
- ? (this: EndpointInstanceInterface, body: B) => Promise<R>
569
- :
570
- | ((
571
- this: EndpointInstanceInterface,
572
- params: P,
573
- body: B,
574
- ) => Promise<R>)
575
- | ((this: EndpointInstanceInterface, body: B) => Promise<R>)
576
- : (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
577
-
578
- export type ParamFetchNoBody<P, R = any> =
579
- // we must always allow undefined in a union and give it a type without params
580
- P extends undefined
581
- ? (this: EndpointInstanceInterface) => Promise<R>
582
- : // even with loose null, this will only be true when all members are optional
583
- {} extends P
584
- ? // this safely handles PathArgs with no members that results in a simple `unknown` type
585
- keyof P extends never
586
- ? (this: EndpointInstanceInterface) => Promise<R>
587
- :
588
- | ((this: EndpointInstanceInterface, params: P) => Promise<R>)
589
- | ((this: EndpointInstanceInterface) => Promise<R>)
590
- : (this: EndpointInstanceInterface, params: P) => Promise<R>;
591
-
592
- type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;
593
-
594
- export type KeyofRestEndpoint = keyof RestInstance;
595
-
596
- export type FromFallBack<K extends keyof E, O, E> = K extends keyof O
597
- ? O[K]
598
- : E[K];
599
-
600
- export type FetchMutate<
601
- A extends readonly any[] = // eslint-disable-next-line @typescript-eslint/ban-types
602
- | [any, {}]
603
- // eslint-disable-next-line @typescript-eslint/ban-types
604
- | [{}],
605
- R = any,
606
- > = (this: RestInstance, ...args: A) => Promise<R>;
607
-
608
- export type FetchGet<A extends readonly any[] = [any], R = any> = (
609
- this: RestInstance,
610
- ...args: A
611
- ) => Promise<R>;
612
-
613
- export type Defaults<O, D> = {
614
- [K in keyof O | keyof D]: K extends keyof O
615
- ? Exclude<O[K], undefined>
616
- : D[Extract<K, keyof D>];
617
- };
618
-
619
- export type GetEndpoint<
620
- O extends {
621
- readonly path: string;
622
- readonly schema: Schema;
623
- /** Only used for types */
624
- readonly searchParams?: any;
625
- readonly paginationField?: string;
626
- } = {
627
- path: string;
628
- schema: Schema;
629
- },
630
- > = RestTypeNoBody<
631
- 'searchParams' extends keyof O
632
- ? O['searchParams'] extends undefined
633
- ? PathArgs<O['path']>
634
- : O['searchParams'] & PathArgs<O['path']>
635
- : PathArgs<O['path']>,
636
- O['schema'],
637
- undefined,
638
- any,
639
- O & { method: 'GET' }
640
- >;
641
-
642
- export type MutateEndpoint<
643
- O extends {
644
- readonly path: string;
645
- readonly schema: Schema;
646
- /** Only used for types */
647
- readonly searchParams?: any;
648
- /** Only used for types */
649
- readonly body?: any;
650
- } = {
651
- path: string;
652
- body: any;
653
- schema: Schema;
654
- },
655
- > = RestTypeWithBody<
656
- 'searchParams' extends keyof O
657
- ? O['searchParams'] extends undefined
658
- ? PathArgs<O['path']>
659
- : O['searchParams'] & PathArgs<O['path']>
660
- : PathArgs<O['path']>,
661
- O['schema'],
662
- true,
663
- O['body'],
664
- any,
665
- O & { body: any; method: 'POST' | 'PUT' | 'PATCH' | 'DELETE' }
666
- >;