@data-client/rest 0.9.8 → 0.9.9

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.
Files changed (46) hide show
  1. package/legacy/OptionsToFunction.js +1 -1
  2. package/legacy/RestEndpoint.js +1 -1
  3. package/legacy/RestEndpointTypeHelp.js +1 -1
  4. package/legacy/RestEndpointTypes.js +1 -1
  5. package/legacy/createResource.js +1 -1
  6. package/legacy/extractCollection.js +1 -1
  7. package/legacy/mapCollection.js +1 -1
  8. package/legacy/pathTypes.js +1 -1
  9. package/legacy/resourceExtensionTypes.js +1 -1
  10. package/legacy/resourceTypes.js +1 -1
  11. package/legacy/utiltypes.js +1 -1
  12. package/lib/OptionsToFunction.d.ts.map +1 -1
  13. package/lib/OptionsToFunction.js +1 -1
  14. package/lib/RestEndpoint.js +1 -1
  15. package/lib/RestEndpointTypeHelp.d.ts.map +1 -1
  16. package/lib/RestEndpointTypeHelp.js +1 -1
  17. package/lib/RestEndpointTypes.d.ts.map +1 -1
  18. package/lib/RestEndpointTypes.js +1 -1
  19. package/lib/createResource.js +1 -1
  20. package/lib/extractCollection.d.ts +2 -2
  21. package/lib/extractCollection.d.ts.map +1 -1
  22. package/lib/extractCollection.js +1 -1
  23. package/lib/mapCollection.d.ts.map +1 -1
  24. package/lib/mapCollection.js +1 -1
  25. package/lib/pathTypes.d.ts.map +1 -1
  26. package/lib/pathTypes.js +1 -1
  27. package/lib/resourceExtensionTypes.d.ts.map +1 -1
  28. package/lib/resourceExtensionTypes.js +1 -1
  29. package/lib/resourceTypes.d.ts.map +1 -1
  30. package/lib/resourceTypes.js +1 -1
  31. package/lib/utiltypes.d.ts.map +1 -1
  32. package/lib/utiltypes.js +1 -1
  33. package/package.json +4 -2
  34. package/src/OptionsToFunction.ts +42 -42
  35. package/src/RestEndpoint.js +3 -3
  36. package/src/RestEndpointTypeHelp.ts +2 -3
  37. package/src/RestEndpointTypes.ts +187 -220
  38. package/src/createResource.ts +2 -2
  39. package/src/extractCollection.ts +13 -13
  40. package/src/mapCollection.ts +14 -22
  41. package/src/pathTypes.ts +27 -36
  42. package/src/resourceExtensionTypes.ts +33 -48
  43. package/src/resourceTypes.ts +76 -80
  44. package/src/utiltypes.ts +3 -3
  45. package/ts4.0/extractCollection.d.ts +2 -2
  46. package/ts4.1/extractCollection.d.ts +2 -2
@@ -29,10 +29,9 @@ export interface RestInstanceBase<
29
29
  /** @see https://dataclient.io/rest/api/RestEndpoint#body */
30
30
  readonly body?: 'body' extends keyof O ? O['body'] : any;
31
31
  /** @see https://dataclient.io/rest/api/RestEndpoint#searchParams */
32
- readonly searchParams?: 'searchParams' extends keyof O
33
- ? O['searchParams']
34
- : // unknown is identity with '&' type operator
35
- unknown;
32
+ readonly searchParams?: 'searchParams' extends keyof O ? O['searchParams']
33
+ : // unknown is identity with '&' type operator
34
+ unknown;
36
35
 
37
36
  /** Pattern to construct url based on Url Parameters
38
37
  * @see https://dataclient.io/rest/api/RestEndpoint#path
@@ -121,14 +120,14 @@ export interface RestInstance<
121
120
  /** Endpoint to append the next page extending a list for pagination
122
121
  * @see https://dataclient.io/rest/api/RestEndpoint#getPage
123
122
  */
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;
123
+ getPage: 'paginationField' extends keyof O ?
124
+ O['paginationField'] extends string ?
125
+ PaginationFieldEndpoint<
126
+ F & { schema: S; sideEffect: M } & O,
127
+ O['paginationField']
128
+ >
129
+ : undefined
130
+ : undefined;
132
131
  /** Endpoint that pushes (place at end) a newly created entity to this Collection
133
132
  * @see https://dataclient.io/rest/api/RestEndpoint#push
134
133
  */
