@gopowerteam/request 0.1.20 → 0.2.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/dist/index.cjs CHANGED
@@ -1,268 +1,250 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
- var __export = (target, all) => {
10
- for (var name in all)
11
- __defProp(target, name, { get: all[name], enumerable: true });
12
- };
13
- var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
- var __publicField = (obj, key, value) => {
31
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
32
- return value;
33
- };
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
34
2
 
35
- // src/index.ts
36
- var src_exports = {};
37
- __export(src_exports, {
38
- PluginLifecycle: () => PluginLifecycle,
39
- RequestGenerateType: () => RequestGenerateType,
40
- RequestMethod: () => RequestMethod,
41
- RequestService: () => RequestService,
42
- setup: () => setup
43
- });
44
- module.exports = __toCommonJS(src_exports);
3
+ //#region src/interfaces/request-generate.interface.ts
4
+ let RequestGenerateType = /* @__PURE__ */ function(RequestGenerateType) {
5
+ RequestGenerateType["Request"] = "TO_REQUEST";
6
+ RequestGenerateType["URL"] = "TO_URL";
7
+ return RequestGenerateType;
8
+ }({});
45
9
 
46
- // src/request-service.ts
47
- var import_qs = __toESM(require("qs"), 1);
10
+ //#endregion
11
+ //#region src/interfaces/request-plugin.interface.ts
12
+ let PluginLifecycle = /* @__PURE__ */ function(PluginLifecycle) {
13
+ PluginLifecycle["before"] = "before";
14
+ PluginLifecycle["after"] = "after";
15
+ PluginLifecycle["catch"] = "catch";
16
+ return PluginLifecycle;
17
+ }({});
48
18
 
49
- // src/interfaces/request-plugin.interface.ts
50
- var PluginLifecycle = /* @__PURE__ */ ((PluginLifecycle2) => {
51
- PluginLifecycle2["before"] = "before";
52
- PluginLifecycle2["after"] = "after";
53
- PluginLifecycle2["catch"] = "catch";
54
- return PluginLifecycle2;
55
- })(PluginLifecycle || {});
19
+ //#endregion
20
+ //#region src/interfaces/request-send.interface.ts
21
+ /**
22
+ * 请求方法类型
23
+ */
24
+ let RequestMethod = /* @__PURE__ */ function(RequestMethod) {
25
+ RequestMethod["Get"] = "GET";
26
+ RequestMethod["Post"] = "POST";
27
+ RequestMethod["Put"] = "PUT";
28
+ RequestMethod["Delete"] = "DELETE";
29
+ RequestMethod["Options"] = "OPTIONS";
30
+ RequestMethod["Head"] = "HEAD";
31
+ RequestMethod["Patch"] = "PATCH";
32
+ return RequestMethod;
33
+ }({});
56
34
 
