axios-annotations 2.3.0 → 3.0.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/README.md +774 -741
- package/es/core/builder.d.ts +33 -0
- package/es/core/builder.js +515 -0
- package/es/core/common.d.ts +36 -0
- package/es/core/common.js +148 -0
- package/es/core/config.d.ts +60 -0
- package/es/core/config.js +357 -0
- package/es/core/core-expect.js +3 -0
- package/es/core/expect.d.ts +2 -0
- package/es/core/expect.js +2 -0
- package/es/core/provider.d.ts +6 -0
- package/es/core/provider.js +172 -0
- package/es/core/service.d.ts +5 -0
- package/es/core/service.js +56 -0
- package/es/decorator/path-variables.d.ts +7 -0
- package/es/decorator/path-variables.js +32 -0
- package/es/decorator/request-body.d.ts +7 -0
- package/es/decorator/request-body.js +31 -0
- package/es/decorator/request-config.d.ts +7 -0
- package/es/decorator/request-config.js +25 -0
- package/es/decorator/request-header.d.ts +4 -0
- package/es/decorator/request-header.js +14 -0
- package/es/decorator/request-mapping.d.ts +6 -0
- package/es/decorator/request-mapping.js +56 -0
- package/es/decorator/request-param.d.ts +4 -0
- package/es/decorator/request-param.js +15 -0
- package/es/decorator/request-with.d.ts +3 -0
- package/es/decorator/request-with.js +8 -0
- package/es/index.d.ts +13 -0
- package/es/index.js +14 -0
- package/es/plugins/auth/authorizer.d.ts +24 -0
- package/es/plugins/auth/authorizer.js +268 -0
- package/es/plugins/auth/history.d.ts +15 -0
- package/es/plugins/auth/history.js +94 -0
- package/es/plugins/auth/index.d.ts +16 -0
- package/es/plugins/auth/index.js +358 -0
- package/es/plugins/auth/queue.d.ts +29 -0
- package/es/plugins/auth/queue.js +281 -0
- package/es/plugins/auth/storage.d.ts +6 -0
- package/es/plugins/auth/storage.js +203 -0
- package/lib/core/builder.d.ts +33 -0
- package/lib/core/builder.js +520 -0
- package/lib/core/common.d.ts +34 -4
- package/lib/core/common.js +139 -147
- package/lib/core/config.d.ts +15 -15
- package/lib/core/config.js +44 -14
- package/lib/core/core-expect.js +8 -0
- package/lib/core/expect.d.ts +2 -4
- package/lib/core/expect.js +6 -15
- package/lib/core/provider.d.ts +5 -5
- package/lib/core/provider.js +2 -2
- package/lib/core/service.d.ts +3 -151
- package/lib/core/service.js +42 -544
- package/lib/decorator/path-variables.d.ts +7 -0
- package/lib/decorator/path-variables.js +37 -0
- package/lib/decorator/request-body.d.ts +7 -1
- package/lib/decorator/request-body.js +28 -20
- package/lib/decorator/request-config.d.ts +6 -4
- package/lib/decorator/request-config.js +23 -16
- package/lib/decorator/request-header.d.ts +4 -2
- package/lib/decorator/request-header.js +11 -13
- package/lib/decorator/request-mapping.d.ts +6 -3
- package/lib/decorator/request-mapping.js +46 -43
- package/lib/decorator/request-param.d.ts +4 -1
- package/lib/decorator/request-param.js +12 -19
- package/lib/decorator/request-with.d.ts +3 -1
- package/lib/decorator/request-with.js +6 -13
- package/lib/index.d.ts +4 -11
- package/lib/index.js +19 -68
- package/lib/plugins/auth/authorizer.d.ts +6 -5
- package/lib/plugins/auth/authorizer.js +3 -2
- package/lib/plugins/auth/history.d.ts +5 -4
- package/lib/plugins/auth/history.js +2 -0
- package/lib/plugins/auth/index.d.ts +7 -0
- package/lib/plugins/auth/index.js +11 -3
- package/lib/plugins/auth/queue.d.ts +3 -2
- package/lib/plugins/auth/queue.js +31 -24
- package/lib/plugins/auth/storage.js +2 -2
- package/package.json +42 -7
- package/wechat-mp/core/builder.d.ts +33 -0
- package/wechat-mp/core/builder.js +520 -0
- package/wechat-mp/core/common.d.ts +36 -0
- package/wechat-mp/core/common.js +158 -0
- package/wechat-mp/core/config.d.ts +60 -0
- package/wechat-mp/core/config.js +362 -0
- package/wechat-mp/core/core-expect.js +8 -0
- package/wechat-mp/core/expect.d.ts +2 -0
- package/wechat-mp/core/expect.js +6 -0
- package/wechat-mp/core/provider.d.ts +6 -0
- package/wechat-mp/core/provider.js +178 -0
- package/wechat-mp/core/service.d.ts +5 -0
- package/wechat-mp/core/service.js +60 -0
- package/wechat-mp/decorator/path-variables.d.ts +7 -0
- package/wechat-mp/decorator/path-variables.js +37 -0
- package/wechat-mp/decorator/request-body.d.ts +7 -0
- package/wechat-mp/decorator/request-body.js +36 -0
- package/wechat-mp/decorator/request-config.d.ts +7 -0
- package/wechat-mp/decorator/request-config.js +30 -0
- package/wechat-mp/decorator/request-header.d.ts +4 -0
- package/wechat-mp/decorator/request-header.js +19 -0
- package/wechat-mp/decorator/request-mapping.d.ts +6 -0
- package/wechat-mp/decorator/request-mapping.js +61 -0
- package/wechat-mp/decorator/request-param.d.ts +4 -0
- package/wechat-mp/decorator/request-param.js +20 -0
- package/wechat-mp/decorator/request-with.d.ts +3 -0
- package/wechat-mp/decorator/request-with.js +13 -0
- package/wechat-mp/index.d.ts +13 -0
- package/wechat-mp/index.js +97 -0
- package/wechat-mp/plugins/auth/authorizer.d.ts +24 -0
- package/wechat-mp/plugins/auth/authorizer.js +272 -0
- package/wechat-mp/plugins/auth/history.d.ts +15 -0
- package/wechat-mp/plugins/auth/history.js +98 -0
- package/wechat-mp/plugins/auth/index.d.ts +16 -0
- package/wechat-mp/plugins/auth/index.js +376 -0
- package/wechat-mp/plugins/auth/queue.d.ts +29 -0
- package/wechat-mp/plugins/auth/queue.js +285 -0
- package/wechat-mp/plugins/auth/storage.d.ts +6 -0
- package/wechat-mp/plugins/auth/storage.js +207 -0
- package/index.d.ts +0 -1
- package/index.js +0 -127
- package/lib/core/cancel.d.ts +0 -30
- package/lib/core/cancel.js +0 -56
- package/lib/core/parser.d.ts +0 -19
- package/lib/core/parser.js +0 -79
- package/lib/decorator/abort-source.d.ts +0 -3
- package/lib/decorator/abort-source.js +0 -25
- package/lib/decorator/delete-mapping.d.ts +0 -1
- package/lib/decorator/delete-mapping.js +0 -13
- package/lib/decorator/get-mapping.d.ts +0 -1
- package/lib/decorator/get-mapping.js +0 -13
- package/lib/decorator/ignore-residual-params.d.ts +0 -1
- package/lib/decorator/ignore-residual-params.js +0 -24
- package/lib/decorator/patch-mapping.d.ts +0 -1
- package/lib/decorator/patch-mapping.js +0 -13
- package/lib/decorator/post-mapping.d.ts +0 -1
- package/lib/decorator/post-mapping.js +0 -13
- package/lib/decorator/put-mapping.d.ts +0 -1
- package/lib/decorator/put-mapping.js +0 -13
- package/plugins/auth/index.d.ts +0 -4
- package/plugins/auth/index.js +0 -26
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
function _type_of(obj) {
|
|
2
|
+
"@swc/helpers - typeof";
|
|
3
|
+
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
4
|
+
}
|
|
5
|
+
var __values = this && this.__values || function(o) {
|
|
6
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
7
|
+
if (m) return m.call(o);
|
|
8
|
+
if (o && typeof o.length === "number") return {
|
|
9
|
+
next: function next() {
|
|
10
|
+
if (o && i >= o.length) o = void 0;
|
|
11
|
+
return {
|
|
12
|
+
value: o && o[i++],
|
|
13
|
+
done: !o
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
18
|
+
};
|
|
19
|
+
import RequestBuilder from "./builder.js";
|
|
20
|
+
export function normalizePath(path) {
|
|
21
|
+
return path.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
22
|
+
}
|
|
23
|
+
export function isNullOrEmpty(param) {
|
|
24
|
+
return param === null || param === undefined || param === "";
|
|
25
|
+
}
|
|
26
|
+
export function castToMetaDescriptor(descriptor) {
|
|
27
|
+
if (!descriptor.builder) {
|
|
28
|
+
descriptor.builder = new RequestBuilder();
|
|
29
|
+
}
|
|
30
|
+
return descriptor;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Merges multiple Axios request configurations with specific logic for Axios.
|
|
34
|
+
* - `headers` and `params` are shallowly merged.
|
|
35
|
+
* - All other properties are replaced by the last provided value.
|
|
36
|
+
*
|
|
37
|
+
* @param sources A list of AxiosRequestConfig objects to merge.
|
|
38
|
+
* @returns A new, merged AxiosRequestConfig object.
|
|
39
|
+
*/ export function mergeAxiosConfigs() {
|
|
40
|
+
var e_1, _a, e_2, _b;
|
|
41
|
+
var sources = [];
|
|
42
|
+
for(var _i = 0; _i < arguments.length; _i++){
|
|
43
|
+
sources[_i] = arguments[_i];
|
|
44
|
+
}
|
|
45
|
+
// Start with an empty config
|
|
46
|
+
var finalConfig = {};
|
|
47
|
+
try {
|
|
48
|
+
// Sequentially apply all source configs. This handles the "replacement" logic for most properties.
|
|
49
|
+
for(var sources_1 = __values(sources), sources_1_1 = sources_1.next(); !sources_1_1.done; sources_1_1 = sources_1.next()){
|
|
50
|
+
var source = sources_1_1.value;
|
|
51
|
+
if (source) {
|
|
52
|
+
Object.assign(finalConfig, source);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
} catch (e_1_1) {
|
|
56
|
+
e_1 = {
|
|
57
|
+
error: e_1_1
|
|
58
|
+
};
|
|
59
|
+
} finally{
|
|
60
|
+
try {
|
|
61
|
+
if (sources_1_1 && !sources_1_1.done && (_a = sources_1["return"])) _a.call(sources_1);
|
|
62
|
+
} finally{
|
|
63
|
+
if (e_1) throw e_1.error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Now, handle the special merge logic for 'headers' and 'params'
|
|
67
|
+
var finalHeaders = {};
|
|
68
|
+
var finalParams = {};
|
|
69
|
+
try {
|
|
70
|
+
for(var sources_2 = __values(sources), sources_2_1 = sources_2.next(); !sources_2_1.done; sources_2_1 = sources_2.next()){
|
|
71
|
+
var source = sources_2_1.value;
|
|
72
|
+
if (source === null || source === void 0 ? void 0 : source.headers) {
|
|
73
|
+
Object.assign(finalHeaders, source.headers);
|
|
74
|
+
}
|
|
75
|
+
if (source === null || source === void 0 ? void 0 : source.params) {
|
|
76
|
+
Object.assign(finalParams, source.params);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch (e_2_1) {
|
|
80
|
+
e_2 = {
|
|
81
|
+
error: e_2_1
|
|
82
|
+
};
|
|
83
|
+
} finally{
|
|
84
|
+
try {
|
|
85
|
+
if (sources_2_1 && !sources_2_1.done && (_b = sources_2["return"])) _b.call(sources_2);
|
|
86
|
+
} finally{
|
|
87
|
+
if (e_2) throw e_2.error;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// Assign the merged headers and params back to the final config
|
|
91
|
+
if (Object.keys(finalHeaders).length > 0) {
|
|
92
|
+
finalConfig.headers = finalHeaders;
|
|
93
|
+
}
|
|
94
|
+
if (Object.keys(finalParams).length > 0) {
|
|
95
|
+
finalConfig.params = finalParams;
|
|
96
|
+
}
|
|
97
|
+
return finalConfig;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 替换链接占位符,注意使用基本类型
|
|
101
|
+
* Replaces placeholders in a URL with values from a data object.
|
|
102
|
+
* e.g., formatUrl("http://a.com/{c}?d={e}", {c: 'x', e: 100}) -> "http://a.com/x?d=100"
|
|
103
|
+
*
|
|
104
|
+
* @param url The URL string with placeholders like {key}.
|
|
105
|
+
* @param data The plain object data source.
|
|
106
|
+
* @returns The formatted URL string.
|
|
107
|
+
*/ export function formatUrl(url, data) {
|
|
108
|
+
return url.replace(/\{([^{}]+)}/g, function(match, key) {
|
|
109
|
+
// Check if the key exists in the data object
|
|
110
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
111
|
+
var value = data[key];
|
|
112
|
+
// Handle null, undefined, NaN
|
|
113
|
+
if (value === null) return 'null';
|
|
114
|
+
if (value === undefined) return 'undefined';
|
|
115
|
+
if (Number.isNaN(value)) return 'NaN';
|
|
116
|
+
var valueType = typeof value === "undefined" ? "undefined" : _type_of(value);
|
|
117
|
+
// Handle primitive types
|
|
118
|
+
if (valueType === 'string' || valueType === 'number' || valueType === 'boolean') {
|
|
119
|
+
return String(value);
|
|
120
|
+
}
|
|
121
|
+
// Handle objects and arrays
|
|
122
|
+
try {
|
|
123
|
+
// 此处不应该触发 不要传奇怪的类型
|
|
124
|
+
return JSON.stringify(value);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
// 如果取出的值不是基本类型(例如数组),则直接JSON.stringify后替换,JSON转换过程抛异常则替换为 undefined
|
|
127
|
+
console.error("Error stringify value for key \"".concat(key, "\":"), e);
|
|
128
|
+
return 'undefined'; // Replace with 'undefined' on stringify error
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// If key is not found in data, return the original placeholder
|
|
132
|
+
return match;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Checks if a value is a plain object, i.e., an object created by `{}` or `new Object()`.
|
|
137
|
+
* @param value The value to check.
|
|
138
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
139
|
+
*/ export function isPlainObject(value) {
|
|
140
|
+
if (value === null || (typeof value === "undefined" ? "undefined" : _type_of(value)) !== 'object') {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
var proto = Object.getPrototypeOf(value);
|
|
144
|
+
if (proto === null) {
|
|
145
|
+
return true;
|
|
146
|
+
}
|
|
147
|
+
return proto === Object.prototype;
|
|
148
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { AxiosInstance } from 'axios';
|
|
2
|
+
import AxiosStaticInstanceProvider from "./provider";
|
|
3
|
+
export type ConfigPlugin = (axios: AxiosInstance, config: Config) => void;
|
|
4
|
+
export type PartialConstructorString = string | null;
|
|
5
|
+
export type PartialConstructorNumber = number | null;
|
|
6
|
+
export type PartialPluginConstructorPlugins = ConfigPlugin[] | null;
|
|
7
|
+
export default class Config {
|
|
8
|
+
private _host;
|
|
9
|
+
private _port;
|
|
10
|
+
private _protocol;
|
|
11
|
+
private _prefix;
|
|
12
|
+
private _axiosProvider;
|
|
13
|
+
private _axios;
|
|
14
|
+
private _plugins;
|
|
15
|
+
constructor(options?: {
|
|
16
|
+
protocol?: PartialConstructorString;
|
|
17
|
+
host?: PartialConstructorString;
|
|
18
|
+
port?: PartialConstructorNumber;
|
|
19
|
+
prefix?: PartialConstructorString;
|
|
20
|
+
plugins?: PartialPluginConstructorPlugins;
|
|
21
|
+
axiosProvider?: AxiosStaticInstanceProvider;
|
|
22
|
+
});
|
|
23
|
+
static forName(name: string): Config | null;
|
|
24
|
+
init(protocol: PartialConstructorString, host: PartialConstructorString, port: PartialConstructorNumber, prefix: PartialConstructorString, plugins: PartialPluginConstructorPlugins): void;
|
|
25
|
+
get host(): string;
|
|
26
|
+
set host(value: string);
|
|
27
|
+
get port(): number;
|
|
28
|
+
set port(value: number);
|
|
29
|
+
get protocol(): string;
|
|
30
|
+
set protocol(value: string);
|
|
31
|
+
get prefix(): string;
|
|
32
|
+
set prefix(value: string);
|
|
33
|
+
/**
|
|
34
|
+
* default value: <br/>
|
|
35
|
+
* http://localhost:8080
|
|
36
|
+
*/
|
|
37
|
+
get origin(): string;
|
|
38
|
+
/**
|
|
39
|
+
* if prefix = "/a" <br/>
|
|
40
|
+
* return "http://localhost:8080/a"
|
|
41
|
+
*/
|
|
42
|
+
get baseURL(): string;
|
|
43
|
+
get plugins(): PartialPluginConstructorPlugins;
|
|
44
|
+
set plugins(value: PartialPluginConstructorPlugins);
|
|
45
|
+
get axiosProvider(): AxiosStaticInstanceProvider;
|
|
46
|
+
set axiosProvider(value: AxiosStaticInstanceProvider);
|
|
47
|
+
/**
|
|
48
|
+
* register config global and return self.
|
|
49
|
+
* @param name
|
|
50
|
+
* @return {Config} config self
|
|
51
|
+
*/
|
|
52
|
+
register(name: string): Config;
|
|
53
|
+
/**
|
|
54
|
+
* remove self from global config store.
|
|
55
|
+
* @return {Config} - config self
|
|
56
|
+
*/
|
|
57
|
+
unregister(): Config;
|
|
58
|
+
requestAxiosInstance(): Promise<AxiosInstance>;
|
|
59
|
+
}
|
|
60
|
+
export declare const config: Config;
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
8
|
+
function fulfilled(value) {
|
|
9
|
+
try {
|
|
10
|
+
step(generator.next(value));
|
|
11
|
+
} catch (e) {
|
|
12
|
+
reject(e);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function rejected(value) {
|
|
16
|
+
try {
|
|
17
|
+
step(generator["throw"](value));
|
|
18
|
+
} catch (e) {
|
|
19
|
+
reject(e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function step(result) {
|
|
23
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
24
|
+
}
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
29
|
+
var _ = {
|
|
30
|
+
label: 0,
|
|
31
|
+
sent: function sent() {
|
|
32
|
+
if (t[0] & 1) throw t[1];
|
|
33
|
+
return t[1];
|
|
34
|
+
},
|
|
35
|
+
trys: [],
|
|
36
|
+
ops: []
|
|
37
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
38
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
39
|
+
return this;
|
|
40
|
+
}), g;
|
|
41
|
+
function verb(n) {
|
|
42
|
+
return function(v) {
|
|
43
|
+
return step([
|
|
44
|
+
n,
|
|
45
|
+
v
|
|
46
|
+
]);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [
|
|
54
|
+
op[0] & 2,
|
|
55
|
+
t.value
|
|
56
|
+
];
|
|
57
|
+
switch(op[0]){
|
|
58
|
+
case 0:
|
|
59
|
+
case 1:
|
|
60
|
+
t = op;
|
|
61
|
+
break;
|
|
62
|
+
case 4:
|
|
63
|
+
_.label++;
|
|
64
|
+
return {
|
|
65
|
+
value: op[1],
|
|
66
|
+
done: false
|
|
67
|
+
};
|
|
68
|
+
case 5:
|
|
69
|
+
_.label++;
|
|
70
|
+
y = op[1];
|
|
71
|
+
op = [
|
|
72
|
+
0
|
|
73
|
+
];
|
|
74
|
+
continue;
|
|
75
|
+
case 7:
|
|
76
|
+
op = _.ops.pop();
|
|
77
|
+
_.trys.pop();
|
|
78
|
+
continue;
|
|
79
|
+
default:
|
|
80
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
81
|
+
_ = 0;
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
85
|
+
_.label = op[1];
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
89
|
+
_.label = t[1];
|
|
90
|
+
t = op;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (t && _.label < t[2]) {
|
|
94
|
+
_.label = t[2];
|
|
95
|
+
_.ops.push(op);
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
if (t[2]) _.ops.pop();
|
|
99
|
+
_.trys.pop();
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
op = body.call(thisArg, _);
|
|
103
|
+
} catch (e) {
|
|
104
|
+
op = [
|
|
105
|
+
6,
|
|
106
|
+
e
|
|
107
|
+
];
|
|
108
|
+
y = 0;
|
|
109
|
+
} finally{
|
|
110
|
+
f = t = 0;
|
|
111
|
+
}
|
|
112
|
+
if (op[0] & 5) throw op[1];
|
|
113
|
+
return {
|
|
114
|
+
value: op[0] ? op[1] : void 0,
|
|
115
|
+
done: true
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var __values = this && this.__values || function(o) {
|
|
120
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
121
|
+
if (m) return m.call(o);
|
|
122
|
+
if (o && typeof o.length === "number") return {
|
|
123
|
+
next: function next() {
|
|
124
|
+
if (o && i >= o.length) o = void 0;
|
|
125
|
+
return {
|
|
126
|
+
value: o && o[i++],
|
|
127
|
+
done: !o
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
132
|
+
};
|
|
133
|
+
import AxiosStaticInstanceProvider from "./provider.js";
|
|
134
|
+
var _global_configs = [];
|
|
135
|
+
var Config = /** @class */ function() {
|
|
136
|
+
function Config(options) {
|
|
137
|
+
this._host = "localhost";
|
|
138
|
+
this._port = 8080;
|
|
139
|
+
this._protocol = "http";
|
|
140
|
+
this._prefix = "";
|
|
141
|
+
this._axiosProvider = new AxiosStaticInstanceProvider();
|
|
142
|
+
this._axios = null;
|
|
143
|
+
this._plugins = null;
|
|
144
|
+
if (options === null || options === void 0 ? void 0 : options.axiosProvider) {
|
|
145
|
+
this._axiosProvider = options === null || options === void 0 ? void 0 : options.axiosProvider;
|
|
146
|
+
}
|
|
147
|
+
this.init((options === null || options === void 0 ? void 0 : options.protocol) || null, (options === null || options === void 0 ? void 0 : options.host) || null, (options === null || options === void 0 ? void 0 : options.port) || null, (options === null || options === void 0 ? void 0 : options.prefix) || null, (options === null || options === void 0 ? void 0 : options.plugins) || null);
|
|
148
|
+
}
|
|
149
|
+
Config.forName = function(name) {
|
|
150
|
+
var c = _global_configs.find(function(i) {
|
|
151
|
+
return i.name === name;
|
|
152
|
+
});
|
|
153
|
+
if (c) {
|
|
154
|
+
return c.config;
|
|
155
|
+
} else {
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
Config.prototype.init = function(protocol, host, port, prefix, plugins) {
|
|
160
|
+
if (port) {
|
|
161
|
+
this.port = port;
|
|
162
|
+
}
|
|
163
|
+
if (protocol) {
|
|
164
|
+
this.protocol = protocol;
|
|
165
|
+
}
|
|
166
|
+
if (host) {
|
|
167
|
+
this.host = host;
|
|
168
|
+
}
|
|
169
|
+
if (prefix) {
|
|
170
|
+
this.prefix = prefix;
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(plugins)) {
|
|
173
|
+
this._plugins = plugins;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
Object.defineProperty(Config.prototype, "host", {
|
|
177
|
+
get: function get() {
|
|
178
|
+
return this._host;
|
|
179
|
+
},
|
|
180
|
+
set: function set(value) {
|
|
181
|
+
this._host = value;
|
|
182
|
+
},
|
|
183
|
+
enumerable: false,
|
|
184
|
+
configurable: true
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(Config.prototype, "port", {
|
|
187
|
+
get: function get() {
|
|
188
|
+
return this._port;
|
|
189
|
+
},
|
|
190
|
+
set: function set(value) {
|
|
191
|
+
this._port = value;
|
|
192
|
+
},
|
|
193
|
+
enumerable: false,
|
|
194
|
+
configurable: true
|
|
195
|
+
});
|
|
196
|
+
Object.defineProperty(Config.prototype, "protocol", {
|
|
197
|
+
get: function get() {
|
|
198
|
+
return this._protocol;
|
|
199
|
+
},
|
|
200
|
+
set: function set(value) {
|
|
201
|
+
this._protocol = value;
|
|
202
|
+
},
|
|
203
|
+
enumerable: false,
|
|
204
|
+
configurable: true
|
|
205
|
+
});
|
|
206
|
+
Object.defineProperty(Config.prototype, "prefix", {
|
|
207
|
+
get: function get() {
|
|
208
|
+
return this._prefix;
|
|
209
|
+
},
|
|
210
|
+
set: function set(value) {
|
|
211
|
+
this._prefix = value;
|
|
212
|
+
},
|
|
213
|
+
enumerable: false,
|
|
214
|
+
configurable: true
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(Config.prototype, "origin", {
|
|
217
|
+
/**
|
|
218
|
+
* default value: <br/>
|
|
219
|
+
* http://localhost:8080
|
|
220
|
+
*/ get: function get() {
|
|
221
|
+
var port = this.protocol === "https" && String(this.port) === "443" || this.protocol === "http" && String(this.port) === "80" ? "" : this.port;
|
|
222
|
+
return "".concat(this.protocol, "://").concat(this.host).concat(port ? ":" + port : "");
|
|
223
|
+
},
|
|
224
|
+
enumerable: false,
|
|
225
|
+
configurable: true
|
|
226
|
+
});
|
|
227
|
+
Object.defineProperty(Config.prototype, "baseURL", {
|
|
228
|
+
/**
|
|
229
|
+
* if prefix = "/a" <br/>
|
|
230
|
+
* return "http://localhost:8080/a"
|
|
231
|
+
*/ get: function get() {
|
|
232
|
+
return "".concat(this.origin).concat(this.prefix);
|
|
233
|
+
},
|
|
234
|
+
enumerable: false,
|
|
235
|
+
configurable: true
|
|
236
|
+
});
|
|
237
|
+
Object.defineProperty(Config.prototype, "plugins", {
|
|
238
|
+
get: function get() {
|
|
239
|
+
return this._plugins;
|
|
240
|
+
},
|
|
241
|
+
set: function set(value) {
|
|
242
|
+
this._plugins = value;
|
|
243
|
+
},
|
|
244
|
+
enumerable: false,
|
|
245
|
+
configurable: true
|
|
246
|
+
});
|
|
247
|
+
Object.defineProperty(Config.prototype, "axiosProvider", {
|
|
248
|
+
get: function get() {
|
|
249
|
+
return this._axiosProvider;
|
|
250
|
+
},
|
|
251
|
+
set: function set(value) {
|
|
252
|
+
this._axiosProvider = value;
|
|
253
|
+
},
|
|
254
|
+
enumerable: false,
|
|
255
|
+
configurable: true
|
|
256
|
+
});
|
|
257
|
+
/**
|
|
258
|
+
* register config global and return self.
|
|
259
|
+
* @param name
|
|
260
|
+
* @return {Config} config self
|
|
261
|
+
*/ Config.prototype.register = function(name) {
|
|
262
|
+
var _this = this;
|
|
263
|
+
var c = _global_configs.find(function(i) {
|
|
264
|
+
return i.config === _this;
|
|
265
|
+
});
|
|
266
|
+
if (c) {
|
|
267
|
+
c.name = name;
|
|
268
|
+
} else {
|
|
269
|
+
_global_configs.push({
|
|
270
|
+
name: name,
|
|
271
|
+
config: this
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return this;
|
|
275
|
+
};
|
|
276
|
+
// noinspection JSUnusedGlobalSymbols
|
|
277
|
+
/**
|
|
278
|
+
* remove self from global config store.
|
|
279
|
+
* @return {Config} - config self
|
|
280
|
+
*/ Config.prototype.unregister = function() {
|
|
281
|
+
var _this = this;
|
|
282
|
+
var index = _global_configs.findIndex(function(i) {
|
|
283
|
+
return i.config === _this;
|
|
284
|
+
});
|
|
285
|
+
if (index >= 0) {
|
|
286
|
+
_global_configs.splice(index, 1);
|
|
287
|
+
}
|
|
288
|
+
return this;
|
|
289
|
+
};
|
|
290
|
+
// 创建 axios 实例
|
|
291
|
+
Config.prototype.requestAxiosInstance = function() {
|
|
292
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
293
|
+
var _a, e_1, _b, _c, plugin;
|
|
294
|
+
var e_2, _d;
|
|
295
|
+
return __generator(this, function(_e) {
|
|
296
|
+
switch(_e.label){
|
|
297
|
+
case 0:
|
|
298
|
+
if (this._axios) {
|
|
299
|
+
return [
|
|
300
|
+
2 /*return*/ ,
|
|
301
|
+
this._axios
|
|
302
|
+
];
|
|
303
|
+
}
|
|
304
|
+
_e.label = 1;
|
|
305
|
+
case 1:
|
|
306
|
+
_e.trys.push([
|
|
307
|
+
1,
|
|
308
|
+
3,
|
|
309
|
+
,
|
|
310
|
+
4
|
|
311
|
+
]);
|
|
312
|
+
_a = this;
|
|
313
|
+
return [
|
|
314
|
+
4 /*yield*/ ,
|
|
315
|
+
this._axiosProvider.get()
|
|
316
|
+
];
|
|
317
|
+
case 2:
|
|
318
|
+
_a._axios = _e.sent().create();
|
|
319
|
+
return [
|
|
320
|
+
3 /*break*/ ,
|
|
321
|
+
4
|
|
322
|
+
];
|
|
323
|
+
case 3:
|
|
324
|
+
e_1 = _e.sent();
|
|
325
|
+
throw e_1;
|
|
326
|
+
case 4:
|
|
327
|
+
// 插件注入
|
|
328
|
+
if (this._plugins && this._plugins.length) {
|
|
329
|
+
try {
|
|
330
|
+
for(_b = __values(this._plugins), _c = _b.next(); !_c.done; _c = _b.next()){
|
|
331
|
+
plugin = _c.value;
|
|
332
|
+
plugin(this._axios, this);
|
|
333
|
+
}
|
|
334
|
+
} catch (e_2_1) {
|
|
335
|
+
e_2 = {
|
|
336
|
+
error: e_2_1
|
|
337
|
+
};
|
|
338
|
+
} finally{
|
|
339
|
+
try {
|
|
340
|
+
if (_c && !_c.done && (_d = _b["return"])) _d.call(_b);
|
|
341
|
+
} finally{
|
|
342
|
+
if (e_2) throw e_2.error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return [
|
|
347
|
+
2 /*return*/ ,
|
|
348
|
+
this._axios
|
|
349
|
+
];
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
return Config;
|
|
355
|
+
}();
|
|
356
|
+
export default Config;
|
|
357
|
+
export var config = new Config();
|