-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadditional.ts
More file actions
43 lines (38 loc) · 1.4 KB
/
additional.ts
File metadata and controls
43 lines (38 loc) · 1.4 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
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> = keyof T extends undefined
? never
: 'params' extends keyof T
? T
: 'query' extends keyof T
? T
: 'body' extends keyof T
? T
: never
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 | (number | string)[]>
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> = IsCold 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]