@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 CHANGED
@@ -116,7 +116,7 @@ class XRequest {
116
116
  }
117
117
  return gotOptions;
118
118
  }
119
- static getRaw(options, responseType) {
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 postRaw(options, responseType) {
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.getRaw(options, 'text');
173
+ return this.get(options, 'text');
174
174
  }
175
175
  static async postText(options) {
176
- return this.postRaw(options, 'text');
176
+ return this.post(options, 'text');
177
177
  }
178
- static async get(options) {
179
- return this.getRaw(options, 'json');
178
+ static async getJson(options) {
179
+ return this.get(options, 'json');
180
180
  }
181
- static async post(options) {
182
- return this.postRaw(options, 'json');
181
+ static async postJson(options) {
182
+ return this.post(options, 'json');
183
183
  }
184
184
  static getStream(options) {
185
- return this.getRaw(options, 'stream');
185
+ return this.get(options, 'stream');
186
186
  }
187
187
  static postStream(options) {
188
- return this.postRaw(options, 'stream');
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
- getRaw(options, responseType) {
196
+ get(options, responseType) {
197
197
  var _this$options;
198
- return XRequest.getRaw({
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
- postRaw(options, responseType) {
207
+ post(options, responseType) {
208
208
  var _this$options2;
209
- return XRequest.postRaw({
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.getRaw(options, 'text');
219
+ return this.get(options, 'text');
220
220
  }
221
221
  async postText(options) {
222
- return this.postRaw(options, 'text');
222
+ return this.post(options, 'text');
223
223
  }
224
- async get(options) {
225
- return this.getRaw(options, 'json');
224
+ async getJson(options) {
225
+ return this.get(options, 'json');
226
226
  }
227
- async post(options) {
228
- return this.postRaw(options, 'json');
227
+ async postJson(options) {
228
+ return this.post(options, 'json');
229
229
  }
230
230
  getStream(options) {
231
- return this.getRaw(options, 'stream');
231
+ return this.get(options, 'stream');
232
232
  }
233
233
  postStream(options) {
234
- return this.postRaw(options, 'stream');
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 getRaw(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
97
- static getRaw(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
98
- static getRaw(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
99
- static getRaw<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
100
- static getRaw(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
101
- static postRaw(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
102
- static postRaw(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
103
- static postRaw(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
104
- static postRaw<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
105
- static postRaw(options: XRequestPostOptions, responseType: 'stream'): Request;
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 get<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
109
- static post<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
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
- getRaw(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
115
- getRaw(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
116
- getRaw(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
117
- getRaw<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
118
- getRaw(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
119
- postRaw(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
120
- postRaw(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
121
- postRaw(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
122
- postRaw<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
123
- postRaw(options: XRequestPostOptions, responseType: 'stream'): Request;
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
- get<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
127
- post<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
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 getRaw(options, responseType) {
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 postRaw(options, responseType) {
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.getRaw(options, 'text');
164
+ return this.get(options, 'text');
165
165
  }
166
166
  static async postText(options) {
167
- return this.postRaw(options, 'text');
167
+ return this.post(options, 'text');
168
168
  }
169
- static async get(options) {
170
- return this.getRaw(options, 'json');
169
+ static async getJson(options) {
170
+ return this.get(options, 'json');
171
171
  }
172
- static async post(options) {
173
- return this.postRaw(options, 'json');
172
+ static async postJson(options) {
173
+ return this.post(options, 'json');
174
174
  }
175
175
  static getStream(options) {
176
- return this.getRaw(options, 'stream');
176
+ return this.get(options, 'stream');
177
177
  }
178
178
  static postStream(options) {
179
- return this.postRaw(options, 'stream');
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
- getRaw(options, responseType) {
187
+ get(options, responseType) {
188
188
  var _this$options;
189
- return XRequest.getRaw({
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
- postRaw(options, responseType) {
198
+ post(options, responseType) {
199
199
  var _this$options2;
200
- return XRequest.postRaw({
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.getRaw(options, 'text');
210
+ return this.get(options, 'text');
211
211
  }
212
212
  async postText(options) {
213
- return this.postRaw(options, 'text');
213
+ return this.post(options, 'text');
214
214
  }
215
- async get(options) {
216
- return this.getRaw(options, 'json');
215
+ async getJson(options) {
216
+ return this.get(options, 'json');
217
217
  }
218
- async post(options) {
219
- return this.postRaw(options, 'json');
218
+ async postJson(options) {
219
+ return this.post(options, 'json');
220
220
  }
221
221
  getStream(options) {
222
- return this.getRaw(options, 'stream');
222
+ return this.get(options, 'stream');
223
223
  }
224
224
  postStream(options) {
225
- return this.postRaw(options, 'stream');
225
+ return this.post(options, 'stream');
226
226
  }
227
227
  isTimeoutError(err) {
228
228
  return XRequest.isTimeoutError(err);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-request",
3
- "version": "2.12.18",
3
+ "version": "2.12.19",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",