-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditional.ts
More file actions
47 lines (42 loc) · 1.44 KB
/
additional.ts
File metadata and controls
47 lines (42 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import type { DevupApiServers } from './api-struct'
import type { Middleware } from './middleware'
export type Additional<
T extends string,
Target extends object,
> = T extends keyof Target ? Target[T] & object : object
export type RequiredOptions<T extends object> = ('params' | 'query' | 'body') &
keyof T extends never
? never
: T
export type IsCold = keyof DevupApiServers extends never ? true : false
export type DevupApiRequestInit = Omit<RequestInit, 'body'> & {
body?: object | RequestInit['body']
params?: Record<string, string | number | boolean | null | undefined>
query?:
| ConstructorParameters<typeof URLSearchParams>[0]
| Record<
string,
| string
| number
| boolean
| null
| undefined
| (number | string | boolean)[]
>
middleware?: Middleware[]
}
// biome-ignore lint/suspicious/noExplicitAny: any is used to allow for flexibility in the type
export type ExtractValue<T, V extends string, F = any> = V extends keyof T
? T[V]
: F
export type BoildApiOption<O> = Omit<DevupApiRequestInit, 'params'> &
Omit<O, 'response' | 'error'>
export type ConditionalApiOption<
O,
_Cold extends boolean = IsCold,
> = _Cold extends true ? DevupApiRequestInit : BoildApiOption<O>
export type ApiOption<O extends object, R extends unknown[] = []> = [
RequiredOptions<O>,
] extends [never]
? [options?: ConditionalApiOption<O>, ...R]
: [options: BoildApiOption<O>, ...R]