forked from RocketChat/Rocket.Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
271 lines (242 loc) · 10.1 KB
/
index.ts
File metadata and controls
271 lines (242 loc) · 10.1 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
// import type { EnterpriseEndpoints } from "@rocket.chat/core-typings";
import type { KeyOfEach } from '@rocket.chat/core-typings';
import type { AppsEndpoints } from './apps';
import type { DefaultEndpoints } from './default';
import type { ReplacePlaceholders } from './helpers/ReplacePlaceholders';
import type { AssetsEndpoints } from './v1/assets';
import type { AuthEndpoints } from './v1/auth';
import type { AutoTranslateEndpoints } from './v1/autoTranslate';
import type { BannersEndpoints } from './v1/banners';
import type { CalendarEndpoints } from './v1/calendar';
import type { ChannelsEndpoints } from './v1/channels';
import type { ChatEndpoints } from './v1/chat';
import type { CloudEndpoints } from './v1/cloud';
import type { CommandsEndpoints } from './v1/commands';
import type { CustomUserStatusEndpoints } from './v1/customUserStatus';
import type { DirectoryEndpoint } from './v1/directory';
import type { ImEndpoints, DmEndpoints } from './v1/dm';
import type { DnsEndpoints } from './v1/dns';
import type { E2eEndpoints } from './v1/e2e';
import type { EmailInboxEndpoints } from './v1/email-inbox';
import type { EmojiCustomEndpoints } from './v1/emojiCustom';
import type { FederationEndpoints } from './v1/federation';
import type { GroupsEndpoints } from './v1/groups';
import type { ImportEndpoints } from './v1/import';
import type { InstancesEndpoints } from './v1/instances';
import type { IntegrationsEndpoints } from './v1/integrations';
import type { IntegrationHooksEndpoints } from './v1/integrations/hooks';
import type { InvitesEndpoints } from './v1/invites';
import type { LDAPEndpoints } from './v1/ldap';
import type { LicensesEndpoints } from './v1/licenses';
import type { MailerEndpoints } from './v1/mailer';
import type { MeEndpoints } from './v1/me';
import type { MiscEndpoints } from './v1/misc';
import type { ModerationEndpoints } from './v1/moderation';
import type { OmnichannelEndpoints } from './v1/omnichannel';
import type { PresenceEndpoints } from './v1/presence';
import type { PushEndpoints } from './v1/push';
import type { RolesEndpoints } from './v1/roles';
import type { RoomsEndpoints } from './v1/rooms';
import type { ServerEventsEndpoints } from './v1/server-events';
import type { SettingsEndpoints } from './v1/settings';
import type { StatisticsEndpoints } from './v1/statistics';
import type { SubscriptionsEndpoints } from './v1/subscriptionsEndpoints';
import type { TeamsEndpoints } from './v1/teams';
import type { UsersEndpoints } from './v1/users';
import type { VideoConferenceEndpoints } from './v1/videoConference';
import type { VoipEndpoints } from './v1/voip';
import type { VoipFreeSwitchEndpoints } from './v1/voip-freeswitch';
// eslint-disable-next-line @typescript-eslint/naming-convention
export interface Endpoints
extends ChannelsEndpoints,
MeEndpoints,
ModerationEndpoints,
BannersEndpoints,
ChatEndpoints,
CommandsEndpoints,
CloudEndpoints,
CommandsEndpoints,
CustomUserStatusEndpoints,
DmEndpoints,
DnsEndpoints,
DirectoryEndpoint,
EmojiCustomEndpoints,
GroupsEndpoints,
ImEndpoints,
LDAPEndpoints,
RoomsEndpoints,
PushEndpoints,
RolesEndpoints,
TeamsEndpoints,
SettingsEndpoints,
UsersEndpoints,
AppsEndpoints,
OmnichannelEndpoints,
StatisticsEndpoints,
LicensesEndpoints,
MiscEndpoints,
PresenceEndpoints,
InstancesEndpoints,
IntegrationsEndpoints,
IntegrationHooksEndpoints,
VoipEndpoints,
VideoConferenceEndpoints,
InvitesEndpoints,
E2eEndpoints,
AssetsEndpoints,
EmailInboxEndpoints,
MailerEndpoints,
SubscriptionsEndpoints,
AutoTranslateEndpoints,
ImportEndpoints,
FederationEndpoints,
CalendarEndpoints,
AuthEndpoints,
ImportEndpoints,
VoipFreeSwitchEndpoints,
ServerEventsEndpoints,
DefaultEndpoints {}
type OperationsByPathPatternAndMethod<
TEndpoints extends Endpoints,
TPathPattern extends keyof TEndpoints,
TMethod extends KeyOfEach<TEndpoints[TPathPattern]> = KeyOfEach<TEndpoints[TPathPattern]>,
> = TMethod extends any
? {
pathPattern: TPathPattern;
method: TMethod;
fn: TEndpoints[TPathPattern][TMethod];
path: ReplacePlaceholders<TPathPattern extends string ? TPathPattern : never>;
params: GetParams<TEndpoints[TPathPattern][TMethod]>;
result: GetResult<TEndpoints[TPathPattern][TMethod]>;
}
: never;
type OperationsByPathPattern<TEndpoints extends Endpoints, TPathPattern extends keyof TEndpoints> = TPathPattern extends any
? OperationsByPathPatternAndMethod<TEndpoints, TPathPattern>
: never;
type Operations = OperationsByPathPattern<Endpoints, keyof Endpoints>;
export type PathPattern = Operations['pathPattern'];
export type Method = Operations['method'];
export type Path = Operations['path'];
type MethodToPathMap = {
[TOperation in Operations as TOperation['method']]: TOperation['path'];
};
type MethodToPathWithParamsMap = {
[TOperation in Operations as Parameters<TOperation['fn']> extends { length: 0 } ? never : TOperation['method']]: TOperation['path'];
};
type MethodToPathWithoutParamsMap = {
[TOperation in Operations as Parameters<TOperation['fn']> extends { length: 0 }
? TOperation['method']
: undefined extends Parameters<TOperation['fn']>[0]
? TOperation['method']
: never]: TOperation['path'];
};
export type PathFor<TMethod extends Method> = MethodToPathMap[TMethod];
export type PathWithParamsFor<TMethod extends Method> = MethodToPathWithParamsMap[TMethod extends keyof MethodToPathWithParamsMap
? TMethod
: never];
export type PathWithoutParamsFor<TMethod extends Method> = MethodToPathWithoutParamsMap[TMethod extends keyof MethodToPathWithoutParamsMap
? TMethod
: never];
type MethodToPathPatternToParamsMap = {
[TMethod in Method]: {
[TPathPattern in keyof Endpoints]: TMethod extends keyof Endpoints[TPathPattern]
? Endpoints[TPathPattern][TMethod] extends infer TOperation
? TOperation extends (...args: any) => any
? Parameters<TOperation>[0]
: never
: never
: never;
};
};
type MethodToPathPatternToResultMap = {
[TMethod in Method]: {
[TPathPattern in keyof Endpoints]: TMethod extends keyof Endpoints[TPathPattern]
? Endpoints[TPathPattern][TMethod] extends infer TOperation
? TOperation extends (...args: any) => any
? ReturnType<TOperation>
: never
: never
: never;
};
};
export type ParamsFor<TMethod extends Method, TPathPattern extends PathPattern> = MethodToPathPatternToParamsMap[TMethod][TPathPattern];
export type ResultFor<TMethod extends Method, TPathPattern extends PathPattern> = MethodToPathPatternToResultMap[TMethod][TPathPattern];
export type MatchPathPattern<TPath extends Path> = TPath extends any ? Extract<Operations, { path: TPath }>['pathPattern'] : never;
export type JoinPathPattern<TBasePath extends string, TSubPathPattern extends string> = Extract<
PathPattern,
`${TBasePath}${TSubPathPattern extends '' ? TSubPathPattern : `/${TSubPathPattern}`}` | TSubPathPattern
>;
type GetParams<TOperation> = TOperation extends (...args: any) => any ? Parameters<TOperation>[0] : never;
type GetResult<TOperation> = TOperation extends (...args: any) => any ? ReturnType<TOperation> : never;
export type OperationParams<TMethod extends Method, TPathPattern extends PathPattern> = TMethod extends keyof Endpoints[TPathPattern]
? GetParams<Endpoints[TPathPattern][TMethod]>
: never;
export type OperationResult<TMethod extends Method, TPathPattern extends PathPattern> = TMethod extends keyof Endpoints[TPathPattern]
? GetResult<Endpoints[TPathPattern][TMethod]>
: never;
export type UrlParams<T extends string> = string extends T
? Record<string, string>
: T extends `${string}:${infer Param}/${infer Rest}`
? { [k in Param | keyof UrlParams<Rest>]: string }
: T extends `${string}:${infer Param}`
? { [k in Param]: string }
: undefined | Record<string, never>;
export type MethodOf<TPathPattern extends PathPattern> = TPathPattern extends any ? keyof Endpoints[TPathPattern] : never;
export * from './apps';
export * from './v1/presence';
export * from './v1/roles';
export * from './v1/settings';
export * from './v1/teams';
export * from './v1/videoConference';
export * from './v1/assets';
export * from './v1/channels';
export * from './v1/customUserStatus';
export * from './v1/subscriptionsEndpoints';
export * from './v1/mailer';
export * from './v1/mailer/MailerParamsPOST';
export * from './v1/mailer/MailerUnsubscribeParamsPOST';
export * from './v1/misc';
export * from './v1/invites';
export * from './v1/dm';
export * from './v1/dm/DmHistoryProps';
export * from './v1/integrations';
export * from './v1/licenses';
export * from './v1/omnichannel';
export * from './helpers/PaginatedRequest';
export * from './helpers/PaginatedResult';
export * from './helpers/ReplacePlaceholders';
export * from './helpers/WithItemCount';
export * from './v1/emojiCustom';
export * from './v1/instances';
export * from './v1/users';
export * from './v1/users/UsersSetAvatarParamsPOST';
export * from './v1/users/UsersSetPreferenceParamsPOST';
export * from './v1/users/UsersUpdateOwnBasicInfoParamsPOST';
export * from './v1/users/UsersUpdateParamsPOST';
export * from './v1/users/UsersCheckUsernameAvailabilityParamsGET';
export * from './v1/users/UsersSendConfirmationEmailParamsPOST';
export * from './v1/moderation';
export * from './v1/server-events';
export * from './v1/autotranslate/AutotranslateGetSupportedLanguagesParamsGET';
export * from './v1/autotranslate/AutotranslateSaveSettingsParamsPOST';
export * from './v1/autotranslate/AutotranslateTranslateMessageParamsPOST';
export * from './v1/e2e/e2eGetUsersOfRoomWithoutKeyParamsGET';
export * from './v1/e2e/e2eSetRoomKeyIDParamsPOST';
export * from './v1/e2e/e2eSetUserPublicAndPrivateKeysParamsPOST';
export * from './v1/e2e/e2eUpdateGroupKeyParamsPOST';
export * from './v1/e2e';
export * from './v1/import';
export * from './v1/voip';
export * from './v1/voip-freeswitch';
export * from './v1/email-inbox';
export * from './v1/calendar';
export * from './v1/federation';
export * from './v1/rooms';
export * from './v1/groups';
export * from './v1/chat';
export * from './v1/auth';
export * from './v1/cloud';
export * from './v1/banners';
export * from './default';
// Export the ajv instance for use in other packages
export * from './v1/Ajv';