Skip to content

Commit 6e6f85a

Browse files
committed
more work on adding support with intersystems.servers
1 parent d884a99 commit 6e6f85a

File tree

14 files changed

+233
-168
lines changed

14 files changed

+233
-168
lines changed

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
"request": "launch",
4040
"runtimeExecutable": "${execPath}",
4141
"args": [
42+
"${workspaceFolder}/test-fixtures/test.code-workspace",
43+
"--disable-extensions",
4244
"--extensionDevelopmentPath=${workspaceFolder}",
4345
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
4446
],
4547
"outFiles": [
4648
"${workspaceFolder}/out/test/**/*.js"
4749
],
48-
"preLaunchTask": "npm: watch"
50+
"preLaunchTask": "npm: test-compile"
4951
}
5052
]
5153
}

package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -508,12 +508,6 @@
508508
"description": "Server Access",
509509
"scope": "resource",
510510
"additionalProperties": false,
511-
"default": {
512-
"active": false,
513-
"host": "localhost",
514-
"port": 52773,
515-
"ns": "USER"
516-
},
517511
"required": [
518512
"active"
519513
],
@@ -548,8 +542,7 @@
548542
"type": "integer",
549543
"description": "TCP port number the web server listens on.",
550544
"minimum": 1,
551-
"maximum": 65535,
552-
"default": 52773
545+
"maximum": 65535
553546
},
554547
"ns": {
555548
"description": "Server Namespace",
@@ -558,13 +551,11 @@
558551
},
559552
"username": {
560553
"type": "string",
561-
"description": "Username to connect as. If not set here it must be provided when connecting.",
562-
"default": "_SYSTEM"
554+
"description": "Username to connect as. If not set here it must be provided when connecting."
563555
},
564556
"password": {
565557
"type": "string",
566-
"description": "Password of username. If not set here it must be provided when connecting.",
567-
"default": "SYS"
558+
"description": "Password of username. If not set here it must be provided when connecting."
568559
},
569560
"https": {
570561
"description": "Use SSL to access to API",
@@ -586,21 +577,19 @@
586577
},
587578
"internalPort": {
588579
"description": "Target port inside the service in docker-compose",
589-
"type": "number",
590-
"default": 52773
580+
"type": "number"
591581
},
592582
"file": {
593583
"description": "docker-compose file",
594-
"type": "string",
595-
"default": "docker-compose.yml"
584+
"type": "string"
596585
}
597586
}
598587
}
599588
}
600589
},
601590
"objectscript.export": {
602591
"type": "object",
603-
"description": "Export only the necessary stuff ",
592+
"description": "Export only the necessary stuff",
604593
"scope": "resource"
605594
},
606595
"objectscript.export.folder": {
@@ -813,8 +802,9 @@
813802
"webpack-dev": "webpack --mode development --watch",
814803
"package": "vsce package",
815804
"compile": "webpack --mode production && tsc -p ./",
805+
"test-compile": "webpack --mode development && tsc -p ./",
816806
"watch": "tsc -w -p ./tsconfig.json",
817-
"pretest": "npm run compile",
807+
"pretest": "npm run test-compile",
818808
"test": "node ./out/test/runTest.js",
819809
"lint": "eslint src/**",
820810
"lint-fix": "eslint --fix src/**",
@@ -843,6 +833,7 @@
843833
"extend": "^3.0.2",
844834
"minimist": ">=1.2.5",
845835
"mocha": "^8.0.1",
836+
"nock": "^13.0.0",
846837
"prettier": "^2.0.5",
847838
"tape": "^5.0.1",
848839
"ts-loader": "^7.0.5",

src/api/index.ts

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,26 @@ export interface ConnectionSettings {
2626
export class AtelierAPI {
2727
private _config: ConnectionSettings;
2828
private namespace: string;
29-
private cache;
30-
private workspaceFolder;
29+
private configName: string;
30+
31+
// when FileSystemProvider used
32+
public externalServer = false;
3133

3234
public get ns(): string {
3335
return this.namespace || this._config.ns;
3436
}
3537

3638
public get config(): ConnectionSettings {
37-
const { active, apiVersion, https, host, port, pathPrefix, username, password } = this._config;
39+
const { active = false, https = false, pathPrefix = "", username } = this._config;
3840
const ns = this.namespace || this._config.ns;
41+
const host = this.externalServer
42+
? this._config.host
43+
: workspaceState.get(this.configName + ":host", this._config.host);
44+
const port = this.externalServer
45+
? this._config.port
46+
: workspaceState.get(this.configName + ":port", this._config.port);
47+
const password = workspaceState.get(this.configName + ":password", this._config.password);
48+
const apiVersion = workspaceState.get(this.configName + ":apiVersion", DEFAULT_API_VERSION);
3949
return {
4050
active,
4151
apiVersion,
@@ -50,7 +60,7 @@ export class AtelierAPI {
5060
}
5161

5262
private get iris(): boolean {
53-
return workspaceState.get(this.workspaceFolder + ":iris", false);
63+
return workspaceState.get(this.configName + ":iris", false);
5464
}
5565

5666
private transformNameIfCsp(filename: string): string {
@@ -105,7 +115,7 @@ export class AtelierAPI {
105115
}
106116

107117
public xdebugUrl(): string {
108-
const { host, username, https, port, password, apiVersion } = this._config;
118+
const { host, username, https, port, password, apiVersion } = this.config;
109119
const proto = https ? "wss" : "ws";
110120
const auth = this.iris
111121
? `IRISUsername=${username}&IRISPassword=${password}`
@@ -129,8 +139,10 @@ export class AtelierAPI {
129139

130140
private setConnection(workspaceFolderName: string, namespace?: string): void {
131141
let serverName;
132-
if (config(`intersystems.servers.${workspaceFolderName}`)) {
133-
serverName = workspaceFolderName;
142+
this.configName = workspaceFolderName;
143+
if (config("intersystems.servers").has(workspaceFolderName.toLowerCase())) {
144+
this.externalServer = true;
145+
serverName = workspaceFolderName.toLowerCase();
134146
workspaceFolderName = currentWorkspaceFolder();
135147
}
136148
const conn = config("conn", workspaceFolderName);
@@ -140,12 +152,12 @@ export class AtelierAPI {
140152

141153
if (serverName && serverName.length) {
142154
const {
143-
webServer: { scheme, host, port, pathPrefix },
155+
webServer: { scheme, host, port, pathPrefix = "" },
144156
username,
145157
password,
146-
} = config(`intersystems.servers.${serverName}`, workspaceFolderName);
158+
} = config("intersystems.servers", workspaceFolderName).get(serverName);
147159
this._config = {
148-
active: conn.active,
160+
active: this.externalServer || conn.active,
149161
apiVersion: 1,
150162
https: scheme === "https",
151163
ns: namespace || conn.ns,
@@ -157,14 +169,12 @@ export class AtelierAPI {
157169
};
158170
} else {
159171
this._config = conn;
160-
this._config.port = workspaceState.get(workspaceFolderName + ":port", this._config.port);
161172
}
162-
this._config.password = workspaceState.get(workspaceFolderName + ":password", this._config.password);
163-
this._config.apiVersion = workspaceState.get(workspaceFolderName + ":apiVersion", DEFAULT_API_VERSION);
173+
}
164174

165-
this.workspaceFolder = workspaceFolderName;
166-
const { host, port } = this._config;
167-
this.cache = new Cache(extensionContext, `API:${host}:${port}`);
175+
private get cache(): Cache {
176+
const { host, port } = this.config;
177+
return new Cache(extensionContext, `API:${host}:${port}`);
168178
}
169179

170180
public async request(
@@ -178,18 +188,14 @@ export class AtelierAPI {
178188
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
179189
headers?: any
180190
): Promise<any> {
181-
const {
182-
active = false,
183-
apiVersion = 1,
184-
host = "localhost",
185-
port = 52773,
186-
username = "_SYSTEM",
187-
password = "SYS",
188-
https = false,
189-
} = this._config;
191+
const { active, apiVersion, host, port, username, password, https } = this.config;
190192
if (!active) {
191193
return Promise.reject();
192194
}
195+
if (!username || !username.length || !password || !password.length) {
196+
outputChannel.appendLine("username and password fields in settinds are mandatory");
197+
return Promise.reject();
198+
}
193199
if (minVersion > apiVersion) {
194200
return Promise.reject(`${path} not supported by API version ${apiVersion}`);
195201
}
@@ -264,7 +270,6 @@ export class AtelierAPI {
264270
.then((response) => this.updateCookies(response.headers["set-cookie"]).then(() => response))
265271
.then((response) => {
266272
panel.text = `${connInfo} - Connected`;
267-
// console.log(`APIResponse: ${method} ${proto}://${host}:${port}${path}`)
268273
if (method === "HEAD") {
269274
return this.cookies;
270275
}
@@ -299,7 +304,10 @@ export class AtelierAPI {
299304
}
300305
})
301306
.catch((error) => {
307+
console.log(error.error);
302308
if (error.error && error.error.code === "ECONNREFUSED") {
309+
workspaceState.update(this.configName + ":host", undefined);
310+
workspaceState.update(this.configName + ":port", undefined);
303311
setTimeout(checkConnection, 30000);
304312
}
305313
console.error(error);
@@ -322,8 +330,8 @@ export class AtelierAPI {
322330
};
323331
}
324332
return Promise.all([
325-
workspaceState.update(currentWorkspaceFolder() + ":apiVersion", apiVersion),
326-
workspaceState.update(currentWorkspaceFolder() + ":iris", data.version.startsWith("IRIS")),
333+
workspaceState.update(this.configName + ":apiVersion", apiVersion),
334+
workspaceState.update(this.configName + ":iris", data.version.startsWith("IRIS")),
327335
]).then(() => info);
328336
}
329337
});

0 commit comments

Comments
 (0)