-
Notifications
You must be signed in to change notification settings - Fork 37
/
httpyacJsApi.ts
41 lines (36 loc) · 1.23 KB
/
httpyacJsApi.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as models from '../../models';
import * as utils from '../../utils';
export class HttpyacJsApi {
constructor(
private readonly context: models.ProcessorContext,
private readonly httpFileStore: models.HttpFileStore
) {}
findHttpRegionInContext(name: string) {
return utils.findHttpRegionInContext(name, this.context);
}
async import(fileName: string) {
return await utils.importHttpFileInContext(fileName, this.httpFileStore, this.context);
}
setVariables(vars: models.Variables) {
utils.setVariableInContext(vars, this.context);
}
async execute(httpRegion: models.HttpRegion | string, vars?: models.Variables): Promise<models.Variables> {
if (vars) {
utils.setVariableInContext(vars, this.context);
}
let obj: models.HttpRegion | undefined;
if (utils.isString(httpRegion)) {
obj = utils.findHttpRegionInContext(httpRegion, this.context);
} else {
obj = httpRegion;
}
if (obj) {
const result = await obj?.execute(this.context);
if (result) {
const envKey = utils.toEnvironmentKey(this.context.activeEnvironment);
utils.setVariableInContext(obj.variablesPerEnv[envKey], this.context);
}
}
return this.context.variables;
}
}