Skip to content

Commit 04e0897

Browse files
committed
satisfy tslint
1 parent 3a0a618 commit 04e0897

File tree

7 files changed

+396
-321
lines changed

7 files changed

+396
-321
lines changed

src/api/addServer.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import * as vscode from "vscode";
2-
import { JSONServerSpec } from "../extension";
2+
import { IJSONServerSpec } from "../extension";
33
import { getServerNames } from "./getServerNames";
44

55
export async function addServer(
6-
scope?: vscode.ConfigurationScope
6+
scope?: vscode.ConfigurationScope,
77
): Promise<string | undefined> {
88
const serverNames = getServerNames(scope);
9-
const spec: JSONServerSpec = { webServer: { scheme: "", host: "", port: 0 }};
9+
const spec: IJSONServerSpec = { webServer: { scheme: "", host: "", port: 0 }};
1010
return await vscode.window
1111
.showInputBox({
12+
ignoreFocusOut: true,
1213
placeHolder: "Name of new server definition",
1314
validateInput: (value) => {
1415
if (value === "") {
@@ -22,29 +23,29 @@ export async function addServer(
2223
}
2324
return null;
2425
},
25-
ignoreFocusOut: true
2626
})
2727
.then(
2828
async (name): Promise<string | undefined> => {
2929
if (name) {
3030
const description = await vscode.window.showInputBox({
31+
ignoreFocusOut: true,
3132
placeHolder: "Optional description",
32-
ignoreFocusOut: true
3333
});
34-
if (typeof description !== 'undefined') {
34+
if (typeof description !== "undefined") {
3535
if (description) {
3636
spec.description = description.trim();
3737
}
3838
const host = await vscode.window.showInputBox({
39+
ignoreFocusOut: true,
3940
placeHolder: "Hostname or IP address of web server",
4041
validateInput: (value) => {
4142
return value.trim().length ? undefined : "Required";
4243
},
43-
ignoreFocusOut: true
4444
});
4545
if (host) {
4646
spec.webServer.host = host.trim();
4747
const portString = await vscode.window.showInputBox({
48+
ignoreFocusOut: true,
4849
placeHolder: "Port of web server",
4950
validateInput: (value) => {
5051
const port = +value;
@@ -55,36 +56,35 @@ export async function addServer(
5556
? undefined
5657
: "Required, 1-65535";
5758
},
58-
ignoreFocusOut: true
5959
});
6060
if (portString) {
6161
spec.webServer.port = +portString;
6262
const username = await vscode.window.showInputBox({
63+
ignoreFocusOut: true,
6364
placeHolder:
6465
"Username",
6566
prompt:
6667
"Leave empty to be prompted when connecting.",
67-
ignoreFocusOut: true
6868
});
69-
if (typeof username !== 'undefined') {
69+
if (typeof username !== "undefined") {
7070
const usernameTrimmed = username.trim();
7171
if (usernameTrimmed !== "") {
7272
spec.username = usernameTrimmed;
7373
}
7474
const scheme = await vscode.window.showQuickPick(
7575
["http", "https"],
7676
{
77+
ignoreFocusOut: true,
7778
placeHolder:
7879
"Confirm connection type, then the definition will be stored in your User Settings. 'Escape' to cancel.",
79-
ignoreFocusOut: true
80-
}
80+
},
8181
);
8282
if (scheme) {
8383
spec.webServer.scheme = scheme;
8484
try {
8585
const config = vscode.workspace.getConfiguration(
8686
"intersystems",
87-
scope
87+
scope,
8888
);
8989
// For simplicity we always add to the user-level (aka Global) settings
9090
const servers: any =
@@ -95,7 +95,7 @@ export async function addServer(
9595
return name;
9696
} catch (error) {
9797
vscode.window.showErrorMessage(
98-
"Failed to store server '${name}' definition."
98+
"Failed to store server '${name}' definition.",
9999
);
100100
return undefined;
101101
}
@@ -105,6 +105,6 @@ export async function addServer(
105105
}
106106
}
107107
}
108-
}
108+
},
109109
);
110110
}

src/api/getPortalUriWithToken.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
1-
import * as vscode from 'vscode';
2-
import { Uri } from 'vscode';
3-
import { extensionId, ServerSpec } from '../extension';
4-
import { makeRESTRequest } from '../makeRESTRequest';
1+
import * as vscode from "vscode";
2+
import { Uri } from "vscode";
3+
import { extensionId, IServerSpec } from "../extension";
4+
import { makeRESTRequest } from "../makeRESTRequest";
55

66
export enum BrowserTarget {
77
SIMPLE = 0,
8-
EXTERNAL = 1
8+
EXTERNAL = 1,
99
}
1010

1111
const allTokens = [ new Map<string, string>(), new Map<string, string>()];
1212

13-
export async function getPortalUriWithToken(target: BrowserTarget, name: string, scope?: vscode.ConfigurationScope): Promise<Uri | undefined> {
13+
export async function getPortalUriWithToken(
14+
target: BrowserTarget,
15+
name: string,
16+
scope?: vscode.ConfigurationScope,
17+
): Promise<Uri | undefined> {
1418

15-
const PORTAL_HOME = '/csp/sys/UtilHome.csp';
19+
const PORTAL_HOME = "/csp/sys/UtilHome.csp";
1620

1721
// Use our own API so that the Recent folder updates with our activity
1822
const myApi = vscode.extensions.getExtension(extensionId)?.exports;
1923

20-
const spec: ServerSpec | undefined = await myApi.getServerSpec(name, scope);
21-
if (typeof spec !== 'undefined') {
24+
const spec: IServerSpec | undefined = await myApi.getServerSpec(name, scope);
25+
if (typeof spec !== "undefined") {
2226

2327
// Retrieve previously cached token
24-
let token = allTokens[target].get(name) || '';
28+
let token = allTokens[target].get(name) || "";
2529

2630
// Revalidate and extend existing token, or obtain a new one
27-
const response = await makeRESTRequest("POST", spec, { apiVersion: 1, namespace: '%SYS', path:'/action/query' }, { query: 'select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token', parameters: [PORTAL_HOME, token]});
31+
const response = await makeRESTRequest(
32+
"POST",
33+
spec,
34+
{ apiVersion: 1, namespace: "%SYS", path: "/action/query" },
35+
{ query: "select %Atelier_v1_Utils.General_GetCSPToken(?, ?) token", parameters: [PORTAL_HOME, token]},
36+
);
2837

2938
if (!response) {
3039
// User will have to enter credentials
31-
token = '';
40+
token = "";
3241
allTokens[target].delete(name);
33-
}
34-
else {
35-
token = response.data?.result?.content[0]?.token || '';
42+
} else {
43+
token = response.data?.result?.content[0]?.token || "";
3644
allTokens[target].set(name, token);
3745
}
3846

3947
const webServer = spec.webServer;
40-
let queryString = token ? `CSPCHD=${encodeURIComponent(token)}` : '';
48+
const queryString = token ? `CSPCHD=${encodeURIComponent(token)}` : "";
4149

4250
return vscode.Uri.parse(`${webServer.scheme}://${webServer.host}:${webServer.port}${webServer.pathPrefix}${PORTAL_HOME}?${queryString}`, true);
4351
}

src/api/getServerNames.ts

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
import * as vscode from 'vscode';
2-
import { ServerName } from '../extension';
3-
import { serverDetail } from './getServerSummary';
1+
import * as vscode from "vscode";
2+
import { IServerName } from "../extension";
3+
import { serverDetail } from "./getServerSummary";
44

5-
export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): ServerName[] {
6-
const allNames: ServerName[] = [];
7-
let names: ServerName[] = [];
8-
const embeddedNames: ServerName[] = [];
9-
const servers = vscode.workspace.getConfiguration('intersystems', scope).get('servers');
5+
export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boolean): IServerName[] {
6+
const allNames: IServerName[] = [];
7+
let names: IServerName[] = [];
8+
const embeddedNames: IServerName[] = [];
9+
const servers = vscode.workspace.getConfiguration("intersystems", scope).get("servers");
1010

11-
if (typeof servers === 'object' && servers) {
12-
11+
if (typeof servers === "object" && servers) {
1312
// Helper function to return true iff inspected setting is not explicitly set at any level
14-
const notSet = (inspected):boolean => {
15-
return !inspected?.globalLanguageValue && !inspected?.globalValue && !inspected?.workspaceFolderLanguageValue && !inspected?.workspaceFolderValue && !inspected?.workspaceLanguageValue && !inspected?.workspaceValue;
16-
}
17-
13+
const notSet = (inspected): boolean => {
14+
return !inspected?.globalLanguageValue
15+
&& !inspected?.globalValue
16+
&& !inspected?.workspaceFolderLanguageValue
17+
&& !inspected?.workspaceFolderValue
18+
&& !inspected?.workspaceLanguageValue
19+
&& !inspected?.workspaceValue;
20+
};
21+
1822
// If a valid default has been explicitly nominated, add it first
19-
const inspectedDefault = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect('/default');
20-
const myDefault: string = notSet(inspectedDefault) ? '' : servers['/default'] || '';
23+
const inspectedDefault = vscode.workspace.getConfiguration("intersystems.servers", scope).inspect("/default");
24+
const myDefault: string = notSet(inspectedDefault) ? "" : servers["/default"] || "";
2125
if (myDefault.length > 0 && servers[myDefault]) {
2226
allNames.push({
27+
description: `${servers[myDefault].description || ""} (default)`.trim(),
28+
detail: serverDetail(servers[myDefault]),
2329
name: myDefault,
24-
description: `${servers[myDefault].description || ''} (default)`.trim(),
25-
detail: serverDetail(servers[myDefault])
2630
});
2731
}
28-
32+
2933
// Process the rest
3034
for (const key in servers) {
31-
if (!key.startsWith('/') && key !== myDefault) {
32-
const inspected = vscode.workspace.getConfiguration('intersystems.servers', scope).inspect(key);
35+
if (!key.startsWith("/") && key !== myDefault) {
36+
const inspected = vscode.workspace.getConfiguration("intersystems.servers", scope).inspect(key);
3337

3438
// Collect embedded (default~*) servers separately
3539
if (notSet(inspected)) {
3640
embeddedNames.push({
41+
description: servers[key].description || "",
42+
detail: serverDetail(servers[key]),
3743
name: key,
38-
description: servers[key].description || '',
39-
detail: serverDetail(servers[key])
4044
});
4145
} else {
4246
names.push({
47+
description: servers[key].description || "",
48+
detail: serverDetail(servers[key]),
4349
name: key,
44-
description: servers[key].description || '',
45-
detail: serverDetail(servers[key])
4650
});
4751
}
4852
}
@@ -58,7 +62,7 @@ export function getServerNames(scope?: vscode.ConfigurationScope, sorted?: boole
5862
allNames.push(...names);
5963

6064
// Append the embedded servers unless suppressed
61-
if (!vscode.workspace.getConfiguration('intersystems.servers', scope).get('/hideEmbeddedEntries')) {
65+
if (!vscode.workspace.getConfiguration("intersystems.servers", scope).get("/hideEmbeddedEntries")) {
6266
allNames.push(...embeddedNames);
6367
}
6468
return allNames;

0 commit comments

Comments
 (0)