Skip to content

Commit 3f12e64

Browse files
committed
feat: update Intellij d.ts Stubs and add Window.btoa/atob (#839)
1 parent 3174b19 commit 3f12e64

File tree

8 files changed

+57
-11
lines changed

8 files changed

+57
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Features
44
- logger supports call to parent logger (AnWeber/vscode-httpyac#347)
5+
- update Intellij d.ts Stubs and add Window.btoa/atob (#839)
56

67
### Fix
78
- ensure correct order if cli args are used (#773)

src/plugins/intellij/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './intellijHttpRequest';
44
export * from './intellijHttpResponse';
55
export * from './intellijRandom';
66
export * from './intellijVariables';
7+
export * from './intellijWindow';
78
export * from './stubs';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { CommonWindow } from './stubs';
2+
3+
export class IntellijWindow implements CommonWindow {
4+
btoa(bytes: string): string {
5+
return global.btoa(bytes);
6+
}
7+
8+
atob(bytes: string): string {
9+
return global.atob(bytes);
10+
}
11+
}

src/plugins/intellij/api/stubs/http-client.common.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ export interface Variables {
3636
/**
3737
* Saves variable with name 'varName' and sets its value to 'varValue'.
3838
*/
39-
set(varName: string, varValue: string): void;
39+
set(varName: string, varValue: unknown): void;
4040

4141
/**
4242
* Returns value of variable 'varName'.
4343
*/
44-
get(varName: string): string;
44+
get(varName: string): unknown;
4545

4646
/**
4747
* Checks no variables are defined.
@@ -84,6 +84,11 @@ export interface CommonHttpClientRequest {
8484
* Method of the current request
8585
*/
8686
method: string;
87+
88+
// currently not supported
89+
// iteration(): number;
90+
// currently not supported
91+
// templateValue(expressionNumber: number): string | boolean | number;
8792
}
8893

8994
/**
@@ -117,12 +122,12 @@ export interface RequestEnvironment {
117122
/**
118123
* Variables for constructing current request. Can be updated in Pre-request handler script.
119124
*/
120-
export interface RequestVariables {
125+
interface RequestVariables {
121126
/**
122127
* Retrieves request variable value by its name. Returns null if there is no such variable
123128
* @param name request variable name
124129
*/
125-
get(name: string): string | null;
130+
get(name: string): unknown;
126131
}
127132

128133
/**
@@ -134,6 +139,7 @@ export interface CommonRequestHeader {
134139
*/
135140
name: string;
136141
}
142+
137143
/**
138144
* Retrieves a value from a JSON object using a JSONPath expression.
139145
*
@@ -142,3 +148,19 @@ export interface CommonRequestHeader {
142148
* @return {any} - The value found in the JSON object using the JSONPath expression.
143149
*/
144150
export type jsonPath = (obj: unknown, expression: string) => unknown;
151+
152+
/**
153+
* Retrieves a value from a XML object using a XPath expression.
154+
*
155+
* @param {any} obj - The obj to search in with XPath expression:
156+
* - if obj is Node, Element or Document returns result of search with expression.
157+
* - null in all other cases.
158+
* @param {string} expression - The XPath expression to use for searching.
159+
* @return {any} - The value found in the XML object using the XPath expression.
160+
*/
161+
export type xpath = (obj: unknown, expression: string) => unknown;
162+
163+
export interface CommonWindow {
164+
atob(str: string): string;
165+
btoa(bytes: string): string;
166+
}

src/plugins/intellij/api/stubs/http-client.pre-request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export interface PreRequestRequestVariables {
1818
/**
1919
* Saves variable with name 'varName' and sets its value to 'varValue'.
2020
*/
21-
set(varName: string, varValue: string): void;
21+
set(varName: string, varValue: unknown): void;
2222

2323
/**
2424
* Returns value of variable 'varName'.
2525
*/
26-
get(varName: string): string | undefined;
26+
get(varName: string): unknown;
2727

2828
/**
2929
* Checks no variables are defined.

src/plugins/intellij/api/stubs/http-client.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import { CommonHttpClient, CommonHttpClientRequest, CommonRequestHeader } from './http-client.common';
77
import { PreRequestRequestHeader } from './http-client.pre-request';
8-
8+
import { Document } from '@xmldom/xmldom';
99
// declare const request: HttpClientFinalRequest;
1010

1111
export interface HttpClient extends CommonHttpClient {
@@ -34,7 +34,10 @@ export interface TextStreamResponse {
3434
* @param subscriber function to be called on each line of the stream
3535
* @param onFinish function to be called after the end of the stream
3636
*/
37-
onEachLine(subscriber: (line: string | object, unsubscribe: () => void) => void, onFinish?: () => void): void;
37+
onEachLine(
38+
subscriber: (line: string | Document | object, unsubscribe: () => void) => void,
39+
onFinish?: () => void
40+
): void;
3841

3942
/**
4043
* Subscribes user to each message sent by server. This method should be used with well-defined streaming protocols,
@@ -44,7 +47,11 @@ export interface TextStreamResponse {
4447
* @param onFinish function to be called after the end of the stream
4548
*/
4649
onEachMessage(
47-
subscriber: (message: string | object, unsubscribe: () => void, output?: (answer: string) => void) => void,
50+
subscriber: (
51+
message: string | Document | object,
52+
unsubscribe: () => void,
53+
output?: (answer: string) => void
54+
) => void,
4855
onFinish?: () => void
4956
): void;
5057
}
@@ -56,7 +63,7 @@ export interface HttpResponse {
5663
/**
5764
* Response content, it is a string or JSON object if response content-type is json.
5865
*/
59-
body: string | TextStreamResponse | unknown;
66+
body: string | TextStreamResponse | Document | object;
6067

6168
/**
6269
* Response headers storage.

src/plugins/intellij/api/stubs/http-declare.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { HttpClient, HttpClientRequest, HttpResponse } from './http-client';
2-
import { jsonPath } from './http-client.common';
2+
import { CommonWindow, jsonPath, xpath } from './http-client.common';
33
import { CryptoSupport } from './http-client.crypto';
44
import { PreRequestHttpClientRequest } from './http-client.pre-request';
55

@@ -8,6 +8,8 @@ export interface IntellijJavascriptGlobal extends Record<string, unknown> {
88
client: HttpClient;
99
crypto: CryptoSupport;
1010
jsonPath?: jsonPath; // not implemented
11+
xpath?: xpath; // not implemented
12+
Window: CommonWindow;
1113
$exampleServer?: string; // not implemented
1214
/**
1315
* The object holds information about HTTP Response.

src/plugins/intellij/intellijAction.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ function initIntellijVariables(context: models.ProcessorContext): intellij.Intel
111111
crypto: new intellij.IntellijCryptoSupport(),
112112
$random: new intellij.IntellijRandom(),
113113
$env: process.env,
114+
Window: new intellij.IntellijWindow(),
115+
xpath:
114116
};
115117
if (context.request) {
116118
if (context.httpRegion.response) {

0 commit comments

Comments
 (0)