57
- // src/request-service.ts
58
- var _RequestService = class {
59
- /**
60
- * 获取服务请求单例
61
- */
62
- static getInstance() {
63
- if (this.instance) {
64
- return this.instance;
65
- }
66
- return new _RequestService();
67
- }
68
- /**
69
- * 获取RequestAdatper
70
- * @returns
71
- */
72
- getRequestAdapter() {
73
- if (!_RequestService.config.adapter) {
74
- throw new Error("\u8BF7\u68C0\u67E5\u662F\u5426\u914D\u7F6E\u8BF7\u6C42Adatper");
75
- }
76
- return _RequestService.config.adapter;
77
- }
78
- /**
79
- * 执行前置插件逻辑
80
- * @param plugins
81
- * @param options
82
- */
83
- async execRequestPlugin(plugins = [], options) {
84
- const extraParams = {};
85
- const appendParams = (params) => {
86
- Object.assign(extraParams, params || {});
87
- };
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
- }
98
- return extraParams;
99
- }
100
- /**
101
- * 执行前置插件逻辑
102
- * @param plugins
103
- * @param options
104
- */
105
- execResponsePlugin(leftcycle, plugins = [], options, response) {
106
- plugins.forEach((plugin) => {
107
- const leftcycleFn = plugin[leftcycle];
108
- leftcycleFn && leftcycleFn.bind(plugin)(response, options);
109
- });
110
- _RequestService.config.plugins.forEach((plugin) => {
111
- const leftcycleFn = plugin[leftcycle];
112
- leftcycleFn && leftcycleFn.bind(plugin)(response, options);
113
- });
114
- }
115
- /**
116
- * 转换请求路径
117
- */
118
- parseRequestPath(path, paramsPath, service) {
119
- if (service) {
120
- path = `/${service}/${path}`.replace(/\/{2,3}/g, "/");
121
- }
122
- if (paramsPath) {
123
- return Object.entries(paramsPath).reduce(
124
- (r, [key, value]) => r.replace(`{${key}}`, value.toString()),
125
- path
126
- );
127
- } else {
128
- return path;
129
- }
130
- }
131
- /**
132
- * 开始请求
133
- * @param adapter
134
- * @param options
135
- * @returns
136
- */
137
- startRequest(adapter, options, extraParams) {
138
- return adapter.request({
139
- baseURL: _RequestService.config.gateway,
140
- pathURL: this.parseRequestPath(
141
- options.path,
142
- options.paramsPath,
143
- options.service
144
- ),
145
- method: options.method,
146
- headers: options.headers || {},
147
- paramsQuery: options.paramsQuery,
148
- paramsBody: options.paramsBody,
149
- extraParams
150
- });
151
- }
152
- /**
153
- * 执行拦截器
154
- * @param response 请求响应对象
155
- * @returns
156
- */
157
- execInterceptors(response, hasException = false) {
158
- const interceptors = _RequestService.config?.interceptors;
159
- if (!interceptors?.status || !interceptors?.error || !interceptors?.success || !interceptors?.exception) {
160
- throw new Error("\u8BF7\u68C0\u67E5\u62E6\u622A\u5668\u914D\u7F6E");
161
- }
162
- const status = interceptors.status.exec(response) && !hasException;
163
- if (hasException) {
164
- interceptors.exception.exec(response);
165
- }
166
- if (status) {
167
- return Promise.resolve(interceptors.success.exec(response));
168
- } else {
169
- return Promise.reject(interceptors.error.exec(response));
170
- }
171
- }
172
- /**
173
- * 发送请求
174
- * @param {RequestSendOptions} options 请求选项
175
- * @param {RequestPlugin[]} plugins 请求插件
176
- * @returns
177
- */
178
- async send(options, requestPlugins = []) {
179
- if (!_RequestService.config) {
180
- throw new Error("\u8BF7\u68C0\u67E5\u8BF7\u6C42\u914D\u7F6E\u662F\u5426\u5B8C\u6210");
181
- }
182
- let hasException = false;
183
- const adapter = this.getRequestAdapter();
184
- const plugins = requestPlugins.filter(Boolean);
185
- const extraParams = await this.execRequestPlugin(plugins, options);
186
- const response = await this.startRequest(adapter, options, extraParams).then((response2) => adapter.transformResponse(response2)).catch((exception) => {
187
- hasException = true;
188
- return adapter.transformException(exception);
189
- });
190
- if (!hasException) {
191
- this.execResponsePlugin("after" /* after */, plugins, options, response);
192
- } else {
193
- this.execResponsePlugin("catch" /* catch */, plugins, options, response);
194
- }
195
- return this.execInterceptors(response, hasException);
196
- }
197
- /**
198
- * 生成请求路径
199
- * @param {RequestSendOptions} options 请求选项
200
- * @param {RequestPlugin[]} plugins 请求插件
201
- * @returns
202
- */
203
- toURL(options, plugins = []) {
204
- if (!_RequestService.config) {
205
- throw new Error("\u8BF7\u68C0\u67E5\u8BF7\u6C42\u914D\u7F6E\u662F\u5426\u5B8C\u6210");
206
- }
207
- if (plugins && plugins.length) {
208
- this.execRequestPlugin(
209
- plugins.filter(Boolean),
210
- options
211
- );
212
- }
213
- const baseURL = _RequestService.config.gateway;
214
- const pathURL = this.parseRequestPath(
215
- options.path,
216
- options.paramsPath,
217
- options.service
218
- );
219
- const queryString = import_qs.default.stringify(options.paramsQuery, {
220
- ...{
221
- arrayFormat: "repeat",
222
- skipNulls: true,
223
- allowDots: true,
224
- encodeValuesOnly: true,
225
- encode: true
226
- },
227
- ..._RequestService.config.qs || {},
228
- addQueryPrefix: true
229
- });
230
- return `${baseURL}${pathURL}${queryString}`;
231
- }
35
+ //#endregion
36
+ //#region src/utils/query-string.ts
37
+ /**
38
+ * 编码字符串
39
+ */
40
+ function encodeValue(value, encode) {
41
+ if (!encode) return value;
42
+ return encodeURIComponent(value);
43
+ }
44
+ /**
45
+ * 处理嵌套对象的键名
46
+ */
47
+ function getKeyWithDot(key, childKey, allowDots) {
48
+ return allowDots ? `${key}.${childKey}` : `${key}[${childKey}]`;
49
+ }
50
+ /**
51
+ * 递归处理对象值
52
+ */
53
+ function processValue(value, options, parentKey = "") {
54
+ const result = [];
55
+ if (value === null || value === void 0) {
56
+ if (!options.skipNulls) result.push(`${parentKey}=`);
57
+ return result;
58
+ }
59
+ if (Array.isArray(value)) if (options.arrayFormat === "comma") {
60
+ const filteredValues = value.filter((item) => item !== null && item !== void 0);
61
+ if (filteredValues.length > 0) {
62
+ const encodedValue = encodeValue(filteredValues.map((item) => typeof item === "object" ? JSON.stringify(item) : item.toString()).join(","), options.encode !== false);
63
+ result.push(`${parentKey}=${encodedValue}`);
64
+ }
65
+ } else value.forEach((item, index) => {
66
+ let itemKey;
67
+ const shouldEncode = options.encode !== false;
68
+ if (options.arrayFormat === "indices") itemKey = parentKey ? `${parentKey}[${index}]` : `[${index}]`;
69
+ else if (options.arrayFormat === "brackets") itemKey = parentKey ? `${parentKey}[]` : "[]";
70
+ else itemKey = parentKey;
71
+ if (typeof item === "object" && item !== null) result.push(...processValue(item, options, itemKey));
72
+ else {
73
+ const encodedValue = encodeValue(item.toString(), shouldEncode);
74
+ result.push(`${itemKey}=${encodedValue}`);
75
+ }
76
+ });
77
+ else if (typeof value === "object") Object.keys(value).forEach((childKey) => {
78
+ const fullKey = parentKey ? getKeyWithDot(parentKey, childKey, options.allowDots || false) : childKey;
79
+ result.push(...processValue(value[childKey], options, fullKey));
80
+ });
81
+ else {
82
+ const shouldEncode = options.encode !== false;
83
+ const encodedValue = encodeValue(value.toString(), shouldEncode);
84
+ const encodedKey = options.encodeValuesOnly ? parentKey : encodeValue(parentKey, shouldEncode);
85
+ result.push(`${encodedKey}=${encodedValue}`);
86
+ }
87
+ return result;
88
+ }
89
+ /**
90
+ * 将对象序列化为查询字符串
91
+ */
92
+ function stringify(obj, options = {}) {
93
+ const { arrayFormat = "indices", skipNulls = true, allowDots = true, encodeValuesOnly = false, encode = true, addQueryPrefix = false } = options;
94
+ if (!obj || typeof obj !== "object") return options.addQueryPrefix ? "?" : "";
95
+ const parts = [];
96
+ Object.keys(obj).forEach((key) => {
97
+ const value = obj[key];
98
+ const processedValues = processValue(value, {
99
+ arrayFormat,
100
+ skipNulls,
101
+ allowDots,
102
+ encodeValuesOnly,
103
+ encode,
104
+ addQueryPrefix
105
+ }, key);
106
+ parts.push(...processedValues);
107
+ });
108
+ const queryString = parts.join("&");
109
+ return addQueryPrefix ? queryString ? `?${queryString}` : "?" : queryString;
110
+ }
111
+
112
+ //#endregion
113
+ //#region src/request-service.ts
114
+ var RequestService = class RequestService {
115
+ static config;
116
+ static instance;
117
+ /**
118
+ * 获取服务请求单例
119
+ */
120
+ static getInstance() {
121
+ if (this.instance) return this.instance;
122
+ return new RequestService();
123
+ }
124
+ /**
125
+ * 获取RequestAdatper
126
+ * @returns RequestAdapter
127
+ */
128
+ getRequestAdapter() {
129
+ if (!RequestService.config.adapter) throw new Error("请检查是否配置请求Adatper");
130
+ return RequestService.config.adapter;
131
+ }
132
+ /**
133
+ * 执行前置插件逻辑
134
+ * @param plugins
135
+ * @param options
136
+ */
137
+ async execRequestPlugin(plugins = [], options) {
138
+ const extraParams = {};
139
+ const appendParams = (params) => {
140
+ Object.assign(extraParams, params || {});
141
+ };
142
+ for (const plugin of RequestService.config.plugins) if (plugin.before) await plugin.before(options, appendParams);
143
+ for (const plugin of plugins) if (plugin.before) await plugin.before(options, appendParams);
144
+ return extraParams;
145
+ }
146
+ /**
147
+ * 执行前置插件逻辑
148
+ */
149
+ execResponsePlugin(leftcycle, plugins = [], options, response) {
150
+ plugins.forEach((plugin) => {
151
+ const leftcycleFn = plugin[leftcycle];
152
+ if (leftcycleFn) leftcycleFn.bind(plugin)(response, options);
153
+ });
154
+ RequestService.config.plugins.forEach((plugin) => {
155
+ const leftcycleFn = plugin[leftcycle];
156
+ if (leftcycleFn) leftcycleFn.bind(plugin)(response, options);
157
+ });
158
+ }
159
+ /**
160
+ * 转换请求路径
161
+ */
162
+ parseRequestPath(path, paramsPath, service) {
163
+ if (service) path = `/${service}/${path}`.replace(/\/{2,3}/g, "/");
164
+ if (paramsPath) return Object.entries(paramsPath).reduce((r, [key, value]) => r.replace(`{${key}}`, value.toString()), path);
165
+ else return path;
166
+ }
167
+ /**
168
+ * 开始请求
169
+ * @param adapter
170
+ * @param options
171
+ * @returns Promise
172
+ */
173
+ startRequest(adapter, options, extraParams) {
174
+ return adapter.request({
175
+ baseURL: RequestService.config.gateway,
176
+ pathURL: this.parseRequestPath(options.path, options.paramsPath, options.service),
177
+ method: options.method,
178
+ headers: options.headers || {},
179
+ paramsQuery: options.paramsQuery,
180
+ paramsBody: options.paramsBody,
181
+ extraParams
182
+ });
183
+ }
184
+ /**
185
+ * 执行拦截器
186
+ * @param response 请求响应对象
187
+ * @returns Promise
188
+ */
189
+ execInterceptors(response, hasException = false) {
190
+ const interceptors = RequestService.config?.interceptors;
191
+ if (!interceptors?.status || !interceptors?.error || !interceptors?.success || !interceptors?.exception) throw new Error("请检查拦截器配置");
192
+ const status = interceptors.status.exec(response) && !hasException;
193
+ if (hasException) interceptors.exception.exec(response);
194
+ if (status) return Promise.resolve(interceptors.success.exec(response));
195
+ else return Promise.reject(interceptors.error.exec(response));
196
+ }
197
+ /**
198
+ * 发送请求
199
+ * @param {RequestSendOptions} options 请求选项
200
+ * @param {RequestPlugin[]} requestPlugins 请求插件
201
+ * @returns Promise
202
+ */
203
+ async send(options, requestPlugins = []) {
204
+ if (!RequestService.config) throw new Error("请检查请求配置是否完成");
205
+ let hasException = false;
206
+ const adapter = this.getRequestAdapter();
207
+ const plugins = requestPlugins.filter(Boolean);
208
+ const extraParams = await this.execRequestPlugin(plugins, options);
209
+ const response = await this.startRequest(adapter, options, extraParams).then((response) => adapter.transformResponse(response)).catch((exception) => {
210
+ hasException = true;
211
+ return adapter.transformException(exception);
212
+ });
213
+ if (!hasException) this.execResponsePlugin(PluginLifecycle.after, plugins, options, response);
214
+ else this.execResponsePlugin(PluginLifecycle.catch, plugins, options, response);
215
+ return this.execInterceptors(response, hasException);
216
+ }
217
+ /**
218
+ * 生成请求路径
219
+ * @param {RequestSendOptions} options 请求选项
220
+ * @param {RequestPlugin[]} plugins 请求插件
221
+ * @returns string
222
+ */
223
+ toURL(options, plugins = []) {
224
+ if (!RequestService.config) throw new Error("请检查请求配置是否完成");
225
+ if (plugins && plugins.length) this.execRequestPlugin(plugins.filter(Boolean), options);
226
+ return `${RequestService.config.gateway}${this.parseRequestPath(options.path, options.paramsPath, options.service)}${stringify(options.paramsQuery || {}, {
227
+ arrayFormat: "repeat",
228
+ skipNulls: true,
229
+ allowDots: true,
230
+ encodeValuesOnly: true,
231
+ encode: true,
232
+ addQueryPrefix: true,
233
+ ...RequestService.config.qs || {}
234
+ })}`;
235
+ }
232
236
  };
