@gopowerteam/request 0.1.15 → 0.1.17

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.
@@ -65,7 +65,9 @@ var _AxiosAdapter = class {
65
65
  skipNulls: true,
66
66
  allowDots: true,
67
67
  encodeValuesOnly: true,
68
- encode: true
68
+ encode: true,
69
+ sort: (a, b) => a.localeCompare(b),
70
+ filter: (_, value) => ["", void 0, null].some((v) => v === value) ? void 0 : value
69
71
  }
70
72
  )
71
73
  }
@@ -1,4 +1,4 @@
1
- import { c as RequestAdapter, R as RequestSetupConfig, d as RequestAdapterOptions, A as AdapterResponse } from '../request-plugin.interface-8152139f.js';
1
+ import { c as RequestAdapter, R as RequestSetupConfig, d as RequestAdapterOptions, A as AdapterResponse } from '../request-plugin.interface-3df174bc.js';
2
2
  import { AxiosResponse, AxiosError } from 'axios';
3
3
  import 'qs';
4
4
 
@@ -28,7 +28,9 @@ var _AxiosAdapter = class {
28
28
  skipNulls: true,
29
29
  allowDots: true,
30
30
  encodeValuesOnly: true,
31
- encode: true
31
+ encode: true,
32
+ sort: (a, b) => a.localeCompare(b),
33
+ filter: (_, value) => ["", void 0, null].some((v) => v === value) ? void 0 : value
32
34
  }
33
35
  )
34
36
  }
package/dist/index.cjs CHANGED
@@ -80,17 +80,21 @@ var _RequestService = class {
80
80
  * @param plugins
81
81
  * @param options
82
82
  */
83
- execRequestPlugin(plugins = [], options) {
83
+ async execRequestPlugin(plugins = [], options) {
84
84
  const extraParams = {};
85
85
  const appendParams = (params) => {
86
86
  Object.assign(extraParams, params || {});
87
87
  };
88
- _RequestService.config.plugins.forEach(
89
- (service) => service.before && service.before(options, appendParams)
90
- );
91
- plugins.forEach(
92
- (service) => service.before && service.before(options, appendParams)
93
- );
88
+ for (const plugin of _RequestService.config.plugins) {
89
+ if (plugin.before) {
90
+ await plugin.before(options, appendParams);
91
+ }
92
+ }
93
+ for (const plugin of plugins) {
94
+ if (plugin.before) {
95
+ await plugin.before(options, appendParams);
96
+ }
97
+ }
94
98
  return extraParams;
95
99
  }
96
100
  /**
@@ -177,7 +181,7 @@ var _RequestService = class {
177
181
  }
178
182
  let hasException = false;
179
183
  const adapter = this.getRequestAdapter();
180
- const extraParams = this.execRequestPlugin(plugins, options);
184
+ const extraParams = await this.execRequestPlugin(plugins, options);
181
185
  const response = await this.startRequest(adapter, options, extraParams).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
182
186
  hasException = true;
183
187
  return adapter.transformException(exception);
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { R as RequestSetupConfig, a as RequestSendOptions, b as RequestPlugin } from './request-plugin.interface-8152139f.js';
2
- export { A as AdapterResponse, e as AdapterResponseHeaders, P as PluginLifecycle, c as RequestAdapter, d as RequestAdapterOptions, f as RequestLifecycle, h as RequestMethod, i as ResponseInterceptor, g as ResponseLifecycle } from './request-plugin.interface-8152139f.js';
1
+ import { R as RequestSetupConfig, a as RequestSendOptions, b as RequestPlugin } from './request-plugin.interface-3df174bc.js';
2
+ export { A as AdapterResponse, e as AdapterResponseHeaders, P as PluginLifecycle, c as RequestAdapter, d as RequestAdapterOptions, f as RequestLifecycle, h as RequestMethod, i as ResponseInterceptor, g as ResponseLifecycle } from './request-plugin.interface-3df174bc.js';
3
3
  import 'qs';
4
4
 
5
5
  declare class RequestService {
package/dist/index.js CHANGED
@@ -39,17 +39,21 @@ var _RequestService = class {
39
39
  * @param plugins
40
40
  * @param options
41
41
  */
42
- execRequestPlugin(plugins = [], options) {
42
+ async execRequestPlugin(plugins = [], options) {
43
43
  const extraParams = {};
44
44
  const appendParams = (params) => {
45
45
  Object.assign(extraParams, params || {});
46
46
  };
47
- _RequestService.config.plugins.forEach(
48
- (service) => service.before && service.before(options, appendParams)
49
- );
50
- plugins.forEach(
51
- (service) => service.before && service.before(options, appendParams)
52
- );
47
+ for (const plugin of _RequestService.config.plugins) {
48
+ if (plugin.before) {
49
+ await plugin.before(options, appendParams);
50
+ }
51
+ }
52
+ for (const plugin of plugins) {
53
+ if (plugin.before) {
54
+ await plugin.before(options, appendParams);
55
+ }
56
+ }
53
57
  return extraParams;
54
58
  }
55
59
  /**
@@ -136,7 +140,7 @@ var _RequestService = class {
136
140
  }
137
141
  let hasException = false;
138
142
  const adapter = this.getRequestAdapter();
139
- const extraParams = this.execRequestPlugin(plugins, options);
143
+ const extraParams = await this.execRequestPlugin(plugins, options);
140
144
  const response = await this.startRequest(adapter, options, extraParams).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
141
145
  hasException = true;
142
146
  return adapter.transformException(exception);
@@ -83,7 +83,7 @@ type AdapterResponseHeaders = Record<string, string | string[] | number | boolea
83
83
  * 请求插件
84
84
  */
85
85
  interface RequestPlugin {
86
- before?: (options: RequestSendOptions, appendParams: (params: Record<string, any>) => void) => void;
86
+ before?: (options: RequestSendOptions, appendParams: (params: Record<string, any>) => void) => void | Promise<void>;
87
87
  after?: (response: AdapterResponse, options: RequestSendOptions) => void;
88
88
  catch?: (response: AdapterResponse, options: RequestSendOptions) => void;
89
89
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gopowerteam/request",
3
3
  "private": false,
4
- "version": "0.1.15",
4
+ "version": "0.1.17",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",