@@ -173,9 +172,8 @@ export type RestEndpointExtendOptions<
173
172
  F extends FetchFunction,
174
173
  > = RestEndpointOptions<
175
174
  OptionsToFunction<O, E, F>,
176
- 'schema' extends keyof O
177
- ? Extract<O['schema'], Schema | undefined>
178
- : E['schema']
175
+ 'schema' extends keyof O ? Extract<O['schema'], Schema | undefined>
176
+ : E['schema']
179
177
  > &
180
178
  Partial<
181
179
  Omit<
@@ -188,98 +186,89 @@ type OptionsToRestEndpoint<
188
186
  O extends PartialRestGenerics,
189
187
  E extends RestInstanceBase & { body?: any; paginationField?: string },
190
188
  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
- >;
189
+ > = 'path' extends keyof O ?
190
+ RestType<
191
+ 'searchParams' extends keyof O ?
192
+ O['searchParams'] extends undefined ?
193
+ PathArgs<Exclude<O['path'], undefined>>
194
+ : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
195
+ : PathArgs<Exclude<O['path'], undefined>>,
196
+ OptionsToBodyArgument<
197
+ 'body' extends keyof O ? O : E,
198
+ 'method' extends keyof O ? O['method'] : E['method']
199
+ >,
200
+ 'schema' extends keyof O ? O['schema'] : E['schema'],
201
+ 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
202
+ O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
203
+ {
204
+ path: Exclude<O['path'], undefined>;
205
+ body: 'body' extends keyof O ? O['body'] : E['body'];
206
+ searchParams: 'searchParams' extends keyof O ? O['searchParams']
207
+ : E['searchParams'];
208
+ method: 'method' extends keyof O ? O['method'] : E['method'];
209
+ paginationField: 'paginationField' extends keyof O ? O['paginationField']
210
+ : E['paginationField'];
211
+ }
212
+ >
213
+ : 'body' extends keyof O ?
214
+ RestType<
215
+ 'searchParams' extends keyof O ?
216
+ O['searchParams'] extends undefined ?
217
+ PathArgs<Exclude<O['path'], undefined>>
218
+ : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>
219
+ : PathArgs<Exclude<E['path'], undefined>>,
220
+ OptionsToBodyArgument<
221
+ O,
222
+ 'method' extends keyof O ? O['method'] : E['method']
223
+ >,
224
+ 'schema' extends keyof O ? O['schema'] : E['schema'],
225
+ 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
226
+ O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
227
+ {
228
+ path: E['path'];
229
+ body: O['body'];
230
+ searchParams: 'searchParams' extends keyof O ? O['searchParams']
231
+ : E['searchParams'];
232
+ method: 'method' extends keyof O ? O['method'] : E['method'];
233
+ paginationField: 'paginationField' extends keyof O ? O['paginationField']
234
+ : Extract<E['paginationField'], string>;
235
+ }
236
+ >
237
+ : 'searchParams' extends keyof O ?
238
+ RestType<
239
+ O['searchParams'] extends undefined ?
240
+ PathArgs<Exclude<O['path'], undefined>>
241
+ : O['searchParams'] & PathArgs<Exclude<E['path'], undefined>>,
242
+ OptionsToBodyArgument<
243
+ E,
244
+ 'method' extends keyof O ? O['method'] : E['method']
245
+ >,
246
+ 'schema' extends keyof O ? O['schema'] : E['schema'],
247
+ 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
248
+ O['process'] extends {} ? ReturnType<O['process']> : ResolveType<F>,
249
+ {
250
+ path: E['path'];
251
+ body: E['body'];
252
+ searchParams: O['searchParams'];
253
+ method: 'method' extends keyof O ? O['method'] : E['method'];
254
+ paginationField: 'paginationField' extends keyof O ? O['paginationField']
255
+ : Extract<E['paginationField'], string>;
256
+ }
257
+ >
258
+ : RestInstance<
259
+ F,
260
+ 'schema' extends keyof O ? O['schema'] : E['schema'],
261
+ 'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect'],
262
+ {
263
+ path: 'path' extends keyof O ? Exclude<O['path'], undefined> : E['path'];
264
+ body: 'body' extends keyof O ? O['body'] : E['body'];
265
+ searchParams: 'searchParams' extends keyof O ? O['searchParams']
266
+ : E['searchParams'];
267
+ method: 'method' extends keyof O ? O['method'] : E['method'];
268
+ paginationField: 'paginationField' extends keyof O ? O['paginationField']
269
+ : E['paginationField'];
270
+ }
271
+ >;
283
272
 
