-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-struct.ts
More file actions
150 lines (128 loc) · 4.47 KB
/
api-struct.ts
File metadata and controls
150 lines (128 loc) · 4.47 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import type { ExtractValue } from './additional'
import type { ConditionalKeys, ConditionalScope } from './utils'
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupApiServers {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupGetApiStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupPostApiStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupPutApiStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupDeleteApiStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupPatchApiStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupRequestComponentStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupResponseComponentStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface
export interface DevupErrorComponentStruct {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface for augmentation by generator
export interface DevupPrecomputedMethodKeys {}
// biome-ignore lint/suspicious/noEmptyInterface: empty interface for augmentation by generator
export interface DevupPrecomputedScopes {}
type LowercaseMethod = 'get' | 'post' | 'put' | 'delete' | 'patch'
type DevupComponentStructByRole = {
response: DevupResponseComponentStruct
request: DevupRequestComponentStruct
error: DevupErrorComponentStruct
}
type DevupObjectAll<T extends string> = ExtractValue<
DevupResponseComponentStruct,
T,
unknown
> &
ExtractValue<DevupRequestComponentStruct, T, unknown> &
ExtractValue<DevupErrorComponentStruct, T, unknown>
type DevupObjectSpecific<
R extends keyof DevupComponentStructByRole,
T extends string,
> = ExtractValue<DevupComponentStructByRole[R], T>
export type DevupObject<
R extends keyof DevupComponentStructByRole = keyof DevupComponentStructByRole,
T extends keyof DevupApiServers | (string & {}) = 'openapi.json',
> = [keyof DevupComponentStructByRole] extends [R]
? DevupObjectAll<T & string>
: DevupObjectSpecific<R, T & string>
export type DevupGetApiStructScope<O extends string> = ConditionalScope<
DevupGetApiStruct,
O
>
export type DevupPostApiStructScope<O extends string> = ConditionalScope<
DevupPostApiStruct,
O
>
export type DevupPutApiStructScope<O extends string> = ConditionalScope<
DevupPutApiStruct,
O
>
export type DevupDeleteApiStructScope<O extends string> = ConditionalScope<
DevupDeleteApiStruct,
O
>
export type DevupPatchApiStructScope<O extends string> = ConditionalScope<
DevupPatchApiStruct,
O
>
export type DevupGetApiStructKey<O extends string> = ConditionalKeys<
DevupGetApiStructScope<O>
>
export type DevupPostApiStructKey<O extends string> = ConditionalKeys<
DevupPostApiStructScope<O>
>
export type DevupPutApiStructKey<O extends string> = ConditionalKeys<
DevupPutApiStructScope<O>
>
export type DevupDeleteApiStructKey<O extends string> = ConditionalKeys<
DevupDeleteApiStructScope<O>
>
export type DevupPatchApiStructKey<O extends string> = ConditionalKeys<
DevupPatchApiStructScope<O>
>
export type DevupApiMethodKeys =
| 'get'
| 'post'
| 'put'
| 'delete'
| 'patch'
| 'GET'
| 'POST'
| 'PUT'
| 'DELETE'
| 'PATCH'
export type DevupApiMethodScope<
S extends string,
M extends DevupApiMethodKeys,
> = M extends 'get' | 'GET'
? DevupGetApiStructScope<S>
: M extends 'post' | 'POST'
? DevupPostApiStructScope<S>
: M extends 'put' | 'PUT'
? DevupPutApiStructScope<S>
: M extends 'delete' | 'DELETE'
? DevupDeleteApiStructScope<S>
: M extends 'patch' | 'PATCH'
? DevupPatchApiStructScope<S>
: never
export type DevupApiMethodKey<
S extends string,
M extends DevupApiMethodKeys,
> = S extends keyof DevupPrecomputedMethodKeys
? ExtractValue<
ExtractValue<DevupPrecomputedMethodKeys, S>,
Lowercase<M> & LowercaseMethod,
never
>
: ConditionalKeys<DevupApiMethodScope<S, M>>
export type DevupApiStructScope<O extends string> = DevupGetApiStructScope<O> &
DevupPostApiStructScope<O> &
DevupPutApiStructScope<O> &
DevupDeleteApiStructScope<O> &
DevupPatchApiStructScope<O>
export type DevupApiStructKey<O extends string> =
| DevupGetApiStructKey<O>
| DevupPostApiStructKey<O>
| DevupPutApiStructKey<O>
| DevupDeleteApiStructKey<O>
| DevupPatchApiStructKey<O>