233
- var RequestService = _RequestService;
234
- __publicField(RequestService, "config");
235
- __publicField(RequestService, "instance");
236
237
 
237
- // src/request-setup.ts
238
+ //#endregion
239
+ //#region src/request-setup.ts
238
240
  function setup(config) {
239
- RequestService.config = config;
240
- RequestService.config?.adapter?.injectConfig?.(config);
241
+ RequestService.config = config;
242
+ RequestService.config?.adapter?.injectConfig?.(config);
241
243
  }
242
244
 
243
- // src/interfaces/request-send.interface.ts
244
- var RequestMethod = /* @__PURE__ */ ((RequestMethod2) => {
245
- RequestMethod2["Get"] = "GET";
246
- RequestMethod2["Post"] = "POST";
247
- RequestMethod2["Put"] = "PUT";
248
- RequestMethod2["Delete"] = "DELETE";
249
- RequestMethod2["Options"] = "OPTIONS";
250
- RequestMethod2["Head"] = "HEAD";
251
- RequestMethod2["Patch"] = "PATCH";
252
- return RequestMethod2;
253
- })(RequestMethod || {});
254
-
255
- // src/interfaces/request-generate.interface.ts
256
- var RequestGenerateType = /* @__PURE__ */ ((RequestGenerateType2) => {
257
- RequestGenerateType2["Request"] = "TO_REQUEST";
258
- RequestGenerateType2["URL"] = "TO_URL";
259
- return RequestGenerateType2;
260
- })(RequestGenerateType || {});
261
- // Annotate the CommonJS export names for ESM import in node:
262
- 0 && (module.exports = {
263
- PluginLifecycle,
264
- RequestGenerateType,
265
- RequestMethod,
266
- RequestService,
267
- setup
268
- });
245
+ //#endregion
246
+ exports.PluginLifecycle = PluginLifecycle;
247
+ exports.RequestGenerateType = RequestGenerateType;
248
+ exports.RequestMethod = RequestMethod;
249
+ exports.RequestService = RequestService;
250
+ exports.setup = setup;
@@ -0,0 +1,71 @@
1
+ import { a as RequestSetupConfig, c as RequestLifecycle, d as RequestMethod, f as RequestSendOptions, i as RequestAdapterOptions, l as RequestPlugin, n as AdapterResponseHeaders, o as ResponseInterceptor, r as RequestAdapter, s as PluginLifecycle, t as AdapterResponse, u as ResponseLifecycle } from "./request-adapter.interface-Cr5s4kIp.cjs";
2
+
3
+ //#region src/interfaces/request-generate.interface.d.ts
4
+ declare enum RequestGenerateType {
5
+ Request = "TO_REQUEST",
6
+ URL = "TO_URL"
7
+ }
8
+ interface RequestGenerateOptions {
9
+ type?: RequestGenerateType;
10
+ }
11
+ //#endregion
12
+ //#region src/request-service.d.ts
13
+ declare class RequestService {
14
+ static config: RequestSetupConfig;
15
+ static instance: RequestService;
16
+ /**
17
+ * 获取服务请求单例
18
+ */
19
+ static getInstance(): RequestService;
20
+ /**
21
+ * 获取RequestAdatper
22
+ * @returns RequestAdapter
23
+ */
24
+ private getRequestAdapter;
25
+ /**
26
+ * 执行前置插件逻辑
27
+ * @param plugins
28
+ * @param options
29
+ */
30
+ private execRequestPlugin;
31
+ /**
32
+ * 执行前置插件逻辑
33
+ */
34
+ private execResponsePlugin;
35
+ /**
36
+ * 转换请求路径
37
+ */
38
+ private parseRequestPath;
39
+ /**
40
+ * 开始请求
41
+ * @param adapter
42
+ * @param options
43
+ * @returns Promise
44
+ */
45
+ private startRequest;
46
+ /**
47
+ * 执行拦截器
48
+ * @param response 请求响应对象
49
+ * @returns Promise
50
+ */
51
+ private execInterceptors;
52
+ /**
53
+ * 发送请求
54
+ * @param {RequestSendOptions} options 请求选项
55
+ * @param {RequestPlugin[]} requestPlugins 请求插件
56
+ * @returns Promise
57
+ */
58
+ send(options: RequestSendOptions, requestPlugins?: (RequestPlugin | undefined)[]): Promise<any>;
59
+ /**
60
+ * 生成请求路径
61
+ * @param {RequestSendOptions} options 请求选项
62
+ * @param {RequestPlugin[]} plugins 请求插件
63
+ * @returns string
64
+ */
65
+ toURL(options: RequestSendOptions, plugins?: (RequestPlugin | undefined)[]): string;
66
+ }
67
+ //#endregion
68
+ //#region src/request-setup.d.ts
69
+ declare function setup(config: RequestSetupConfig): void;
70
+ //#endregion
71
+ export { AdapterResponse, AdapterResponseHeaders, PluginLifecycle, RequestAdapter, RequestAdapterOptions, RequestGenerateOptions, RequestGenerateType, RequestLifecycle, RequestMethod, RequestPlugin, RequestSendOptions, RequestService, RequestSetupConfig, ResponseInterceptor, ResponseLifecycle, setup };
@@ -0,0 +1,62 @@
1
+ import { a as RequestAdapter, c as ResponseInterceptor, d as RequestPlugin, f as ResponseLifecycle, i as AdapterResponseHeaders, l as PluginLifecycle, m as RequestSendOptions, n as RequestGenerateType, o as RequestAdapterOptions, p as RequestMethod, r as AdapterResponse, s as RequestSetupConfig, t as RequestGenerateOptions, u as RequestLifecycle } from "./index-hNav9Ikc.mjs";
2
+
3
+ //#region src/request-service.d.ts
4
+ declare class RequestService {
5
+ static config: RequestSetupConfig;
6
+ static instance: RequestService;
7
+ /**
8
+ * 获取服务请求单例
9
+ */
10
+ static getInstance(): RequestService;
11
+ /**
12
+ * 获取RequestAdatper
13
+ * @returns RequestAdapter
14
+ */
15
+ private getRequestAdapter;
16
+ /**
17
+ * 执行前置插件逻辑
18
+ * @param plugins
19
+ * @param options
20
+ */
21
+ private execRequestPlugin;
22
+ /**
23
+ * 执行前置插件逻辑
24
+ */
25
+ private execResponsePlugin;
26
+ /**
27
+ * 转换请求路径
28
+ */
29
+ private parseRequestPath;
30
+ /**
31
+ * 开始请求
32
+ * @param adapter
33
+ * @param options
34
+ * @returns Promise
35
+ */
36
+ private startRequest;
37
+ /**
38
+ * 执行拦截器
39
+ * @param response 请求响应对象
40
+ * @returns Promise
41
+ */
42
+ private execInterceptors;
43
+ /**
44
+ * 发送请求
45
+ * @param {RequestSendOptions} options 请求选项
46
+ * @param {RequestPlugin[]} requestPlugins 请求插件
47
+ * @returns Promise
48
+ */
49
+ send(options: RequestSendOptions, requestPlugins?: (RequestPlugin | undefined)[]): Promise<any>;
50
+ /**
51
+ * 生成请求路径
52
+ * @param {RequestSendOptions} options 请求选项
53
+ * @param {RequestPlugin[]} plugins 请求插件
54
+ * @returns string
55
+ */
56
+ toURL(options: RequestSendOptions, plugins?: (RequestPlugin | undefined)[]): string;
57
+ }
58
+ //#endregion
59
+ //#region src/request-setup.d.ts
60
+ declare function setup(config: RequestSetupConfig): void;
61
+ //#endregion
62
+ export { AdapterResponse, AdapterResponseHeaders, PluginLifecycle, RequestAdapter, RequestAdapterOptions, RequestGenerateOptions, RequestGenerateType, RequestLifecycle, RequestMethod, RequestPlugin, RequestSendOptions, RequestService, RequestSetupConfig, ResponseInterceptor, ResponseLifecycle, setup };