284
273
  export type RestExtendedEndpoint<
285
274
  O extends PartialRestGenerics,
@@ -287,15 +276,14 @@ export type RestExtendedEndpoint<
287
276
  > = OptionsToRestEndpoint<
288
277
  O,
289
278
  E &
290
- (E extends { getPage: { paginationField: string } }
291
- ? { paginationField: E['getPage']['paginationField'] }
292
- : unknown),
279
+ (E extends { getPage: { paginationField: string } } ?
280
+ { paginationField: E['getPage']['paginationField'] }
281
+ : unknown),
293
282
  RestInstance<
294
283
  (
295
284
  ...args: Parameters<E>
296
- ) => O['process'] extends {}
297
- ? Promise<ReturnType<O['process']>>
298
- : ReturnType<E>,
285
+ ) => O['process'] extends {} ? Promise<ReturnType<O['process']>>
286
+ : ReturnType<E>,
299
287
  'schema' extends keyof O ? O['schema'] : E['schema'],
300
288
  'method' extends keyof O ? MethodToSide<O['method']> : E['sideEffect']
301
289
  >
@@ -361,11 +349,11 @@ export type AddEndpoint<
361
349
  } = { path: string; body: any },
362
350
  > = RestInstanceBase<
363
351
  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>>,
352
+ 'searchParams' extends keyof O ?
353
+ O['searchParams'] extends undefined ?
354
+ PathArgs<Exclude<O['path'], undefined>>
355
+ : O['searchParams'] & PathArgs<Exclude<O['path'], undefined>>
356
+ : PathArgs<Exclude<O['path'], undefined>>,
369
357
  O['body'],
370
358
  ResolveType<F>
371
359
  >,
@@ -374,10 +362,9 @@ export type AddEndpoint<
374
362
  Omit<O, 'method'> & { method: 'POST' }
375
363
  >;
376
364
 
377
- type OptionsBodyDefault<O extends RestGenerics> = 'body' extends keyof O
378
- ? O
379
- : O['method'] extends 'POST' | 'PUT' | 'PATCH'
380
- ? O & { body: any }
365
+ type OptionsBodyDefault<O extends RestGenerics> =
366
+ 'body' extends keyof O ? O
367
+ : O['method'] extends 'POST' | 'PUT' | 'PATCH' ? O & { body: any }
381
368
  : O & { body: undefined };
382
369
 
383
370
  type OptionsToAdderBodyArgument<O extends { body?: any }> =
@@ -406,22 +393,19 @@ export interface RestEndpointOptions<
406
393
  export type RestEndpointConstructorOptions<O extends RestGenerics = any> =
407
394
  RestEndpointOptions<
408
395
  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']>,
396
+ 'searchParams' extends keyof O ?
397
+ O['searchParams'] extends undefined ?
398
+ PathArgs<O['path']>
399
+ : O['searchParams'] & PathArgs<O['path']>
400
+ : PathArgs<O['path']>,
414
401
  OptionsToBodyArgument<
415
402
  O,
416
- 'method' extends keyof O
417
- ? O['method']
418
- : O extends { sideEffect: true }
419
- ? 'POST'
420
- : 'GET'
403
+ 'method' extends keyof O ? O['method']
404
+ : O extends { sideEffect: true } ? 'POST'
405
+ : 'GET'
421
406
  >,
422
- O['process'] extends {}
423
- ? ReturnType<O['process']>
424
- : any /*Denormalize<O['schema']>*/
407
+ O['process'] extends {} ? ReturnType<O['process']>
408
+ : any /*Denormalize<O['schema']>*/
425
409
  >,
426
410
  O['schema']
427
411
  >;
@@ -434,39 +418,35 @@ export interface RestEndpointConstructor {
434
418
  ...options
435
419
  }: RestEndpointConstructorOptions<O> & Readonly<O>): RestInstance<
436
420
  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']>,
421
+ 'searchParams' extends keyof O ?
422
+ O['searchParams'] extends undefined ?
423
+ PathArgs<O['path']>
424
+ : O['searchParams'] & PathArgs<O['path']>
425
+ : PathArgs<O['path']>,
442
426
  OptionsToBodyArgument<
