Skip to content

Commit 3b5e9a4

Browse files
committed
more work on adding support with intersystems.servers
1 parent 9629548 commit 3b5e9a4

File tree

14 files changed

+231
-164
lines changed

14 files changed

+231
-164
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
@@ -447,12 +447,6 @@
447447
"description": "Server Access",
448448
"scope": "resource",
449449
"additionalProperties": false,
450-
"default": {
451-
"active": false,
452-
"host": "localhost",
453-
"port": 52773,
454-
"ns": "USER"
455-
},
456450
"required": [
457451
"active"
458452
],
@@ -487,8 +481,7 @@
487481
"type": "integer",
488482
"description": "TCP port number the web server listens on.",
489483
"minimum": 1,
490-
"maximum": 65535,
491-
"default": 52773
484+
"maximum": 65535
492485
},
493486
"ns": {
494487
"description": "Server Namespace",
@@ -497,13 +490,11 @@
497490
},
498491
"username": {
499492
"type": "string",
500-
"description": "Username to connect as. If not set here it must be provided when connecting.",
501-
"default": "_SYSTEM"
493+
"description": "Username to connect as. If not set here it must be provided when connecting."
502494
},
503495
"password": {
504496
"type": "string",
505-
"description": "Password of username. If not set here it must be provided when connecting.",
506-
"default": "SYS"
497+
"description": "Password of username. If not set here it must be provided when connecting."
507498
},
508499
"https": {
509500
"description": "Use SSL to access to API",
@@ -525,21 +516,19 @@
525516
},
526517
"internalPort": {
527518
"description": "Target port inside the service in docker-compose",
528-
"type": "number",
529-
"default": 52773
519+
"type": "number"
530520
},
531521
"file": {
532522
"description": "docker-compose file",
533-
"type": "string",
534-
"default": "docker-compose.yml"
523+
"type": "string"
535524
}
536525
}
537526
}
538527
}
539528
},
540529
"objectscript.export": {
541530
"type": "object",
542-
"description": "Export only the necessary stuff ",
531+
"description": "Export only the necessary stuff",
543532
"scope": "resource"
544533
},
545534
"objectscript.export.folder": {
@@ -752,8 +741,9 @@
752741
"webpack-dev": "webpack --mode development --watch",
753742
"package": "vsce package",
754743
"compile": "webpack --mode production && tsc -p ./",
744+
"test-compile": "webpack --mode development && tsc -p ./",
755745
"watch": "tsc -w -p ./tsconfig.json",
756-
"pretest": "npm run compile",
746+
"pretest": "npm run test-compile",
757747
"test": "node ./out/test/runTest.js",
758748
"lint": "eslint src/**",
759749
"lint-fix": "eslint --fix src/**",
@@ -782,6 +772,7 @@
782772
"extend": "^3.0.2",
783773
"minimist": ">=1.2.5",
784774
"mocha": "^8.0.1",
775+
"nock": "^13.0.0",
785776
"prettier": "^2.0.5",
786777
"tape": "^5.0.1",
787778
"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
public constructor(wsOrFile?: string | vscode.Uri) {
@@ -95,7 +105,7 @@ export class AtelierAPI {
95105
}
96106

97107
public xdebugUrl(): string {
98-
const { host, username, https, port, password, apiVersion } = this._config;
108+
const { host, username, https, port, password, apiVersion } = this.config;
99109
const proto = https ? "wss" : "ws";
100110
const auth = this.iris
101111
? `IRISUsername=${username}&IRISPassword=${password}`
@@ -119,8 +129,10 @@ export class AtelierAPI {
119129

120130
private setConnection(workspaceFolderName: string, namespace?: string): void {
121131
let serverName;
122-
if (config(`intersystems.servers.${workspaceFolderName}`)) {
123-
serverName = workspaceFolderName;
132+
this.configName = workspaceFolderName;
133+
if (config("intersystems.servers").has(workspaceFolderName.toLowerCase())) {
134+
this.externalServer = true;
135+
serverName = workspaceFolderName.toLowerCase();
124136
workspaceFolderName = currentWorkspaceFolder();
125137
}
126138
const conn = config("conn", workspaceFolderName);
@@ -130,12 +142,12 @@ export class AtelierAPI {
130142

131143
if (serverName && serverName.length) {
132144
const {
133-
webServer: { scheme, host, port, pathPrefix },
145+
webServer: { scheme, host, port, pathPrefix = "" },
134146
username,
135147
password,
136-
} = config(`intersystems.servers.${serverName}`, workspaceFolderName);
148+
} = config("intersystems.servers", workspaceFolderName).get(serverName);
137149
this._config = {
138-
active: conn.active,
150+
active: this.externalServer || conn.active,
139151
apiVersion: 1,
140152
https: scheme === "https",
141153
ns: namespace || conn.ns,
@@ -147,14 +159,12 @@ export class AtelierAPI {
147159
};
148160
} else {
149161
this._config = conn;
150-
this._config.port = workspaceState.get(workspaceFolderName + ":port", this._config.port);
151162
}
152-
this._config.password = workspaceState.get(workspaceFolderName + ":password", this._config.password);
153-
this._config.apiVersion = workspaceState.get(workspaceFolderName + ":apiVersion", DEFAULT_API_VERSION);
163+
}
154164

155-
this.workspaceFolder = workspaceFolderName;
156-
const { host, port } = this._config;
157-
this.cache = new Cache(extensionContext, `API:${host}:${port}`);
165+
private get cache(): Cache {
166+
const { host, port } = this.config;
167+
return new Cache(extensionContext, `API:${host}:${port}`);
158168
}
159169

160170
public async request(
@@ -168,18 +178,14 @@ export class AtelierAPI {
168178
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
169179
headers?: any
170180
): Promise<any> {
171-
const {
172-
active = false,
173-
apiVersion = 1,
174-
host = "localhost",
175-
port = 52773,
176-
username = "_SYSTEM",
177-
password = "SYS",
178-
https = false,
179-
} = this._config;
181+
const { active, apiVersion, host, port, username, password, https } = this.config;
180182
if (!active) {
181183
return Promise.reject();
182184
}
185+
if (!username || !username.length || !password || !password.length) {
186+
outputChannel.appendLine("username and password fields in settinds are mandatory");
187+
return Promise.reject();
188+
}
183189
if (minVersion > apiVersion) {
184190
return Promise.reject(`${path} not supported by API version ${apiVersion}`);
185191
}
@@ -254,7 +260,6 @@ export class AtelierAPI {
254260
.then((response) => this.updateCookies(response.headers["set-cookie"]).then(() => response))
255261
.then((response) => {
256262
panel.text = `${connInfo} - Connected`;
257-
// console.log(`APIResponse: ${method} ${proto}://${host}:${port}${path}`)
258263
if (method === "HEAD") {
259264
return this.cookies;
260265
}
@@ -292,7 +297,10 @@ export class AtelierAPI {
292297
}
293298
})
294299
.catch((error) => {
300+
console.log(error.error);
295301
if (error.error && error.error.code === "ECONNREFUSED") {
302+
workspaceState.update(this.configName + ":host", undefined);
303+
workspaceState.update(this.configName + ":port", undefined);
296304
setTimeout(checkConnection, 30000);
297305
}
298306
console.error(error);
@@ -315,8 +323,8 @@ export class AtelierAPI {
315323
};
316324
}
317325
return Promise.all([
318-
workspaceState.update(currentWorkspaceFolder() + ":apiVersion", apiVersion),
319-
workspaceState.update(currentWorkspaceFolder() + ":iris", data.version.startsWith("IRIS")),
326+
workspaceState.update(this.configName + ":apiVersion", apiVersion),
327+
workspaceState.update(this.configName + ":iris", data.version.startsWith("IRIS")),
320328
]).then(() => info);
321329
}
322330
});

0 commit comments

Comments
 (0)