@theia/ovsx-client 1.48.1 → 1.48.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +61 -61
  2. package/lib/index.d.ts +6 -6
  3. package/lib/index.js +30 -30
  4. package/lib/ovsx-api-filter.d.ts +30 -30
  5. package/lib/ovsx-api-filter.js +73 -73
  6. package/lib/ovsx-http-client.d.ts +17 -17
  7. package/lib/ovsx-http-client.js +82 -82
  8. package/lib/ovsx-mock-client.d.ts +43 -43
  9. package/lib/ovsx-mock-client.js +168 -168
  10. package/lib/ovsx-router-client.d.ts +68 -68
  11. package/lib/ovsx-router-client.js +169 -169
  12. package/lib/ovsx-router-client.spec-data.d.ts +10 -10
  13. package/lib/ovsx-router-client.spec-data.js +66 -66
  14. package/lib/ovsx-router-client.spec.d.ts +1 -1
  15. package/lib/ovsx-router-client.spec.js +107 -107
  16. package/lib/ovsx-router-filters/abstract-reg-exp-filter.d.ts +5 -5
  17. package/lib/ovsx-router-filters/abstract-reg-exp-filter.js +27 -27
  18. package/lib/ovsx-router-filters/extension-id-matches-filter.d.ts +7 -7
  19. package/lib/ovsx-router-filters/extension-id-matches-filter.js +33 -33
  20. package/lib/ovsx-router-filters/index.d.ts +2 -2
  21. package/lib/ovsx-router-filters/index.js +22 -22
  22. package/lib/ovsx-router-filters/request-contains-filter.d.ts +8 -8
  23. package/lib/ovsx-router-filters/request-contains-filter.js +35 -35
  24. package/lib/ovsx-types.d.ts +212 -212
  25. package/lib/ovsx-types.js +74 -74
  26. package/lib/types.d.ts +1 -1
  27. package/lib/types.js +17 -17
  28. package/package.json +3 -3
  29. package/src/index.ts +22 -22
  30. package/src/ovsx-api-filter.ts +91 -91
  31. package/src/ovsx-http-client.ts +85 -85
  32. package/src/ovsx-mock-client.ts +182 -182
  33. package/src/ovsx-router-client.spec-data.ts +68 -68
  34. package/src/ovsx-router-client.spec.ts +126 -126
  35. package/src/ovsx-router-client.ts +248 -248
  36. package/src/ovsx-router-filters/abstract-reg-exp-filter.ts +26 -26
  37. package/src/ovsx-router-filters/extension-id-matches-filter.ts +32 -32
  38. package/src/ovsx-router-filters/index.ts +18 -18
  39. package/src/ovsx-router-filters/request-contains-filter.ts +35 -35
  40. package/src/ovsx-types.ts +268 -268
  41. package/src/types.ts +17 -17