443
427
  O,
444
- 'method' extends keyof O
445
- ? O['method']
446
- : O extends { sideEffect: true }
447
- ? 'POST'
448
- : 'GET'
428
+ 'method' extends keyof O ? O['method']
429
+ : O extends { sideEffect: true } ? 'POST'
430
+ : 'GET'
449
431
  >,
450
- O['process'] extends {}
451
- ? ReturnType<O['process']>
452
- : any /*Denormalize<O['schema']>*/
432
+ O['process'] extends {} ? ReturnType<O['process']>
433
+ : any /*Denormalize<O['schema']>*/
453
434
  >,
454
435
  '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
- }
436
+ 'sideEffect' extends keyof O ? Extract<O['sideEffect'], undefined | true>
437
+ : MethodToSide<O['method']>,
438
+ 'method' extends keyof O ? O
439
+ : O & {
440
+ method: O extends { sideEffect: true } ? 'POST' : 'GET';
441
+ }
463
442
  >;
464
443
  readonly prototype: RestInstanceBase;
465
444
  }
466
445
 
467
- export type MethodToSide<M> = M extends string
468
- ? M extends 'GET'
469
- ? undefined
446
+ export type MethodToSide<M> =
447
+ M extends string ?
448
+ M extends 'GET' ?
449
+ undefined
470
450
  : true
471
451
  : undefined;
472
452
 
@@ -486,29 +466,27 @@ export type RestType<
486
466
  // eslint-disable-next-line @typescript-eslint/ban-types
487
467
  > = IfTypeScriptLooseNull<
488
468
  RestInstance<
489
- keyof UrlParams extends never
490
- ? (this: EndpointInstanceInterface, body?: Body) => Promise<R>
491
- : // even with loose null, this will only be true when all members are optional
492
- {} extends UrlParams
493
- ?
494
- | ((this: EndpointInstanceInterface, body?: Body) => Promise<R>)
495
- | ((
496
- this: EndpointInstanceInterface,
497
- params: UrlParams,
498
- body?: Body,
499
- ) => Promise<R>)
500
- : (
469
+ keyof UrlParams extends never ?
470
+ (this: EndpointInstanceInterface, body?: Body) => Promise<R>
471
+ : // even with loose null, this will only be true when all members are optional
472
+ {} extends UrlParams ?
473
+ | ((this: EndpointInstanceInterface, body?: Body) => Promise<R>)
474
+ | ((
501
475
  this: EndpointInstanceInterface,
502
476
  params: UrlParams,
503
477
  body?: Body,
504
- ) => Promise<R>,
478
+ ) => Promise<R>)
479
+ : (
480
+ this: EndpointInstanceInterface,
481
+ params: UrlParams,
482
+ body?: Body,
483
+ ) => Promise<R>,
505
484
  S,
506
485
  M,
507
486
  O
508
487
  >,
509
- Body extends {}
510
- ? RestTypeWithBody<UrlParams, S, M, Body, R, O>
511
- : RestTypeNoBody<UrlParams, S, M, R, O>
488
+ Body extends {} ? RestTypeWithBody<UrlParams, S, M, Body, R, O>
489
+ : RestTypeNoBody<UrlParams, S, M, R, O>
512
490
  >;
513
491
 
514
492
  export type RestTypeWithBody<
@@ -545,50 +523,40 @@ export type RestFetch<
545
523
  > = IfTypeScriptLooseNull<
546
524
  | ParamFetchNoBody<UrlParams, Resolve>
547
525
  | ParamFetchWithBody<UrlParams, Body, Resolve>,
548
- Body extends {}
549
- ? ParamFetchWithBody<UrlParams, Body, Resolve>
550
- : ParamFetchNoBody<UrlParams, Resolve>
526
+ Body extends {} ? ParamFetchWithBody<UrlParams, Body, Resolve>
527
+ : ParamFetchNoBody<UrlParams, Resolve>
551
528
  >;
552
529
 
553
530
  export type ParamFetchWithBody<P, B = {}, R = any> =
554
531
  // we must always allow undefined in a union and give it a type without params
