@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/adapters/index.cjs +96 -124
- package/dist/adapters/index.d.cts +39 -0
- package/dist/adapters/index.d.mts +39 -0
- package/dist/adapters/index.mjs +77 -0
- package/dist/index-hNav9Ikc.d.mts +112 -0
- package/dist/index.cjs +241 -259
- package/dist/index.d.cts +71 -0
- package/dist/index.d.mts +62 -0
- package/dist/index.mjs +244 -0
- package/dist/request-adapter.interface-Cr5s4kIp.d.cts +103 -0
- package/package.json +34 -28
- package/dist/adapters/index.d.ts +0 -33
- package/dist/adapters/index.js +0 -97
- package/dist/chunk-XXPGZHWZ.js +0 -10
- package/dist/index.d.ts +0 -72
- package/dist/index.js +0 -226
- package/dist/request-plugin.interface-3df174bc.d.ts +0 -98
package/dist/index.cjs
CHANGED
|
@@ -1,268 +1,250 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
238
|
+
//#endregion
|
|
239
|
+
//#region src/request-setup.ts
|
|
238
240
|
function setup(config) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
+
RequestService.config = config;
|
|
242
|
+
RequestService.config?.adapter?.injectConfig?.(config);
|
|
241
243
|
}
|
|
242
244
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
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;
|
package/dist/index.d.cts
ADDED
|
@@ -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 };
|
package/dist/index.d.mts
ADDED
|
@@ -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 };
|