package/src/index.ts CHANGED
@@ -1,22 +1,22 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2021 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- export { OVSXApiFilter, OVSXApiFilterImpl } from './ovsx-api-filter';
18
- export { OVSXHttpClient } from './ovsx-http-client';
19
- export { OVSXMockClient } from './ovsx-mock-client';
20
- export { OVSXRouterClient, OVSXRouterConfig, OVSXRouterFilterFactory as FilterFactory } from './ovsx-router-client';
21
- export * from './ovsx-router-filters';
22
- export * from './ovsx-types';
1
+ // *****************************************************************************
2
+ // Copyright (C) 2021 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ export { OVSXApiFilter, OVSXApiFilterImpl } from './ovsx-api-filter';
18
+ export { OVSXHttpClient } from './ovsx-http-client';
19
+ export { OVSXMockClient } from './ovsx-mock-client';
20
+ export { OVSXRouterClient, OVSXRouterConfig, OVSXRouterFilterFactory as FilterFactory } from './ovsx-router-client';
21
+ export * from './ovsx-router-filters';
22
+ export * from './ovsx-types';
@@ -1,91 +1,91 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import * as semver from 'semver';
18
- import { VSXAllVersions, VSXBuiltinNamespaces, VSXExtensionRaw, VSXSearchEntry } from './ovsx-types';
19
-
20
- export const OVSXApiFilter = Symbol('OVSXApiFilter');
21
- /**
22
- * Filter various data types based on a pre-defined supported VS Code API version.
23
- */
24
- export interface OVSXApiFilter {
25
- supportedApiVersion: string;
26
- /**
27
- * Get the latest compatible extension version:
28
- * - A builtin extension is fetched based on the extension version which matches the API.
29
- * - An extension satisfies compatibility if its `engines.vscode` version is supported.
30
- *
31
- * @param extensionId the extension id.
32
- * @returns the data for the latest compatible extension version if available, else `undefined`.
33
- */
34
- getLatestCompatibleExtension(extensions: VSXExtensionRaw[]): VSXExtensionRaw | undefined;
35
- getLatestCompatibleVersion(searchEntry: VSXSearchEntry): VSXAllVersions | undefined;
36
- }
37
-
38
- export class OVSXApiFilterImpl implements OVSXApiFilter {
39
-
40
- constructor(
41
- public supportedApiVersion: string
42
- ) { }
43
-
44
- getLatestCompatibleExtension(extensions: VSXExtensionRaw[]): VSXExtensionRaw | undefined {
45
- if (extensions.length === 0) {
46
- return;
47
- } else if (this.isBuiltinNamespace(extensions[0].namespace.toLowerCase())) {
48
- return extensions.find(extension => this.versionGreaterThanOrEqualTo(extension.version, this.supportedApiVersion));
49
- } else {
50
- return extensions.find(extension => this.supportedVscodeApiSatisfies(extension.engines?.vscode ?? '*'));
51
- }
52
- }
53
-
54
- getLatestCompatibleVersion(searchEntry: VSXSearchEntry): VSXAllVersions | undefined {
55
- function getLatestCompatibleVersion(predicate: (allVersions: VSXAllVersions) => boolean): VSXAllVersions | undefined {
56
- if (searchEntry.allVersions) {
57
- return searchEntry.allVersions.find(predicate);
58
- }
59
- // If the allVersions field is missing then try to use the
60
- // searchEntry as VSXAllVersions and check if it's compatible:
61
- if (predicate(searchEntry)) {
62
- return searchEntry;
63
- }
64
- }
65
- if (this.isBuiltinNamespace(searchEntry.namespace)) {
66
- return getLatestCompatibleVersion(allVersions => this.versionGreaterThanOrEqualTo(allVersions.version, this.supportedApiVersion));
67
- } else {
68
- return getLatestCompatibleVersion(allVersions => this.supportedVscodeApiSatisfies(allVersions.engines?.vscode ?? '*'));
69
- }
70
- }
71
-
72
- protected isBuiltinNamespace(namespace: string): boolean {
73
- return VSXBuiltinNamespaces.is(namespace);
74
- }
75
-
76
- /**
77
- * @returns `a >= b`
78
- */
79
- protected versionGreaterThanOrEqualTo(a: string, b: string): boolean {
80
- const versionA = semver.clean(a);
81
- const versionB = semver.clean(b);
82
- if (!versionA || !versionB) {
83
- return false;
84
- }
85
- return semver.lte(versionA, versionB);
86
- }
87
-
88
- protected supportedVscodeApiSatisfies(vscodeApiRange: string): boolean {
89
- return semver.satisfies(this.supportedApiVersion, vscodeApiRange);
90
- }
91
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import * as semver from 'semver';
18
+ import { VSXAllVersions, VSXBuiltinNamespaces, VSXExtensionRaw, VSXSearchEntry } from './ovsx-types';
19
+
20
+ export const OVSXApiFilter = Symbol('OVSXApiFilter');
21
+ /**
22
+ * Filter various data types based on a pre-defined supported VS Code API version.
23
+ */
24
+ export interface OVSXApiFilter {
25
+ supportedApiVersion: string;
26
+ /**
27
+ * Get the latest compatible extension version:
28
+ * - A builtin extension is fetched based on the extension version which matches the API.
29
+ * - An extension satisfies compatibility if its `engines.vscode` version is supported.
30
+ *
31
+ * @param extensionId the extension id.
32
+ * @returns the data for the latest compatible extension version if available, else `undefined`.
33
+ */
34
+ getLatestCompatibleExtension(extensions: VSXExtensionRaw[]): VSXExtensionRaw | undefined;
35
+ getLatestCompatibleVersion(searchEntry: VSXSearchEntry): VSXAllVersions | undefined;
36
+ }
37
+
38
+ export class OVSXApiFilterImpl implements OVSXApiFilter {
39
+
40
+ constructor(
41
+ public supportedApiVersion: string
42
+ ) { }
43
+
44
+ getLatestCompatibleExtension(extensions: VSXExtensionRaw[]): VSXExtensionRaw | undefined {
45
+ if (extensions.length === 0) {
46
+ return;
47
+ } else if (this.isBuiltinNamespace(extensions[0].namespace.toLowerCase())) {
48
+ return extensions.find(extension => this.versionGreaterThanOrEqualTo(extension.version, this.supportedApiVersion));
49
+ } else {
50
+ return extensions.find(extension => this.supportedVscodeApiSatisfies(extension.engines?.vscode ?? '*'));
51
+ }
52
+ }
53
+
54
+ getLatestCompatibleVersion(searchEntry: VSXSearchEntry): VSXAllVersions | undefined {
55
+ function getLatestCompatibleVersion(predicate: (allVersions: VSXAllVersions) => boolean): VSXAllVersions | undefined {
56
+ if (searchEntry.allVersions) {
57
+ return searchEntry.allVersions.find(predicate);
58
+ }
59
+ // If the allVersions field is missing then try to use the
60
+ // searchEntry as VSXAllVersions and check if it's compatible:
61
+ if (predicate(searchEntry)) {
62
+ return searchEntry;
63
+ }
64
+ }
65
+ if (this.isBuiltinNamespace(searchEntry.namespace)) {
66
+ return getLatestCompatibleVersion(allVersions => this.versionGreaterThanOrEqualTo(allVersions.version, this.supportedApiVersion));
67
+ } else {
68
+ return getLatestCompatibleVersion(allVersions => this.supportedVscodeApiSatisfies(allVersions.engines?.vscode ?? '*'));
69
+ }
70
+ }
71
+
72
+ protected isBuiltinNamespace(namespace: string): boolean {
73
+ return VSXBuiltinNamespaces.is(namespace);
74
+ }
75
+
76
+ /**
77
+ * @returns `a >= b`
78
+ */
79
+ protected versionGreaterThanOrEqualTo(a: string, b: string): boolean {
80
+ const versionA = semver.clean(a);
81
+ const versionB = semver.clean(b);
82
+ if (!versionA || !versionB) {
83
+ return false;
84
+ }
85
+ return semver.lte(versionA, versionB);
86
+ }
87
+
88
+ protected supportedVscodeApiSatisfies(vscodeApiRange: string): boolean {
89
+ return semver.satisfies(this.supportedApiVersion, vscodeApiRange);
90
+ }
91
+ }
@@ -1,85 +1,85 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2023 Ericsson and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { OVSXClient, VSXQueryOptions, VSXQueryResult, VSXSearchOptions, VSXSearchResult } from './ovsx-types';
18
- import { RequestContext, RequestService } from '@theia/request';
19
-
20
- export class OVSXHttpClient implements OVSXClient {
21
-
22
- /**
23
- * @param requestService
24
- * @returns factory that will cache clients based on the requested input URL.
25
- */
26
- static createClientFactory(requestService: RequestService): (url: string) => OVSXClient {
27
- // eslint-disable-next-line no-null/no-null
28
- const cachedClients: Record<string, OVSXClient> = Object.create(null);
29
- return url => cachedClients[url] ??= new this(url, requestService);
30
- }
31
-
32
- constructor(
33
- protected vsxRegistryUrl: string,
34
- protected requestService: RequestService
35
- ) { }
36
-
37
- async search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
38
- try {
39
- return await this.requestJson(this.buildUrl('api/-/search', searchOptions));
40
- } catch (err) {
41
- return {
42
- error: err?.message || String(err),
43
- offset: -1,
44
- extensions: []
45
- };
46
- }
47
- }
48
-
49
- async query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
50
- try {
51
- return await this.requestJson(this.buildUrl('api/-/query', queryOptions));
52
- } catch (error) {
53
- console.warn(error);
54
- return {
55
- extensions: []
56
- };
57
- }
58
- }
59
-
60
- protected async requestJson<R>(url: string): Promise<R> {
61
- return RequestContext.asJson<R>(await this.requestService.request({
62
- url,
63
- headers: { 'Accept': 'application/json' }
64
- }));
65
- }
66
-
67
- protected buildUrl(url: string, query?: object): string {
68
- return new URL(`${url}${this.buildQueryString(query)}`, this.vsxRegistryUrl).toString();
69
- }
70
-
71
- protected buildQueryString(searchQuery?: object): string {
72
- if (!searchQuery) {
73
- return '';
74
- }
75
- let queryString = '';
76
- for (const [key, value] of Object.entries(searchQuery)) {
77
- if (typeof value === 'string') {
78
- queryString += `&${key}=${encodeURIComponent(value)}`;
79
- } else if (typeof value === 'boolean' || typeof value === 'number') {
80
- queryString += `&${key}=${value}`;
81
- }
82
- }
83
- return queryString && '?' + queryString.slice(1);
84
- }
85
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { OVSXClient, VSXQueryOptions, VSXQueryResult, VSXSearchOptions, VSXSearchResult } from './ovsx-types';
18
+ import { RequestContext, RequestService } from '@theia/request';
19
+
20
+ export class OVSXHttpClient implements OVSXClient {
21
+
22
+ /**
23
+ * @param requestService
24
+ * @returns factory that will cache clients based on the requested input URL.
25
+ */
26
+ static createClientFactory(requestService: RequestService): (url: string) => OVSXClient {
27
+ // eslint-disable-next-line no-null/no-null
28
+ const cachedClients: Record<string, OVSXClient> = Object.create(null);
29
+ return url => cachedClients[url] ??= new this(url, requestService);
30
+ }
31
+
32
+ constructor(
33
+ protected vsxRegistryUrl: string,
34
+ protected requestService: RequestService
35
+ ) { }
36
+
37
+ async search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
38
+ try {
39
+ return await this.requestJson(this.buildUrl('api/-/search', searchOptions));
40
+ } catch (err) {
41
+ return {
42
+ error: err?.message || String(err),
43
+ offset: -1,
44
+ extensions: []
45
+ };
46
+ }
47
+ }
48
+
49
+ async query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
50
+ try {
51
+ return await this.requestJson(this.buildUrl('api/-/query', queryOptions));
52
+ } catch (error) {
53
+ console.warn(error);
54
+ return {
55
+ extensions: []
56
+ };
57
+ }
58
+ }
59
+
60
+ protected async requestJson<R>(url: string): Promise<R> {
61
+ return RequestContext.asJson<R>(await this.requestService.request({
62
+ url,
63
+ headers: { 'Accept': 'application/json' }
64
+ }));
65
+ }
66
+
67
+ protected buildUrl(url: string, query?: object): string {
68
+ return new URL(`${url}${this.buildQueryString(query)}`, this.vsxRegistryUrl).toString();
69
+ }
70
+
71
+ protected buildQueryString(searchQuery?: object): string {
72
+ if (!searchQuery) {
73
+ return '';
74
+ }
75
+ let queryString = '';
76
+ for (const [key, value] of Object.entries(searchQuery)) {
77
+ if (typeof value === 'string') {
78
+ queryString += `&${key}=${encodeURIComponent(value)}`;
79
+ } else if (typeof value === 'boolean' || typeof value === 'number') {
80
+ queryString += `&${key}=${value}`;
81
+ }
82
+ }
83
+ return queryString && '?' + queryString.slice(1);
84
+ }
85
+ }