555
- P extends undefined
556
- ? (this: EndpointInstanceInterface, body: B) => Promise<R>
557
- : // even with loose null, this will only be true when all members are optional
558
- {} extends P
559
- ? // this safely handles PathArgs with no members that results in a simple `unknown` type
560
- keyof P extends never
561
- ? (this: EndpointInstanceInterface, body: B) => Promise<R>
562
- :
563
- | ((
564
- this: EndpointInstanceInterface,
565
- params: P,
566
- body: B,
567
- ) => Promise<R>)
568
- | ((this: EndpointInstanceInterface, body: B) => Promise<R>)
569
- : (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
532
+ P extends undefined ? (this: EndpointInstanceInterface, body: B) => Promise<R>
533
+ : // even with loose null, this will only be true when all members are optional
534
+ {} extends P ?
535
+ // this safely handles PathArgs with no members that results in a simple `unknown` type
536
+ keyof P extends never ?
537
+ (this: EndpointInstanceInterface, body: B) => Promise<R>
538
+ : | ((this: EndpointInstanceInterface, params: P, body: B) => Promise<R>)
539
+ | ((this: EndpointInstanceInterface, body: B) => Promise<R>)
540
+ : (this: EndpointInstanceInterface, params: P, body: B) => Promise<R>;
570
541
 
571
542
  export type ParamFetchNoBody<P, R = any> =
572
543
  // we must always allow undefined in a union and give it a type without params
573
- P extends undefined
574
- ? (this: EndpointInstanceInterface) => Promise<R>
575
- : // even with loose null, this will only be true when all members are optional
576
- {} extends P
577
- ? // this safely handles PathArgs with no members that results in a simple `unknown` type
578
- keyof P extends never
579
- ? (this: EndpointInstanceInterface) => Promise<R>
580
- :
581
- | ((this: EndpointInstanceInterface, params: P) => Promise<R>)
582
- | ((this: EndpointInstanceInterface) => Promise<R>)
583
- : (this: EndpointInstanceInterface, params: P) => Promise<R>;
544
+ P extends undefined ? (this: EndpointInstanceInterface) => Promise<R>
545
+ : // even with loose null, this will only be true when all members are optional
546
+ {} extends P ?
547
+ // this safely handles PathArgs with no members that results in a simple `unknown` type
548
+ keyof P extends never ?
549
+ (this: EndpointInstanceInterface) => Promise<R>
550
+ : | ((this: EndpointInstanceInterface, params: P) => Promise<R>)
551
+ | ((this: EndpointInstanceInterface) => Promise<R>)
552
+ : (this: EndpointInstanceInterface, params: P) => Promise<R>;
584
553
 
585
554
  type IfTypeScriptLooseNull<Y, N> = 1 | undefined extends 1 ? Y : N;
586
555
 
587
556
  export type KeyofRestEndpoint = keyof RestInstance;
588
557
 
589
- export type FromFallBack<K extends keyof E, O, E> = K extends keyof O
590
- ? O[K]
591
- : E[K];
558
+ export type FromFallBack<K extends keyof E, O, E> = K extends keyof O ? O[K]
559
+ : E[K];
592
560
 
593
561
  export type FetchMutate<
594
562
  A extends readonly any[] = // eslint-disable-next-line @typescript-eslint/ban-types
@@ -604,9 +572,8 @@ export type FetchGet<A extends readonly any[] = [any], R = any> = (
604
572
  ) => Promise<R>;
605
573
 
606
574
  export type Defaults<O, D> = {
607
- [K in keyof O | keyof D]: K extends keyof O
608
- ? Exclude<O[K], undefined>
609
- : D[Extract<K, keyof D>];
575
+ [K in keyof O | keyof D]: K extends keyof O ? Exclude<O[K], undefined>
576
+ : D[Extract<K, keyof D>];
610
577
  };
611
578
 
612
579
  export type GetEndpoint<
@@ -621,11 +588,11 @@ export type GetEndpoint<
621
588
  schema: Schema;
622
589
  },
623
590
  > = RestTypeNoBody<
624
- 'searchParams' extends keyof O
625
- ? O['searchParams'] extends undefined
626
- ? PathArgs<O['path']>
627
- : O['searchParams'] & PathArgs<O['path']>
628
- : PathArgs<O['path']>,
591
+ 'searchParams' extends keyof O ?
592
+ O['searchParams'] extends undefined ?
593
+ PathArgs<O['path']>
594
+ : O['searchParams'] & PathArgs<O['path']>
595
+ : PathArgs<O['path']>,
629
596
  O['schema'],
630
597
  undefined,
631
598
  any,
