axios-annotations 2.0.0 → 2.1.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 +53 -1
- package/index.d.ts +1 -1
- package/index.js +7 -1
- package/lib/core/expect.d.ts +4 -0
- package/lib/core/expect.js +15 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -115,8 +115,17 @@ ApiCommon.test.get("a","b",null);
|
|
|
115
115
|
]
|
|
116
116
|
}
|
|
117
117
|
```
|
|
118
|
+
tsconfig.json / jsconfig.json
|
|
119
|
+
```json
|
|
120
|
+
{
|
|
121
|
+
"compilerOptions": {
|
|
122
|
+
"experimentalDecorators": true,
|
|
123
|
+
"emitDecoratorMetadata": true
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
118
127
|
|
|
119
|
-
`vue-cli
|
|
128
|
+
`vue-cli`等脚手架已默认支持装饰器,微信小程序说明请拉到末尾。
|
|
120
129
|
<br>接口方法只需要处理和返回参数,并注解参数类型,框架根据注解分拆参数并注入`HTTP`请求。
|
|
121
130
|
|
|
122
131
|
```javascript
|
|
@@ -176,6 +185,49 @@ ApiCommon.test.get("a","b",null);
|
|
|
176
185
|
|
|
177
186
|
如果不爽部分IDE的`non-promise inspection info`下划线,也可以给方法加上`async`。
|
|
178
187
|
|
|
188
|
+
### 代码提示
|
|
189
|
+
|
|
190
|
+
> Expect<ResponseType, PromiseType = AxiosPromise<ResponseType>>
|
|
191
|
+
|
|
192
|
+
`Typescript`不支持装饰器修改方法返回值,但是可以绕开检查。<br/>
|
|
193
|
+
|
|
194
|
+
Using a method decorator can not change the function return type.<br/>
|
|
195
|
+
|
|
196
|
+
使用`Expect`绕过类型检查,获得代码提示功能。<br/>
|
|
197
|
+
|
|
198
|
+
Using `Expect` to bypass type-checking and get code intelligence.
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
import {Expect} from "axios-annotations";
|
|
202
|
+
|
|
203
|
+
// ...
|
|
204
|
+
|
|
205
|
+
export default class TestService extends Service {
|
|
206
|
+
@RequestBody()
|
|
207
|
+
@RequestMapping("/message", "POST")
|
|
208
|
+
@RequestHeader("Content-Type", "text/plain")
|
|
209
|
+
postMessage(message: string) {
|
|
210
|
+
return Expect<{
|
|
211
|
+
data: string;
|
|
212
|
+
success: boolean;
|
|
213
|
+
}>({
|
|
214
|
+
body: message
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
// call method, the return value can be deconstructed by IDE
|
|
220
|
+
|
|
221
|
+
const res: AxiosResponse<{
|
|
222
|
+
data:string;
|
|
223
|
+
success:boolean;
|
|
224
|
+
}> = await new TestService().postMessage("foo");
|
|
225
|
+
|
|
226
|
+
console.log(res.data.data);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
179
231
|
### QueryString Encoding
|
|
180
232
|
|
|
181
233
|
`key-values pair`转查询串算法,运行环境不支持`URLSearchParams`时使用默认算法,也可以自定义。
|
package/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Config, config, URLSearchParamsParser, AbortControllerAdapter, AxiosStaticInstanceProvider, Service, AbortSource, DeleteMapping, GetMapping, IgnoreResidualParams, PatchMapping, PostMapping, PutMapping, RequestBody, RequestConfig, RequestHeader, RequestMapping, RequestParam, RequestWith } from "./lib/index";
|
|
1
|
+
export { Config, config, URLSearchParamsParser, AbortControllerAdapter, AxiosStaticInstanceProvider, Service, AbortSource, DeleteMapping, GetMapping, IgnoreResidualParams, PatchMapping, PostMapping, PutMapping, RequestBody, RequestConfig, RequestHeader, RequestMapping, RequestParam, RequestWith, Expect } from "./lib/index";
|
package/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.RequestWith = exports.RequestParam = exports.RequestMapping = exports.RequestHeader = exports.RequestConfig = exports.RequestBody = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.IgnoreResidualParams = exports.GetMapping = exports.DeleteMapping = exports.AbortSource = exports.Service = exports.AxiosStaticInstanceProvider = exports.AbortControllerAdapter = exports.URLSearchParamsParser = exports.config = exports.Config = void 0;
|
|
6
|
+
exports.Expect = exports.RequestWith = exports.RequestParam = exports.RequestMapping = exports.RequestHeader = exports.RequestConfig = exports.RequestBody = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.IgnoreResidualParams = exports.GetMapping = exports.DeleteMapping = exports.AbortSource = exports.Service = exports.AxiosStaticInstanceProvider = exports.AbortControllerAdapter = exports.URLSearchParamsParser = exports.config = exports.Config = void 0;
|
|
7
7
|
var index_1 = require("./lib/index");
|
|
8
8
|
Object.defineProperty(exports, "Config", {
|
|
9
9
|
enumerable: true,
|
|
@@ -119,3 +119,9 @@ Object.defineProperty(exports, "RequestWith", {
|
|
|
119
119
|
return index_1.RequestWith;
|
|
120
120
|
}
|
|
121
121
|
});
|
|
122
|
+
Object.defineProperty(exports, "Expect", {
|
|
123
|
+
enumerable: true,
|
|
124
|
+
get: function get() {
|
|
125
|
+
return index_1.Expect;
|
|
126
|
+
}
|
|
127
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = Expect;
|
|
6
|
+
/**
|
|
7
|
+
* 警告 Warning: <br/>
|
|
8
|
+
* 仅用于仿冒使用装饰器的方法返回值,绕过IDE/Typescript的类型检查,获得代码提示功能。<br/>
|
|
9
|
+
*
|
|
10
|
+
* Only used to ensure the return value of a method that uses decorators,
|
|
11
|
+
* bypassing IDE/Typescript type checking and obtaining code intelligence.
|
|
12
|
+
*/
|
|
13
|
+
function Expect(params) {
|
|
14
|
+
return params;
|
|
15
|
+
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as Config } from "./core/config";
|
|
2
2
|
export { config } from "./core/config";
|
|
3
|
+
export { default as Expect } from "./core/expect";
|
|
3
4
|
export { default as URLSearchParamsParser } from "./core/parser";
|
|
4
5
|
export { default as Service } from "./core/service";
|
|
5
6
|
export { default as AbortControllerAdapter } from "./core/cancel";
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.RequestWith = exports.RequestParam = exports.RequestMapping = exports.RequestHeader = exports.RequestConfig = exports.RequestBody = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.IgnoreResidualParams = exports.GetMapping = exports.DeleteMapping = exports.AbortSource = exports.AxiosStaticInstanceProvider = exports.AbortControllerAdapter = exports.Service = exports.URLSearchParamsParser = exports.config = exports.Config = void 0;
|
|
6
|
+
exports.RequestWith = exports.RequestParam = exports.RequestMapping = exports.RequestHeader = exports.RequestConfig = exports.RequestBody = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.IgnoreResidualParams = exports.GetMapping = exports.DeleteMapping = exports.AbortSource = exports.AxiosStaticInstanceProvider = exports.AbortControllerAdapter = exports.Service = exports.URLSearchParamsParser = exports.Expect = exports.config = exports.Config = void 0;
|
|
7
7
|
var config_1 = require("./core/config");
|
|
8
8
|
Object.defineProperty(exports, "Config", {
|
|
9
9
|
enumerable: true,
|
|
@@ -18,6 +18,13 @@ Object.defineProperty(exports, "config", {
|
|
|
18
18
|
return config_2.config;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
+
var expect_1 = require("./core/expect");
|
|
22
|
+
Object.defineProperty(exports, "Expect", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function get() {
|
|
25
|
+
return expect_1["default"];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
21
28
|
var parser_1 = require("./core/parser");
|
|
22
29
|
Object.defineProperty(exports, "URLSearchParamsParser", {
|
|
23
30
|
enumerable: true,
|