@theia/ovsx-client 1.48.0 → 1.48.1

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
@@ -1,182 +1,182 @@
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 { ExtensionLike, OVSXClient, VSXExtensionRaw, VSXQueryOptions, VSXQueryResult, VSXSearchOptions, VSXSearchResult } from './ovsx-types';
18
-
19
- /**
20
- * Querying will only find exact matches.
21
- * Searching will try to find the query string in various fields.
22
- */
23
- export class OVSXMockClient implements OVSXClient {
24
-
25
- constructor(
26
- public extensions: VSXExtensionRaw[] = []
27
- ) { }
28
-
29
- setExtensions(extensions: VSXExtensionRaw[]): this {
30
- this.extensions = extensions;
31
- return this;
32
- }
33
-
34
- /**
35
- * @param baseUrl required to construct the URLs required by {@link VSXExtensionRaw}.
36
- * @param ids list of ids to generate {@link VSXExtensionRaw} from.
37
- */
38
- setExtensionsFromIds(baseUrl: string, ids: string[]): this {
39
- const now = Date.now();
40
- const url = new OVSXMockClient.UrlBuilder(baseUrl);
41
- this.extensions = ids.map((extension, i) => {
42
- const [id, version = '0.0.1'] = extension.split('@', 2);
43
- const [namespace, name] = id.split('.', 2);
44
- return {
45
- allVersions: {
46
- [version]: url.extensionUrl(namespace, name, `/${version}`)
47
- },
48
- displayName: name,
49
- downloadCount: 0,
50
- files: {
51
- download: url.extensionFileUrl(namespace, name, version, `/${id}-${version}.vsix`)
52
- },
53
- name,
54
- namespace,
55
- namespaceAccess: 'public',
56
- namespaceUrl: url.namespaceUrl(namespace),
57
- publishedBy: {
58
- loginName: 'mock'
59
- },
60
- reviewCount: 0,
61
- reviewsUrl: url.extensionReviewsUrl(namespace, name),
62
- timestamp: new Date(now - ids.length + i + 1).toISOString(),
63
- version,
64
- description: `Mock VS Code Extension for ${id}`
65
- };
66
- });
67
- return this;
68
- }
69
-
70
- async query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
71
- return {
72
- extensions: this.extensions
73
- .filter(extension => typeof queryOptions === 'object' && (
74
- this.compare(queryOptions.extensionId, this.id(extension)) &&
75
- this.compare(queryOptions.extensionName, extension.name) &&
76
- this.compare(queryOptions.extensionVersion, extension.version) &&
77
- this.compare(queryOptions.namespaceName, extension.namespace)
78
- ))
79
- };
80
- }
81
-
82
- async search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
83
- const query = searchOptions?.query;
84
- const offset = searchOptions?.offset ?? 0;
85
- const size = searchOptions?.size ?? 18;
86
- const end = offset + size;
87
- return {
88
- offset,
89
- extensions: this.extensions
90
- .filter(extension => typeof query !== 'string' || (
91
- this.includes(query, this.id(extension)) ||
92
- this.includes(query, extension.description) ||
93
- this.includes(query, extension.displayName)
94
- ))
95
- .sort((a, b) => this.sort(a, b, searchOptions))
96
- .filter((extension, i) => i >= offset && i < end)
97
- .map(extension => ({
98
- downloadCount: extension.downloadCount,
99
- files: extension.files,
100
- name: extension.name,
101
- namespace: extension.namespace,
102
- timestamp: extension.timestamp,
103
- url: `${extension.namespaceUrl}/${extension.name}`,
104
- version: extension.version,
105
- }))
106
- };
107
- }
108
-
109
- protected id(extension: ExtensionLike): string {
110
- return `${extension.namespace}.${extension.name}`;
111
- }
112
-
113
- /**
114
- * Case sensitive.
115
- */
116
- protected compare(expected?: string, value?: string): boolean {
117
- return expected === undefined || value === undefined || expected === value;
118
- }
119
-
120
- /**
121
- * Case insensitive.
122
- */
123
- protected includes(needle: string, value?: string): boolean {
124
- return value === undefined || value.toLowerCase().includes(needle.toLowerCase());
125
- }
126
-
127
- protected sort(a: VSXExtensionRaw, b: VSXExtensionRaw, searchOptions?: VSXSearchOptions): number {
128
- let order: number = 0;
129
- const sortBy = searchOptions?.sortBy ?? 'relevance';
130
- const sortOrder = searchOptions?.sortOrder ?? 'desc';
131
- if (sortBy === 'averageRating') {
132
- order = (a.averageRating ?? -1) - (b.averageRating ?? -1);
133
- } else if (sortBy === 'downloadCount') {
134
- order = a.downloadCount - b.downloadCount;
135
- } else if (sortBy === 'relevance') {
136
- order = 0;
137
- } else if (sortBy === 'timestamp') {
138
- order = new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
139
- }
140
- if (sortOrder === 'asc') {
141
- order *= -1;
142
- }
143
- return order;
144
- }
145
- }
146
- export namespace OVSXMockClient {
147
-
148
- /**
149
- * URLs should respect the official OpenVSX API:
150
- * https://open-vsx.org/swagger-ui/index.html
151
- */
152
- export class UrlBuilder {
153
-
154
- constructor(
155
- protected baseUrl: string
156
- ) { }
157
-
158
- url(path: string): string {
159
- return this.baseUrl + path;
160
- }
161
-
162
- apiUrl(path: string): string {
163
- return this.url(`/api${path}`);
164
- }
165
-
166
- namespaceUrl(namespace: string, path = ''): string {
167
- return this.apiUrl(`/${namespace}${path}`);
168
- }
169
-
170
- extensionUrl(namespace: string, name: string, path = ''): string {
171
- return this.apiUrl(`/${namespace}/${name}${path}`);
172
- }
173
-
174
- extensionReviewsUrl(namespace: string, name: string): string {
175
- return this.apiUrl(`/${namespace}/${name}/reviews`);
176
- }
177
-
178
- extensionFileUrl(namespace: string, name: string, version: string, path = ''): string {
179
- return this.apiUrl(`/${namespace}/${name}/${version}/file${path}`);
180
- }
181
- }
182
- }
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 { ExtensionLike, OVSXClient, VSXExtensionRaw, VSXQueryOptions, VSXQueryResult, VSXSearchOptions, VSXSearchResult } from './ovsx-types';
18
+
19
+ /**
20
+ * Querying will only find exact matches.
21
+ * Searching will try to find the query string in various fields.
22
+ */
23
+ export class OVSXMockClient implements OVSXClient {
24
+
25
+ constructor(
26
+ public extensions: VSXExtensionRaw[] = []
27
+ ) { }
28
+
29
+ setExtensions(extensions: VSXExtensionRaw[]): this {
30
+ this.extensions = extensions;
31
+ return this;
32
+ }
33
+
34
+ /**
35
+ * @param baseUrl required to construct the URLs required by {@link VSXExtensionRaw}.
36
+ * @param ids list of ids to generate {@link VSXExtensionRaw} from.
37
+ */
38
+ setExtensionsFromIds(baseUrl: string, ids: string[]): this {
39
+ const now = Date.now();
40
+ const url = new OVSXMockClient.UrlBuilder(baseUrl);
41
+ this.extensions = ids.map((extension, i) => {
42
+ const [id, version = '0.0.1'] = extension.split('@', 2);
43
+ const [namespace, name] = id.split('.', 2);
44
+ return {
45
+ allVersions: {
46
+ [version]: url.extensionUrl(namespace, name, `/${version}`)
47
+ },
48
+ displayName: name,
49
+ downloadCount: 0,
50
+ files: {
51
+ download: url.extensionFileUrl(namespace, name, version, `/${id}-${version}.vsix`)
52
+ },
53
+ name,
54
+ namespace,
55
+ namespaceAccess: 'public',
56
+ namespaceUrl: url.namespaceUrl(namespace),
57
+ publishedBy: {
58
+ loginName: 'mock'
59
+ },
60
+ reviewCount: 0,
61
+ reviewsUrl: url.extensionReviewsUrl(namespace, name),
62
+ timestamp: new Date(now - ids.length + i + 1).toISOString(),
63
+ version,
64
+ description: `Mock VS Code Extension for ${id}`
65
+ };
66
+ });
67
+ return this;
68
+ }
69
+
70
+ async query(queryOptions?: VSXQueryOptions): Promise<VSXQueryResult> {
71
+ return {
72
+ extensions: this.extensions
73
+ .filter(extension => typeof queryOptions === 'object' && (
74
+ this.compare(queryOptions.extensionId, this.id(extension)) &&
75
+ this.compare(queryOptions.extensionName, extension.name) &&
76
+ this.compare(queryOptions.extensionVersion, extension.version) &&
77
+ this.compare(queryOptions.namespaceName, extension.namespace)
78
+ ))
79
+ };
80
+ }
81
+
82
+ async search(searchOptions?: VSXSearchOptions): Promise<VSXSearchResult> {
83
+ const query = searchOptions?.query;
84
+ const offset = searchOptions?.offset ?? 0;
85
+ const size = searchOptions?.size ?? 18;
86
+ const end = offset + size;
87
+ return {
88
+ offset,
89
+ extensions: this.extensions
90
+ .filter(extension => typeof query !== 'string' || (
91
+ this.includes(query, this.id(extension)) ||
92
+ this.includes(query, extension.description) ||
93
+ this.includes(query, extension.displayName)
94
+ ))
95
+ .sort((a, b) => this.sort(a, b, searchOptions))
96
+ .filter((extension, i) => i >= offset && i < end)
97
+ .map(extension => ({
98
+ downloadCount: extension.downloadCount,
99
+ files: extension.files,
100
+ name: extension.name,
101
+ namespace: extension.namespace,
102
+ timestamp: extension.timestamp,
103
+ url: `${extension.namespaceUrl}/${extension.name}`,
104
+ version: extension.version,
105
+ }))
106
+ };
107
+ }
108
+
109
+ protected id(extension: ExtensionLike): string {
110
+ return `${extension.namespace}.${extension.name}`;
111
+ }
112
+
113
+ /**
114
+ * Case sensitive.
115
+ */
116
+ protected compare(expected?: string, value?: string): boolean {
117
+ return expected === undefined || value === undefined || expected === value;
118
+ }
119
+
120
+ /**
121
+ * Case insensitive.
122
+ */
123
+ protected includes(needle: string, value?: string): boolean {
124
+ return value === undefined || value.toLowerCase().includes(needle.toLowerCase());
125
+ }
126
+
127
+ protected sort(a: VSXExtensionRaw, b: VSXExtensionRaw, searchOptions?: VSXSearchOptions): number {
128
+ let order: number = 0;
129
+ const sortBy = searchOptions?.sortBy ?? 'relevance';
130
+ const sortOrder = searchOptions?.sortOrder ?? 'desc';
131
+ if (sortBy === 'averageRating') {
132
+ order = (a.averageRating ?? -1) - (b.averageRating ?? -1);
133
+ } else if (sortBy === 'downloadCount') {
134
+ order = a.downloadCount - b.downloadCount;
135
+ } else if (sortBy === 'relevance') {
136
+ order = 0;
137
+ } else if (sortBy === 'timestamp') {
138
+ order = new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime();
139
+ }
140
+ if (sortOrder === 'asc') {
141
+ order *= -1;
142
+ }
143
+ return order;
144
+ }
145
+ }
146
+ export namespace OVSXMockClient {
147
+
148
+ /**
149
+ * URLs should respect the official OpenVSX API:
150
+ * https://open-vsx.org/swagger-ui/index.html
151
+ */
152
+ export class UrlBuilder {
153
+
154
+ constructor(
155
+ protected baseUrl: string
156
+ ) { }
157
+
158
+ url(path: string): string {
159
+ return this.baseUrl + path;
160
+ }
161
+
162
+ apiUrl(path: string): string {
163
+ return this.url(`/api${path}`);
164
+ }
165
+
166
+ namespaceUrl(namespace: string, path = ''): string {
167
+ return this.apiUrl(`/${namespace}${path}`);
168
+ }
169
+
170
+ extensionUrl(namespace: string, name: string, path = ''): string {
171
+ return this.apiUrl(`/${namespace}/${name}${path}`);
172
+ }
173
+
174
+ extensionReviewsUrl(namespace: string, name: string): string {
175
+ return this.apiUrl(`/${namespace}/${name}/reviews`);
176
+ }
177
+
178
+ extensionFileUrl(namespace: string, name: string, version: string, path = ''): string {
179
+ return this.apiUrl(`/${namespace}/${name}/${version}/file${path}`);
180
+ }
181
+ }
182
+ }
@@ -1,68 +1,68 @@
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
- /* eslint-disable no-null/no-null */
18
-
19
- import { OVSXMockClient } from './ovsx-mock-client';
20
- import { ExtensionIdMatchesFilterFactory, RequestContainsFilterFactory } from './ovsx-router-filters';
21
- import { OVSXClient } from './ovsx-types';
22
-
23
- export const registries = {
24
- internal: 'https://internal.testdomain/',
25
- public: 'https://public.testdomain/',
26
- third: 'https://third.testdomain/'
27
- };
28
-
29
- export const clients: Record<string, OVSXMockClient> = {
30
- [registries.internal]: new OVSXMockClient().setExtensionsFromIds(registries.internal, [
31
- 'some.a@1.0.0',
32
- 'other.d',
33
- 'secret.x',
34
- 'secret.y',
35
- 'secret.z',
36
- ...Array(50)
37
- .fill(undefined)
38
- .map((element, i) => `internal.autogen${i}`)
39
- ]),
40
- [registries.public]: new OVSXMockClient().setExtensionsFromIds(registries.public, [
41
- 'some.a@2.0.0',
42
- 'some.b',
43
- 'other.e',
44
- 'testFullStop.c',
45
- 'secret.w',
46
- ...Array(50)
47
- .fill(undefined)
48
- .map((element, i) => `public.autogen${i}`)
49
- ]),
50
- [registries.third]: new OVSXMockClient().setExtensionsFromIds(registries.third, [
51
- ...Array(200)
52
- .fill(undefined)
53
- .map((element, i) => `third.autogen${i}`)
54
- ])
55
- };
56
-
57
- export const filterFactories = [
58
- RequestContainsFilterFactory,
59
- ExtensionIdMatchesFilterFactory
60
- ];
61
-
62
- export function testClientProvider(uri: string): OVSXClient {
63
- const client = clients[uri];
64
- if (!client) {
65
- throw new Error(`unknown client for URI=${uri}`);
66
- }
67
- return client;
68
- };
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
+ /* eslint-disable no-null/no-null */
18
+
19
+ import { OVSXMockClient } from './ovsx-mock-client';
20
+ import { ExtensionIdMatchesFilterFactory, RequestContainsFilterFactory } from './ovsx-router-filters';
21
+ import { OVSXClient } from './ovsx-types';
22
+
23
+ export const registries = {
24
+ internal: 'https://internal.testdomain/',
25
+ public: 'https://public.testdomain/',
26
+ third: 'https://third.testdomain/'
27
+ };
28
+
29
+ export const clients: Record<string, OVSXMockClient> = {
30
+ [registries.internal]: new OVSXMockClient().setExtensionsFromIds(registries.internal, [
31
+ 'some.a@1.0.0',
32
+ 'other.d',
33
+ 'secret.x',
34
+ 'secret.y',
35
+ 'secret.z',
36
+ ...Array(50)
37
+ .fill(undefined)
38
+ .map((element, i) => `internal.autogen${i}`)
39
+ ]),
40
+ [registries.public]: new OVSXMockClient().setExtensionsFromIds(registries.public, [
41
+ 'some.a@2.0.0',
42
+ 'some.b',
43
+ 'other.e',
44
+ 'testFullStop.c',
45
+ 'secret.w',
46
+ ...Array(50)
47
+ .fill(undefined)
48
+ .map((element, i) => `public.autogen${i}`)
49
+ ]),
50
+ [registries.third]: new OVSXMockClient().setExtensionsFromIds(registries.third, [
51
+ ...Array(200)
52
+ .fill(undefined)
53
+ .map((element, i) => `third.autogen${i}`)
54
+ ])
55
+ };
56
+
57
+ export const filterFactories = [
58
+ RequestContainsFilterFactory,
59
+ ExtensionIdMatchesFilterFactory
60
+ ];
61
+
62
+ export function testClientProvider(uri: string): OVSXClient {
63
+ const client = clients[uri];
64
+ if (!client) {
65
+ throw new Error(`unknown client for URI=${uri}`);
66
+ }
67
+ return client;
68
+ };