@@ -646,11 +613,11 @@ export type MutateEndpoint<
646
613
  schema: Schema;
647
614
  },
648
615
  > = RestTypeWithBody<
649
- 'searchParams' extends keyof O
650
- ? O['searchParams'] extends undefined
651
- ? PathArgs<O['path']>
652
- : O['searchParams'] & PathArgs<O['path']>
653
- : PathArgs<O['path']>,
616
+ 'searchParams' extends keyof O ?
617
+ O['searchParams'] extends undefined ?
618
+ PathArgs<O['path']>
619
+ : O['searchParams'] & PathArgs<O['path']>
620
+ : PathArgs<O['path']>,
654
621
  O['schema'],
655
622
  true,
656
623
  O['body'],
@@ -159,7 +159,7 @@ function optimisticDelete(snap: SnapshotInterface, params: any) {
159
159
  return params;
160
160
  }
161
161
  function ensurePojo(body: any) {
162
- return body instanceof FormData
163
- ? Object.fromEntries((body as any).entries())
162
+ return body instanceof FormData ?
163
+ Object.fromEntries((body as any).entries())
164
164
  : body;
165
165
  }
@@ -20,17 +20,17 @@ export default function extractCollection<
20
20
  }
21
21
  }
22
22
 
23
- export type ExtractCollection<S extends Schema | undefined> = S extends {
24
- push: any;
25
- unshift: any;
26
- assign: any;
27
- schema: Schema;
28
- }
29
- ? S
30
- : S extends schema.Object<infer T>
31
- ? ExtractObject<T>
32
- : S extends Exclude<Schema, { [K: string]: any }>
33
- ? never
34
- : S extends { [K: string]: Schema }
35
- ? ExtractObject<S>
23
+ export type ExtractCollection<S extends Schema | undefined> =
24
+ S extends (
25
+ {
26
+ push: any;
27
+ unshift: any;
28
+ assign: any;
29
+ schema: Schema;
30
+ }
31
+ ) ?
32
+ S
33
+ : S extends schema.Object<infer T> ? ExtractObject<T>
34
+ : S extends Exclude<Schema, { [K: string]: any }> ? never
35
+ : S extends { [K: string]: Schema } ? ExtractObject<S>
36
36
  : never;
@@ -6,21 +6,16 @@ export default function mapCollection<
6
6
  >(
7
7
  s: S,
8
8
  mapper: M,
9
- ): S extends schema.Collection
10
- ? ReturnType<typeof mapper<S>>
11
- : S extends schema.Object<infer T>
12
- ? {
13
- [K in keyof T]: T[K] extends Schema
14
- ? typeof mapCollection<M, T[K]>
15
- : T[K];
16
- }
17
- : S extends { [K: string]: any }
18
- ? {
19
- [K in keyof S]: S[K] extends Schema
20
- ? typeof mapCollection<M, S[K]>
21
- : S[K];
22
- }
23
- : S {
9
+ ): S extends schema.Collection ? ReturnType<typeof mapper<S>>
10
+ : S extends schema.Object<infer T> ?
11
+ {
12
+ [K in keyof T]: T[K] extends Schema ? typeof mapCollection<M, T[K]> : T[K];
13
+ }
14
+ : S extends { [K: string]: any } ?
15
+ {
16
+ [K in keyof S]: S[K] extends Schema ? typeof mapCollection<M, S[K]> : S[K];
17
+ }
18
+ : S {
24
19
  if (typeof s !== 'object' || s === undefined) return s as any;
25
20
  if (s instanceof schema.Collection) {
26
21
  return mapper(s as any);
@@ -38,13 +33,10 @@ export default function mapCollection<
38
33
  type MapCollection<
39
34
  M extends <C extends schema.Collection>(collection: C) => any,
40
35
  S extends Schema | undefined,
41
- > = S extends schema.Collection
42
- ? ReturnType<M>
43
- : S extends schema.Object<infer T>
44
- ? MapCollection<M, T>
45
- : S extends { [K: string]: any }
46
- ? MapObject<M, S>
47
- : never;
36
+ > = S extends schema.Collection ? ReturnType<M>
37
+ : S extends schema.Object<infer T> ? MapCollection<M, T>
38
+ : S extends { [K: string]: any } ? MapObject<M, S>
39
+ : never;
48
40
 
49
41
  export type MapObject<
50
42
  M extends (collection: schema.Collection) => any,