@jayfong/x-request 2.25.0 → 2.26.0

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
@@ -8,9 +8,9 @@ var _formData = _interopRequireDefault(require("form-data"));
8
8
  var _formstream = _interopRequireDefault(require("formstream"));
9
9
  var _fs = _interopRequireDefault(require("fs"));
10
10
  var _got = _interopRequireDefault(require("got"));
11
- var _vtils = require("vtils");
12
11
  var _proxyAgent = require("proxy-agent");
13
12
  var _stream = require("stream");
13
+ var _vtils = require("vtils");
14
14
  class XRequestFormUrlencoded extends URLSearchParams {}
15
15
  exports.XRequestFormUrlencoded = XRequestFormUrlencoded;
16
16
  class XRequestFormData extends _formData.default {
@@ -126,7 +126,7 @@ class XRequest {
126
126
  }
127
127
  static get(options, responseType) {
128
128
  const res = (0, _got.default)({
129
- method: 'GET',
129
+ method: options.method || 'GET',
130
130
  ...this.getGotOptions(options, responseType || 'buffer')
131
131
  });
132
132
  if (responseType === 'stream') {
@@ -144,7 +144,7 @@ class XRequest {
144
144
  gotOptions.headers = options.data.headers(gotOptions.headers);
145
145
  }
146
146
  const res = (0, _got.default)({
147
- method: 'POST',
147
+ method: options.method || 'POST',
148
148
  ...(options.data == null ? {
149
149
  body: ''
150
150
  } : options.data instanceof _formData.default ? {
package/lib/index.d.ts CHANGED
@@ -3,9 +3,9 @@
3
3
  import FormData from 'form-data';
4
4
  import FormStream from 'formstream';
5
5
  import Request from 'got/dist/source/core';
6
+ import { Readable } from 'stream';
6
7
  import { CookieJar } from 'tough-cookie';
7
8
  import { OmitStrict } from 'vtils/types';
8
- import { Readable } from 'stream';
9
9
  export interface XRequestOptions {
10
10
  /**
11
11
  * 请求地址
@@ -56,12 +56,12 @@ export interface XRequestResponse<T> {
56
56
  data: T;
57
57
  }
58
58
  export interface XRequestGetOptions extends XRequestOptions {
59
+ method?: string;
59
60
  }
60
61
  export interface XRequestPostOptions extends XRequestOptions {
62
+ method?: string;
61
63
  data?: Record<string, any> | FormData | URLSearchParams;
62
64
  }
63
- export interface XRequestGetStreamOptions extends XRequestOptions {
64
- }
65
65
  export interface XRequestPostStreamOptions extends XRequestOptions {
66
66
  data?: Record<string, any> | FormData | URLSearchParams | FormStream;
67
67
  }
@@ -95,19 +95,19 @@ export declare class XRequestFormFile {
95
95
  export declare class XRequest {
96
96
  private options?;
97
97
  private static getGotOptions;
98
- static get(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
99
- static get(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
100
- static get(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
101
- static get<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
102
- static get(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
98
+ static get(options: XRequestGetOptions): Promise<XRequestResponse<Buffer>>;
99
+ static get(options: XRequestGetOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
100
+ static get(options: XRequestGetOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
101
+ static get<T>(options: XRequestGetOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
102
+ static get(options: XRequestGetOptions, responseType: 'stream'): Request;
103
103
  static post(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
104
104
  static post(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
105
105
  static post(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
106
106
  static post<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
107
107
  static post(options: XRequestPostOptions, responseType: 'stream'): Request;
108
- static getText(options: XRequestGetStreamOptions): Promise<XRequestResponse<string>>;
108
+ static getText(options: XRequestGetOptions): Promise<XRequestResponse<string>>;
109
109
  static postText(options: XRequestPostOptions): Promise<XRequestResponse<string>>;
110
- static getJson<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
110
+ static getJson<T>(options: XRequestGetOptions): Promise<XRequestResponse<T>>;
111
111
  static postJson<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
112
112
  static getStream(options: XRequestGetOptions): Request;
113
113
  static postStream(options: XRequestPostStreamOptions): Request;
@@ -129,19 +129,19 @@ export declare class XRequest {
129
129
  }): XRequestFormFile;
130
130
  static extend(options: OmitStrict<XRequestOptions, 'url'>): XRequest;
131
131
  constructor(options?: OmitStrict<XRequestOptions, 'url'>);
132
- get(options: XRequestGetStreamOptions): Promise<XRequestResponse<Buffer>>;
133
- get(options: XRequestGetStreamOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
134
- get(options: XRequestGetStreamOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
135
- get<T>(options: XRequestGetStreamOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
136
- get(options: XRequestGetStreamOptions, responseType: 'stream'): Request;
132
+ get(options: XRequestGetOptions): Promise<XRequestResponse<Buffer>>;
133
+ get(options: XRequestGetOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
134
+ get(options: XRequestGetOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
135
+ get<T>(options: XRequestGetOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
136
+ get(options: XRequestGetOptions, responseType: 'stream'): Request;
137
137
  post(options: XRequestPostOptions): Promise<XRequestResponse<Buffer>>;
138
138
  post(options: XRequestPostOptions, responseType: 'buffer'): Promise<XRequestResponse<Buffer>>;
139
139
  post(options: XRequestPostOptions, responseType: 'text'): Promise<XRequestResponse<string>>;
140
140
  post<T>(options: XRequestPostOptions, responseType: 'json'): Promise<XRequestResponse<T>>;
141
141
  post(options: XRequestPostOptions, responseType: 'stream'): Request;
142
- getText(options: XRequestGetStreamOptions): Promise<XRequestResponse<string>>;
142
+ getText(options: XRequestGetOptions): Promise<XRequestResponse<string>>;
143
143
  postText(options: XRequestPostOptions): Promise<XRequestResponse<string>>;
144
- getJson<T>(options: XRequestGetStreamOptions): Promise<XRequestResponse<T>>;
144
+ getJson<T>(options: XRequestGetOptions): Promise<XRequestResponse<T>>;
145
145
  postJson<T>(options: XRequestPostOptions): Promise<XRequestResponse<T>>;
146
146
  getStream(options: XRequestGetOptions): Request;
147
147
  postStream(options: XRequestPostStreamOptions): Request;
package/lib/index.js CHANGED
@@ -3,9 +3,9 @@ import FormData from 'form-data';
3
3
  import FormStream from 'formstream';
4
4
  import fs from 'fs';
5
5
  import got from 'got';
6
- import { mapKeys } from 'vtils';
7
6
  import { ProxyAgent } from 'proxy-agent';
8
7
  import { Readable } from 'stream';
8
+ import { mapKeys } from 'vtils';
9
9
  export class XRequestFormUrlencoded extends URLSearchParams {}
10
10
  export class XRequestFormData extends FormData {
11
11
  constructor(cbOrObject) {
@@ -117,7 +117,7 @@ export class XRequest {
117
117
  }
118
118
  static get(options, responseType) {
119
119
  const res = got({
120
- method: 'GET',
120
+ method: options.method || 'GET',
121
121
  ...this.getGotOptions(options, responseType || 'buffer')
122
122
  });
123
123
  if (responseType === 'stream') {
@@ -135,7 +135,7 @@ export class XRequest {
135
135
  gotOptions.headers = options.data.headers(gotOptions.headers);
136
136
  }
137
137
  const res = got({
138
- method: 'POST',
138
+ method: options.method || 'POST',
139
139
  ...(options.data == null ? {
140
140
  body: ''
141
141
  } : options.data instanceof FormData ? {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-request",
3
- "version": "2.25.0",
3
+ "version": "2.26.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",