@nomicfoundation/hardhat-utils 3.0.0-next.12 → 3.0.0-next.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/request.d.ts +16 -6
- package/dist/src/request.d.ts.map +1 -1
- package/dist/src/request.js +12 -4
- package/dist/src/request.js.map +1 -1
- package/package.json +2 -2
- package/src/request.ts +24 -8
package/dist/src/request.d.ts
CHANGED
|
@@ -35,18 +35,26 @@ export interface RequestOptions {
|
|
|
35
35
|
extraHeaders?: Record<string, string>;
|
|
36
36
|
abortSignal?: AbortSignal | EventEmitter;
|
|
37
37
|
}
|
|
38
|
+
export interface HttpResponse {
|
|
39
|
+
statusCode: number;
|
|
40
|
+
body: {
|
|
41
|
+
json(): Promise<unknown>;
|
|
42
|
+
text(): Promise<string>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
38
45
|
/**
|
|
39
46
|
* Performs a HTTP request.
|
|
40
47
|
*
|
|
41
48
|
* @param url The url to make the request to.
|
|
42
49
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
43
50
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
44
|
-
* @returns
|
|
51
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
52
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
45
53
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
46
54
|
* @throws RequestTimeoutError If the request times out.
|
|
47
55
|
* @throws RequestError If the request fails for any other reason.
|
|
48
56
|
*/
|
|
49
|
-
export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
57
|
+
export declare function getRequest(url: string, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
50
58
|
/**
|
|
51
59
|
* Performs a POST request with a JSON body.
|
|
52
60
|
*
|
|
@@ -54,12 +62,13 @@ export declare function getRequest(url: string, requestOptions?: RequestOptions,
|
|
|
54
62
|
* @param body The body of the request, represented as an object.
|
|
55
63
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
56
64
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
57
|
-
* @returns
|
|
65
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
66
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
58
67
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
59
68
|
* @throws RequestTimeoutError If the request times out.
|
|
60
69
|
* @throws RequestError If the request fails for any other reason.
|
|
61
70
|
*/
|
|
62
|
-
export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
71
|
+
export declare function postJsonRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
63
72
|
/**
|
|
64
73
|
* Performs a POST request with a form body.
|
|
65
74
|
*
|
|
@@ -67,12 +76,13 @@ export declare function postJsonRequest(url: string, body: unknown, requestOptio
|
|
|
67
76
|
* @param body The body of the request, represented as an object.
|
|
68
77
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
69
78
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
70
|
-
* @returns
|
|
79
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
80
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
71
81
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
72
82
|
* @throws RequestTimeoutError If the request times out.
|
|
73
83
|
* @throws RequestError If the request fails for any other reason.
|
|
74
84
|
*/
|
|
75
|
-
export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<
|
|
85
|
+
export declare function postFormRequest(url: string, body: unknown, requestOptions?: RequestOptions, dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions): Promise<HttpResponse>;
|
|
76
86
|
/**
|
|
77
87
|
* Downloads a file from a url to a destination path.
|
|
78
88
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAE5C,OAAO,KAAK,OAAO,MAAM,QAAQ,CAAC;AAuBlC,eAAO,MAAM,+BAA+B,SAAU,CAAC;AACvD,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,kBAAkB,YAAY,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;AAC5C,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC;AAC/C,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,WAAW,iBAAiB;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,WAAW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AED,OAAO,EACL,sBAAsB,EACtB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/dist/src/request.js
CHANGED
|
@@ -15,7 +15,8 @@ export const DEFAULT_USER_AGENT = "Hardhat";
|
|
|
15
15
|
* @param url The url to make the request to.
|
|
16
16
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
17
17
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
18
|
-
* @returns
|
|
18
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
19
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
19
20
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
20
21
|
* @throws RequestTimeoutError If the request times out.
|
|
21
22
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -42,7 +43,8 @@ export async function getRequest(url, requestOptions = {}, dispatcherOrDispatche
|
|
|
42
43
|
* @param body The body of the request, represented as an object.
|
|
43
44
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
44
45
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
45
|
-
* @returns
|
|
46
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
47
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
46
48
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
47
49
|
* @throws RequestTimeoutError If the request times out.
|
|
48
50
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -74,7 +76,8 @@ export async function postJsonRequest(url, body, requestOptions = {}, dispatcher
|
|
|
74
76
|
* @param body The body of the request, represented as an object.
|
|
75
77
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
76
78
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
77
|
-
* @returns
|
|
79
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
80
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
78
81
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
79
82
|
* @throws RequestTimeoutError If the request times out.
|
|
80
83
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -114,7 +117,12 @@ export async function postFormRequest(url, body, requestOptions = {}, dispatcher
|
|
|
114
117
|
export async function download(url, destination, requestOptions = {}, dispatcherOrDispatcherOptions) {
|
|
115
118
|
let statusCode;
|
|
116
119
|
try {
|
|
117
|
-
|
|
120
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
121
|
+
-- We need the full Dispatcher.ResponseData here for stream.pipeline,
|
|
122
|
+
but HttpResponse doesn’t expose the raw ReadableStream.
|
|
123
|
+
TODO: wrap undici's request so we can keep the public API
|
|
124
|
+
strictly typed without falling back to Undici types. */
|
|
125
|
+
const response = (await getRequest(url, requestOptions, dispatcherOrDispatcherOptions));
|
|
118
126
|
const { body } = response;
|
|
119
127
|
statusCode = response.statusCode;
|
|
120
128
|
if (statusCode < 200 || statusCode >= 300) {
|
package/dist/src/request.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.js","sourceRoot":"","sources":["../../src/request.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAC3C,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,YAAY,EACZ,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,EACxB,qBAAqB,EACrB,kBAAk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Ae,EACf,aAAa,EACb,YAAY,EACZ,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nomicfoundation/hardhat-utils",
|
|
3
|
-
"version": "3.0.0-next.
|
|
3
|
+
"version": "3.0.0-next.14",
|
|
4
4
|
"description": "Utilities for Hardhat and its plugins",
|
|
5
5
|
"homepage": "https://github.com/nomicfoundation/hardhat/tree/v-next/v-next/hardhat-utils",
|
|
6
6
|
"repository": {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"README.md"
|
|
49
49
|
],
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0-next.
|
|
51
|
+
"@nomicfoundation/hardhat-node-test-reporter": "^3.0.0-next.14",
|
|
52
52
|
"@types/bn.js": "^5.1.5",
|
|
53
53
|
"@types/debug": "^4.1.7",
|
|
54
54
|
"@types/node": "^20.14.9",
|
package/src/request.ts
CHANGED
|
@@ -62,13 +62,22 @@ export interface RequestOptions {
|
|
|
62
62
|
abortSignal?: AbortSignal | EventEmitter;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
export interface HttpResponse {
|
|
66
|
+
statusCode: number;
|
|
67
|
+
body: {
|
|
68
|
+
json(): Promise<unknown>;
|
|
69
|
+
text(): Promise<string>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
65
73
|
/**
|
|
66
74
|
* Performs a HTTP request.
|
|
67
75
|
*
|
|
68
76
|
* @param url The url to make the request to.
|
|
69
77
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
70
78
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
71
|
-
* @returns
|
|
79
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
80
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
72
81
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
73
82
|
* @throws RequestTimeoutError If the request times out.
|
|
74
83
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -77,7 +86,7 @@ export async function getRequest(
|
|
|
77
86
|
url: string,
|
|
78
87
|
requestOptions: RequestOptions = {},
|
|
79
88
|
dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions,
|
|
80
|
-
): Promise<
|
|
89
|
+
): Promise<HttpResponse> {
|
|
81
90
|
const { request } = await import("undici");
|
|
82
91
|
|
|
83
92
|
try {
|
|
@@ -106,7 +115,8 @@ export async function getRequest(
|
|
|
106
115
|
* @param body The body of the request, represented as an object.
|
|
107
116
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
108
117
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
109
|
-
* @returns
|
|
118
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
119
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
110
120
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
111
121
|
* @throws RequestTimeoutError If the request times out.
|
|
112
122
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -116,7 +126,7 @@ export async function postJsonRequest(
|
|
|
116
126
|
body: unknown,
|
|
117
127
|
requestOptions: RequestOptions = {},
|
|
118
128
|
dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions,
|
|
119
|
-
): Promise<
|
|
129
|
+
): Promise<HttpResponse> {
|
|
120
130
|
const { request } = await import("undici");
|
|
121
131
|
|
|
122
132
|
try {
|
|
@@ -150,7 +160,8 @@ export async function postJsonRequest(
|
|
|
150
160
|
* @param body The body of the request, represented as an object.
|
|
151
161
|
* @param requestOptions The options to configure the request. See {@link RequestOptions}.
|
|
152
162
|
* @param dispatcherOrDispatcherOptions Either a dispatcher or dispatcher options. See {@link DispatcherOptions}.
|
|
153
|
-
* @returns
|
|
163
|
+
* @returns An object containing the status code and the response body. The body can be accessed as JSON or text.
|
|
164
|
+
* `body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
|
|
154
165
|
* @throws ConnectionRefusedError If the connection is refused by the server.
|
|
155
166
|
* @throws RequestTimeoutError If the request times out.
|
|
156
167
|
* @throws RequestError If the request fails for any other reason.
|
|
@@ -160,7 +171,7 @@ export async function postFormRequest(
|
|
|
160
171
|
body: unknown,
|
|
161
172
|
requestOptions: RequestOptions = {},
|
|
162
173
|
dispatcherOrDispatcherOptions?: UndiciT.Dispatcher | DispatcherOptions,
|
|
163
|
-
): Promise<
|
|
174
|
+
): Promise<HttpResponse> {
|
|
164
175
|
const { request } = await import("undici");
|
|
165
176
|
|
|
166
177
|
try {
|
|
@@ -208,11 +219,16 @@ export async function download(
|
|
|
208
219
|
let statusCode: number | undefined;
|
|
209
220
|
|
|
210
221
|
try {
|
|
211
|
-
|
|
222
|
+
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
223
|
+
-- We need the full Dispatcher.ResponseData here for stream.pipeline,
|
|
224
|
+
but HttpResponse doesn’t expose the raw ReadableStream.
|
|
225
|
+
TODO: wrap undici's request so we can keep the public API
|
|
226
|
+
strictly typed without falling back to Undici types. */
|
|
227
|
+
const response = (await getRequest(
|
|
212
228
|
url,
|
|
213
229
|
requestOptions,
|
|
214
230
|
dispatcherOrDispatcherOptions,
|
|
215
|
-
);
|
|
231
|
+
)) as UndiciT.Dispatcher.ResponseData;
|
|
216
232
|
const { body } = response;
|
|
217
233
|
statusCode = response.statusCode;
|
|
218
234
|
|