Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ovsx-client: Use get for querying extension data #10325

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use get for querying extension data from ovsx
  • Loading branch information
msujew committed Oct 26, 2021
commit dbe180f1f0be61dcc33ea3956cc5c430c69f276d
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@
- renamed `createMenuBar` to `createElectronMenuBar`
- [core] moved `DEFAULT_WINDOW_HASH` to `common/window.ts` [#10291](https://github.com/eclipse-theia/theia/pull/10291)
- [core] moved `NewWindowOptions` to `common/window.ts` [#10291](https://github.com/eclipse-theia/theia/pull/10291)
- [ovsx-client] removed `fetchJson` method from `OVSXClient` [#10325](https://github.com/eclipse-theia/theia/pull/10325)

## v1.18.0 - 9/30/2021

52 changes: 19 additions & 33 deletions dev-packages/ovsx-client/src/ovsx-client.ts
Original file line number Diff line number Diff line change
@@ -29,10 +29,6 @@ import {

const fetchText = bent('GET', 'string', 200);
const fetchJson = bent('GET', { 'Accept': 'application/json' }, 'json', 200);
const postJson = bent('POST', {
'Content-Type': 'application/json',
'Accept': 'application/json'
}, 'json', 200);

export interface OVSXClientOptions {
apiVersion: string
@@ -48,43 +44,37 @@ export class OVSXClient {
}

protected async buildSearchUri(param?: VSXSearchParam): Promise<string> {
return this.buildUri('api/-/search', param);
}

protected buildQueryUri(param?: VSXQueryParam): string {
return this.buildUri('api/-/query', param);
}

protected buildUri(url: string, param?: Object): string {
let searchUri = '';
if (param) {
const query: string[] = [];
if (param.query) {
query.push('query=' + encodeURIComponent(param.query));
}
if (param.category) {
query.push('category=' + encodeURIComponent(param.category));
}
if (param.size) {
query.push('size=' + param.size);
}
if (param.offset) {
query.push('offset=' + param.offset);
}
if (param.sortOrder) {
query.push('sortOrder=' + encodeURIComponent(param.sortOrder));
}
if (param.sortBy) {
query.push('sortBy=' + encodeURIComponent(param.sortBy));
}
if (param.includeAllVersions) {
query.push('includeAllVersions=' + param.includeAllVersions);
for (const [key, value] of Object.entries(param)) {
if (typeof value === 'string') {
query.push(`${key}=${encodeURIComponent(value)}`);
} else if (typeof value === 'boolean' || typeof value === 'number') {
query.push(`${key}=${String(value)}`);
}
}
if (query.length > 0) {
searchUri += '?' + query.join('&');
}
}
return new URL(`api/-/search${searchUri}`, this.options!.apiUrl).toString();
return new URL(`${url}${searchUri}`, this.options!.apiUrl).toString();
}

async getExtension(id: string): Promise<VSXExtensionRaw> {
const apiUri = new URL('api/-/query', this.options!.apiUrl);
const param: VSXQueryParam = {
extensionId: id
};
const result = await this.postJson<VSXQueryParam, VSXQueryResult>(apiUri.toString(), param);
const apiUri = this.buildQueryUri(param);
const result = await this.fetchJson<VSXQueryResult>(apiUri);
if (result.extensions && result.extensions.length > 0) {
return result.extensions[0];
}
@@ -96,12 +86,12 @@ export class OVSXClient {
* @param id the requested extension id.
*/
async getAllVersions(id: string): Promise<VSXExtensionRaw[]> {
const apiUri = new URL('api/-/query', this.options!.apiUrl);
const param: VSXQueryParam = {
extensionId: id,
includeAllVersions: true,
};
const result = await this.postJson<VSXQueryParam, VSXQueryResult>(apiUri.toString(), param);
const apiUri = this.buildQueryUri(param);
const result = await this.fetchJson<VSXQueryResult>(apiUri);
if (result.extensions && result.extensions.length > 0) {
return result.extensions;
}
@@ -112,10 +102,6 @@ export class OVSXClient {
return fetchJson(url) as Promise<R>;
}

protected postJson<P, R>(url: string, payload: P): Promise<R> {
return postJson(url, JSON.stringify(payload)) as Promise<R>;
}

fetchText(url: string): Promise<string> {
return fetchText(url);
}