@jayfong/x-request 2.12.18 → 2.12.19
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/lib/_cjs/index.js +22 -22
- package/lib/index.d.ts +24 -24
- package/lib/index.js +22 -22
- package/package.json +1 -1
package/lib/_cjs/index.js
CHANGED
|
@@ -116,7 +116,7 @@ class XRequest {
|
|
|
116
116
|
}
|
|
117
117
|
return gotOptions;
|
|
118
118
|
}
|
|
119
|
-
static
|
|
119
|
+
static get(options, responseType) {
|
|
120
120
|
let url = options.url;
|
|
121
121
|
if (options.data) {
|
|
122
122
|
const _url = new URL(url);
|
|
@@ -139,7 +139,7 @@ class XRequest {
|
|
|
139
139
|
data: res.body
|
|
140
140
|
}));
|
|
141
141
|
}
|
|
142
|
-
static
|
|
142
|
+
static post(options, responseType) {
|
|
143
143
|
const gotOptions = this.getGotOptions(options, responseType || 'buffer');
|
|
144
144
|
if (responseType === 'stream' && options.data instanceof _formstream.default) {
|
|
145
145
|
gotOptions.headers = options.data.headers(gotOptions.headers);
|
|
@@ -170,22 +170,22 @@ class XRequest {
|
|
|
170
170
|
}));
|
|
171
171
|
}
|
|
172
172
|
static async getText(options) {
|
|
173
|
-
return this.
|
|
173
|
+
return this.get(options, 'text');
|
|
174
174
|
}
|
|
175
175
|
static async postText(options) {
|
|
176
|
-
return this.
|
|
176
|
+
return this.post(options, 'text');
|
|
177
177
|
}
|
|
178
|
-
static async
|
|
179
|
-
return this.
|
|
178
|
+
static async getJson(options) {
|
|
179
|
+
return this.get(options, 'json');
|
|
180
180
|
}
|
|
181
|
-
static async
|
|
182
|
-
return this.
|
|
181
|
+
static async postJson(options) {
|
|
182
|
+
return this.post(options, 'json');
|
|
183
183
|
}
|
|
184
184
|
static getStream(options) {
|
|
185
|
-
return this.
|
|
185
|
+
return this.get(options, 'stream');
|
|
186
186
|
}
|
|
187
187
|
static postStream(options) {
|
|
188
|
-
return this.
|
|
188
|
+
return this.post(options, 'stream');
|
|
189
189
|
}
|
|
190
190
|
static isTimeoutError(err) {
|
|
191
191
|
return err instanceof _got.default.TimeoutError;
|
|
@@ -193,9 +193,9 @@ class XRequest {
|
|
|
193
193
|
constructor(options) {
|
|
194
194
|
this.options = options;
|
|
195
195
|
}
|
|
196
|
-
|
|
196
|
+
get(options, responseType) {
|
|
197
197
|
var _this$options;
|
|
198
|
-
return XRequest.
|
|
198
|
+
return XRequest.get({
|
|
199
199
|
...this.options,
|
|
200
200
|
...options,
|
|
201
201
|
headers: {
|
|
@@ -204,9 +204,9 @@ class XRequest {
|
|
|
204
204
|
}
|
|
205
205
|
}, responseType);
|
|
206
206
|
}
|
|
207
|
-
|
|
207
|
+
post(options, responseType) {
|
|
208
208
|
var _this$options2;
|
|
209
|
-
return XRequest.
|
|
209
|
+
return XRequest.post({
|
|
210
210
|
...this.options,
|
|
211
211
|
...options,
|
|
212
212
|
headers: {
|
|
@@ -216,22 +216,22 @@ class XRequest {
|
|
|
216
216
|
}, responseType);
|
|
217
217
|
}
|
|
218
218
|
async getText(options) {
|
|
219
|
-
return this.
|
|
219
|
+
return this.get(options, 'text');
|
|
220
220
|
}
|
|
221
221
|
async postText(options) {
|
|
222
|
-
return this.
|
|
222
|
+
return this.post(options, 'text');
|
|
223
223
|
}
|
|
224
|
-
async
|
|
225
|
-
return this.
|
|
224
|
+
async getJson(options) {
|
|
225
|
+
return this.get(options, 'json');
|
|
226
226
|
}
|
|
227
|
-
async
|
|
228
|
-
return this.
|
|
227
|
+
async postJson(options) {
|
|
228
|
+
return this.post(options, 'json');
|
|
229
229
|
}
|
|
230
230
|
getStream(options) {
|
|
231
|
-
return this.
|
|
231
|
+
return this.get(options, 'stream');
|
|
232
232
|
}
|
|
233
233
|
postStream(options) {
|
|
234
|
-
return this.
|
|
234
|
+
return this.post(options, 'stream');
|
|
235
235
|
}
|
|
236
236
|
isTimeoutError(err) {
|
|
237
237
|
return XRequest.isTimeoutError(err);
|
package/lib/index.d.ts
CHANGED
|
@@ -93,38 +93,38 @@ export declare class XRequestFormFile {
|
|
|
93
93
|
export declare class XRequest {
|
|
94
94
|
private options?;
|
|
95
95
|
private static getGotOptions;
|
|
96
|
-
static
|
|
97
|
-
static
|
|
98
|
-
static
|
|
99
|
-
static
|
|
100
|
-
static
|
|
101
|
-
static
|
|
102
|
-
static
|
|
103
|
-
static
|
|
104
|
-
static
|
|
105
|
-
static
|
|
96
|
+
static get(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
|
|
97
|
+
static get(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
|
|
98
|
+
static get(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
|
|
99
|
+
static get<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
|
|
100
|
+
static get(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
|
|
101
|
+
static post(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
|
|
102
|
+
static post(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
|
|
103
|
+
static post(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
|
|
104
|
+
static post<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
|
|
105
|
+
static post(options: XRequestPostOptions, responseType: 'stream'): Request;
|
|
106
106
|
static getText(options: XRequestGetStreamOptions): Promise<XRequestResponse<string>>;
|
|
107
107
|
static postText(options: XRequestPostOptions): Promise<XRequestResponse<string>>;
|
|
108
|
-
static
|
|
109
|
-
static
|
|
108
|
+
static getJson<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
|
|
109
|
+
static postJson<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
|
|
110
110
|
static getStream(options: XRequestGetOptions): Request;
|
|
111
111
|
static postStream(options: XRequestPostStreamOptions): Request;
|
|
112
112
|
static isTimeoutError(err: any): boolean;
|
|
113
113
|
constructor(options?: OmitStrict<XRequestOptions, 'url'>);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
114
|
+
get(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
|
|
115
|
+
get(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
|
|
116
|
+
get(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
|
|
117
|
+
get<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
|
|
118
|
+
get(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
|
|
119
|
+
post(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
|
|
120
|
+
post(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
|
|
121
|
+
post(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
|
|
122
|
+
post<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
|
|
123
|
+
post(options: XRequestPostOptions, responseType: 'stream'): Request;
|
|
124
124
|
getText(options: XRequestGetStreamOptions): Promise<XRequestResponse<string>>;
|
|
125
125
|
postText(options: XRequestPostOptions): Promise<XRequestResponse<string>>;
|
|
126
|
-
|
|
127
|
-
|
|
126
|
+
getJson<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
|
|
127
|
+
postJson<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
|
|
128
128
|
getStream(options: XRequestGetOptions): Request;
|
|
129
129
|
postStream(options: XRequestPostStreamOptions): Request;
|
|
130
130
|
isTimeoutError(err: any): boolean;
|
package/lib/index.js
CHANGED
|
@@ -107,7 +107,7 @@ export class XRequest {
|
|
|
107
107
|
}
|
|
108
108
|
return gotOptions;
|
|
109
109
|
}
|
|
110
|
-
static
|
|
110
|
+
static get(options, responseType) {
|
|
111
111
|
let url = options.url;
|
|
112
112
|
if (options.data) {
|
|
113
113
|
const _url = new URL(url);
|
|
@@ -130,7 +130,7 @@ export class XRequest {
|
|
|
130
130
|
data: res.body
|
|
131
131
|
}));
|
|
132
132
|
}
|
|
133
|
-
static
|
|
133
|
+
static post(options, responseType) {
|
|
134
134
|
const gotOptions = this.getGotOptions(options, responseType || 'buffer');
|
|
135
135
|
if (responseType === 'stream' && options.data instanceof FormStream) {
|
|
136
136
|
gotOptions.headers = options.data.headers(gotOptions.headers);
|
|
@@ -161,22 +161,22 @@ export class XRequest {
|
|
|
161
161
|
}));
|
|
162
162
|
}
|
|
163
163
|
static async getText(options) {
|
|
164
|
-
return this.
|
|
164
|
+
return this.get(options, 'text');
|
|
165
165
|
}
|
|
166
166
|
static async postText(options) {
|
|
167
|
-
return this.
|
|
167
|
+
return this.post(options, 'text');
|
|
168
168
|
}
|
|
169
|
-
static async
|
|
170
|
-
return this.
|
|
169
|
+
static async getJson(options) {
|
|
170
|
+
return this.get(options, 'json');
|
|
171
171
|
}
|
|
172
|
-
static async
|
|
173
|
-
return this.
|
|
172
|
+
static async postJson(options) {
|
|
173
|
+
return this.post(options, 'json');
|
|
174
174
|
}
|
|
175
175
|
static getStream(options) {
|
|
176
|
-
return this.
|
|
176
|
+
return this.get(options, 'stream');
|
|
177
177
|
}
|
|
178
178
|
static postStream(options) {
|
|
179
|
-
return this.
|
|
179
|
+
return this.post(options, 'stream');
|
|
180
180
|
}
|
|
181
181
|
static isTimeoutError(err) {
|
|
182
182
|
return err instanceof got.TimeoutError;
|
|
@@ -184,9 +184,9 @@ export class XRequest {
|
|
|
184
184
|
constructor(options) {
|
|
185
185
|
this.options = options;
|
|
186
186
|
}
|
|
187
|
-
|
|
187
|
+
get(options, responseType) {
|
|
188
188
|
var _this$options;
|
|
189
|
-
return XRequest.
|
|
189
|
+
return XRequest.get({
|
|
190
190
|
...this.options,
|
|
191
191
|
...options,
|
|
192
192
|
headers: {
|
|
@@ -195,9 +195,9 @@ export class XRequest {
|
|
|
195
195
|
}
|
|
196
196
|
}, responseType);
|
|
197
197
|
}
|
|
198
|
-
|
|
198
|
+
post(options, responseType) {
|
|
199
199
|
var _this$options2;
|
|
200
|
-
return XRequest.
|
|
200
|
+
return XRequest.post({
|
|
201
201
|
...this.options,
|
|
202
202
|
...options,
|
|
203
203
|
headers: {
|
|
@@ -207,22 +207,22 @@ export class XRequest {
|
|
|
207
207
|
}, responseType);
|
|
208
208
|
}
|
|
209
209
|
async getText(options) {
|
|
210
|
-
return this.
|
|
210
|
+
return this.get(options, 'text');
|
|
211
211
|
}
|
|
212
212
|
async postText(options) {
|
|
213
|
-
return this.
|
|
213
|
+
return this.post(options, 'text');
|
|
214
214
|
}
|
|
215
|
-
async
|
|
216
|
-
return this.
|
|
215
|
+
async getJson(options) {
|
|
216
|
+
return this.get(options, 'json');
|
|
217
217
|
}
|
|
218
|
-
async
|
|
219
|
-
return this.
|
|
218
|
+
async postJson(options) {
|
|
219
|
+
return this.post(options, 'json');
|
|
220
220
|
}
|
|
221
221
|
getStream(options) {
|
|
222
|
-
return this.
|
|
222
|
+
return this.get(options, 'stream');
|
|
223
223
|
}
|
|
224
224
|
postStream(options) {
|
|
225
|
-
return this.
|
|
225
|
+
return this.post(options, 'stream');
|
|
226
226
|
}
|
|
227
227
|
isTimeoutError(err) {
|
|
228
228
|
return XRequest.isTimeoutError(err);
|