-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
ovsx-types.ts
309 lines (285 loc) · 8.96 KB
/
ovsx-types.ts
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
// *****************************************************************************
// Copyright (C) 2020 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************
import { MaybePromise } from './types';
export interface ExtensionLike {
name: string;
namespace: string;
version?: string;
}
export namespace ExtensionLike {
export function id<T extends ExtensionLike>(extension: T): `${string}.${string}` {
return `${extension.namespace}.${extension.name}`;
}
export function idWithVersion<T extends ExtensionLike>(extension: T): `${string}.${string}@${string}` {
if (!extension.version) {
throw new Error(`no valid "version" value provided for "${id(extension)}"`);
}
return `${id(extension)}@${extension.version}`;
}
// eslint-disable-next-line @typescript-eslint/no-shadow
export function fromId(id: string): ExtensionLike {
const [left, version] = id.split('@', 2);
const [namespace, name] = left.split('.', 2);
return {
name,
namespace,
version
};
}
}
export interface OVSXClient {
/**
* GET https://openvsx.org/api/-/search
*/
search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult>;
/**
* GET https://openvsx.org/api/v2/-/query
*
* Fetch one or all versions of an extension.
*/
query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult>;
}
/** @deprecated since 1.31.0 use {@link VSXSearchOptions} instead */
export type VSXSearchParam = VSXSearchOptions;
/**
* The possible options when performing a search.
*
* For available options, and default values consult the `swagger`: https://open-vsx.org/swagger-ui/index.html.
*
* Should be aligned with https://github.com/eclipse/openvsx/blob/b5694a712e07d266801394916bac30609e16d77b/server/src/main/java/org/eclipse/openvsx/RegistryAPI.java#L246-L266
*/
export interface VSXSearchOptions {
/**
* The query text for searching.
*/
query?: string;
/**
* The extension category.
*/
category?: string;
/**
* The maximum number of entries to return.
*/
size?: number;
/**
* The number of entries to skip (usually a multiple of the page size).
*/
offset?: number;
/**
* The sort order.
*/
sortOrder?: 'asc' | 'desc';
/**
* The sort key.
*/
sortBy?: 'averageRating' | 'downloadCount' | 'relevance' | 'timestamp';
/**
* By default an OpenVSX registry will return the last known version of
* extensions. Setting this field to `true` will have the registry specify
* the {@link VSXExtensionRaw.allVersions} field which references all known
* versions for each returned extension.
*
* @default false
*/
includeAllVersions?: boolean;
}
/**
* Should be aligned with https://github.com/eclipse/openvsx/blob/e8f64fe145fc05d2de1469735d50a7a90e400bc4/server/src/main/java/org/eclipse/openvsx/json/SearchResultJson.java
*/
export interface VSXSearchResult {
offset: number;
extensions: VSXSearchEntry[];
}
/**
* The possible options when performing a search.
*
* For available options, and default values consult the `swagger`: https://open-vsx.org/swagger-ui/index.html.
*
* Should be aligned with https://github.com/eclipse/openvsx/blob/b5694a712e07d266801394916bac30609e16d77b/server/src/main/java/org/eclipse/openvsx/json/QueryParamJson.java#L18-L46
*/
export interface VSXQueryOptions {
namespaceName?: string;
extensionName?: string;
extensionVersion?: string;
extensionId?: string;
extensionUuid?: string;
namespaceUuid?: string;
includeAllVersions?: boolean | 'links';
targetPlatform?: VSXTargetPlatform;
size?: number;
offset?: number;
}
export type VSXTargetPlatform =
'universal' | 'web' |
'win32-x64' | 'win32-ia32' | 'win32-arm64' |
'darwin-x64' | 'darwin-arm64' |
'linux-x64' | 'linux-arm64' | 'linux-armhf' |
'alpine-x64' | 'alpine-arm64' | (string & {});
export interface VSXQueryResult {
success?: string;
warning?: string;
error?: string;
offset: number;
totalSize: number;
extensions: VSXExtensionRaw[];
}
/**
* This type describes the data as found in {@link VSXSearchEntry.allVersions}.
*
* Note that this type only represents one version of a given plugin, despite the name.
*/
export interface VSXAllVersions {
url: string;
version: string;
engines?: {
[version: string]: string;
};
}
/**
* Should be aligned with https://github.com/eclipse/openvsx/blob/master/server/src/main/java/org/eclipse/openvsx/json/SearchEntryJson.java
*/
export interface VSXSearchEntry {
url: string;
files: {
download: string;
manifest?: string;
readme?: string;
license?: string;
icon?: string;
};
name: string;
namespace: string;
version: string;
timestamp: string;
averageRating?: number;
downloadCount: number;
displayName?: string;
description?: string;
/**
* May be undefined when {@link VSXSearchOptions.includeAllVersions} is
* `false` or `undefined`.
*/
allVersions?: VSXAllVersions[];
}
export type VSXExtensionNamespaceAccess = 'public' | 'restricted';
/**
* Should be aligned with https://github.com/eclipse/openvsx/blob/master/server/src/main/java/org/eclipse/openvsx/json/UserJson.java
*/
export interface VSXUser {
loginName: string;
homepage?: string;
}
export interface VSXExtensionRawFiles {
download: string;
readme?: string;
license?: string;
icon?: string;
}
/**
* Should be aligned with https://github.com/eclipse/openvsx/blob/master/server/src/main/java/org/eclipse/openvsx/json/ExtensionJson.java
*/
export interface VSXExtensionRaw {
error?: string;
namespaceUrl: string;
reviewsUrl: string;
name: string;
namespace: string;
targetPlatform?: VSXTargetPlatform;
publishedBy: VSXUser;
preRelease: boolean;
namespaceAccess: VSXExtensionNamespaceAccess;
files: VSXExtensionRawFiles;
allVersions: {
[version: string]: string;
};
allVersionsUrl?: string;
averageRating?: number;
downloadCount: number;
reviewCount: number;
version: string;
timestamp: string;
preview?: boolean;
verified?: boolean;
displayName?: string;
namespaceDisplayName: string;
description?: string;
categories?: string[];
extensionKind?: string[];
tags?: string[];
license?: string;
homepage?: string;
repository?: string;
sponsorLink?: string;
bugs?: string;
markdown?: string;
galleryColor?: string;
galleryTheme?: string;
localizedLanguages?: string[];
qna?: string;
badges?: VSXBadge[];
dependencies?: VSXExtensionReference[];
bundledExtensions?: VSXExtensionReference[];
allTargetPlatformVersions?: VSXTargetPlatforms[];
url?: string;
engines?: {
[engine: string]: string;
};
}
export interface VSXBadge {
url?: string;
href?: string;
description?: string;
}
export interface VSXExtensionReference {
url: string;
namespace: string;
extension: string;
}
export interface VSXTargetPlatforms {
version: string;
targetPlatforms: VSXTargetPlatform[];
}
export interface VSXResponseError extends Error {
statusCode: number;
}
export namespace VSXResponseError {
export function is(error: unknown): error is VSXResponseError {
return !!error && typeof error === 'object' && typeof (error as VSXResponseError).statusCode === 'number';
}
}
/**
* Builtin namespaces maintained by the framework.
*/
export namespace VSXBuiltinNamespaces {
/**
* Namespace for individual vscode builtin extensions.
*/
export const VSCODE = 'vscode';
/**
* Namespace for vscode builtin extension packs.
* - corresponds to: https://github.com/eclipse-theia/vscode-builtin-extensions/blob/af9cfeb2ea23e1668a8340c1c2fb5afd56be07d7/src/create-extension-pack.js#L45
*/
export const THEIA = 'eclipse-theia';
/**
* Determines if the extension namespace is a builtin maintained by the framework.
* @param namespace the extension namespace to verify.
*/
export function is(namespace: string): boolean {
return namespace === VSCODE
|| namespace === THEIA;
}
}
export type OVSXClientProvider = (uri: string) => MaybePromise<OVSXClient>;