axios-annotations 2.1.0 → 2.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.
@@ -1,10 +1,10 @@
1
1
  import AxiosStaticInstanceProvider from "./provider";
2
- import type { AxiosInstance } from "axios";
3
- export type ConfigPlugin = (axios: AxiosInstance, config: Config) => void;
2
+ import type { AxiosInstance, AxiosStatic } from "axios";
3
+ export type ConfigPlugin<StaticType = AxiosStatic, InstanceType = AxiosInstance> = (axios: InstanceType, config: Config<StaticType, InstanceType>) => void;
4
4
  export type PartialConstructorString = string | null;
5
5
  export type PartialConstructorNumber = number | null;
6
- export type PartialPluginConstructorPlugins = ConfigPlugin[] | null;
7
- export default class Config {
6
+ export type PartialPluginConstructorPlugins<StaticType = AxiosStatic, InstanceType = AxiosInstance> = ConfigPlugin<StaticType, InstanceType>[] | null;
7
+ export default class Config<StaticType = AxiosStatic, InstanceType = AxiosInstance> {
8
8
  private _host;
9
9
  private _port;
10
10
  private _protocol;
@@ -17,11 +17,11 @@ export default class Config {
17
17
  host?: PartialConstructorString;
18
18
  port?: PartialConstructorNumber;
19
19
  prefix?: PartialConstructorString;
20
- plugins?: PartialPluginConstructorPlugins;
21
- axiosProvider?: AxiosStaticInstanceProvider;
20
+ plugins?: PartialPluginConstructorPlugins<StaticType, InstanceType>;
21
+ axiosProvider?: AxiosStaticInstanceProvider<StaticType>;
22
22
  });
23
23
  static forName(name: string): Config | null;
24
- init(protocol: PartialConstructorString, host: PartialConstructorString, port: PartialConstructorNumber, prefix: PartialConstructorString, plugins: PartialPluginConstructorPlugins): void;
24
+ init(protocol: PartialConstructorString, host: PartialConstructorString, port: PartialConstructorNumber, prefix: PartialConstructorString, plugins: PartialPluginConstructorPlugins<StaticType, InstanceType>): void;
25
25
  get host(): string;
26
26
  set host(value: string);
27
27
  get port(): number;
@@ -40,21 +40,21 @@ export default class Config {
40
40
  * return "http://localhost:8080/a"
41
41
  */
42
42
  get baseURL(): string;
43
- get plugins(): PartialPluginConstructorPlugins;
44
- set plugins(value: PartialPluginConstructorPlugins);
45
- get axiosProvider(): AxiosStaticInstanceProvider;
46
- set axiosProvider(value: AxiosStaticInstanceProvider);
43
+ get plugins(): PartialPluginConstructorPlugins<StaticType, InstanceType>;
44
+ set plugins(value: PartialPluginConstructorPlugins<StaticType, InstanceType>);
45
+ get axiosProvider(): AxiosStaticInstanceProvider<StaticType>;
46
+ set axiosProvider(value: AxiosStaticInstanceProvider<StaticType>);
47
47
  /**
48
48
  * register config global and return self.
49
49
  * @param name
50
50
  * @return {Config} config self
51
51
  */
52
- register(name: string): Config;
52
+ register(name: string): Config<StaticType, InstanceType>;
53
53
  /**
54
54
  * remove self from global config store.
55
55
  * @return {Config} - config self
56
56
  */
57
- unregister(): Config;
58
- requestAxiosInstance(): Promise<AxiosInstance>;
57
+ unregister(): Config<StaticType, InstanceType>;
58
+ requestAxiosInstance(): Promise<InstanceType>;
59
59
  }
60
- export declare const config: Config;
60
+ export declare const config: Config<AxiosStatic, AxiosInstance>;
@@ -1,4 +1,4 @@
1
- import type {AxiosPromise} from "axios";
2
-
3
- export default function Expect<T, D = AxiosPromise<T>>(params: any): D;
4
- export {};
1
+ import type {AxiosPromise} from "axios";
2
+
3
+ export default function Expect<T, D = AxiosPromise<T>>(params: any): D;
4
+ export {};
@@ -1,15 +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
- }
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
+ }
@@ -1,6 +1,6 @@
1
1
  import type { AxiosStatic } from "axios";
2
- export default class AxiosStaticInstanceProvider {
3
- __instance: AxiosStatic | null;
4
- provide(): Promise<AxiosStatic>;
5
- get(): Promise<AxiosStatic>;
2
+ export default class AxiosStaticInstanceProvider<StaticType = AxiosStatic> {
3
+ __instance: StaticType | null;
4
+ provide(): Promise<StaticType>;
5
+ get(): Promise<StaticType>;
6
6
  }
@@ -152,6 +152,12 @@ var AxiosStaticInstanceProvider = /** @class */ function() {
152
152
  return __generator(this, function(_b) {
153
153
  switch(_b.label){
154
154
  case 0:
155
+ if (this.__instance) {
156
+ return [
157
+ 2 /*return*/ ,
158
+ this.__instance
159
+ ];
160
+ }
155
161
  _a = this;
156
162
  return [
157
163
  4 /*yield*/ ,
@@ -35,8 +35,8 @@ export default class Service {
35
35
  _for: Record<string, string>;
36
36
  _features: Record<string, QueryStringEncodeFeatures>;
37
37
  constructor(path?: any);
38
- get config(): Config;
39
- set config(value: Config);
38
+ get config(): Config<import("axios").AxiosStatic, import("axios").AxiosInstance>;
39
+ set config(value: Config<import("axios").AxiosStatic, import("axios").AxiosInstance>);
40
40
  get path(): string;
41
41
  set path(value: string);
42
42
  params(id: string, name: string, config?: RequestParamEncodeRule): void;
@@ -1 +1 @@
1
- export default function DeleteMapping(path?: string): MethodDecorator;
1
+ export default function DeleteMapping<M = undefined>(path?: string): MethodDecorator;
@@ -1 +1 @@
1
- export default function GetMapping(path?: string): MethodDecorator;
1
+ export default function GetMapping<M = undefined>(path?: string): MethodDecorator;
@@ -1 +1 @@
1
- export default function PatchMapping(path?: string): MethodDecorator;
1
+ export default function PatchMapping<M = undefined>(path?: string): MethodDecorator;
@@ -1 +1 @@
1
- export default function PostMapping(path?: string): MethodDecorator;
1
+ export default function PostMapping<M = undefined>(path?: string): MethodDecorator;
@@ -1 +1 @@
1
- export default function PutMapping(path?: string): MethodDecorator;
1
+ export default function PutMapping<M = undefined>(path?: string): MethodDecorator;
@@ -1,3 +1,3 @@
1
1
  type DecoratorTargetType<M> = M extends string ? MethodDecorator : ClassDecorator;
2
- export default function RequestMapping<M = undefined>(path: string, method?: M): DecoratorTargetType<M>;
2
+ export default function RequestMapping<M = undefined>(path: string, method?: M | string): DecoratorTargetType<M>;
3
3
  export {};
package/package.json CHANGED
@@ -1,16 +1,16 @@
1
- {
2
- "name": "axios-annotations",
3
- "version": "2.1.0",
4
- "description": "HTTP client library uses Axios without Typescript.",
5
- "main": "index.js",
6
- "miniprogram": "lib",
7
- "miniprogramRoot": "lib",
8
- "keywords": [
9
- "axios",
10
- "axios-annotations",
11
- "axios-decorators"
12
- ],
13
- "author": "sitorhy",
14
- "license": "MIT",
15
- "homepage": "https://github.com/sitorhy/axios-annotations#readme"
16
- }
1
+ {
2
+ "name": "axios-annotations",
3
+ "version": "2.2.0",
4
+ "description": "HTTP client library uses Axios without Typescript.",
5
+ "main": "index.js",
6
+ "miniprogram": "lib",
7
+ "miniprogramRoot": "lib",
8
+ "keywords": [
9
+ "axios",
10
+ "axios-annotations",
11
+ "axios-decorators"
12
+ ],
13
+ "author": "sitorhy",
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/sitorhy/axios-annotations#readme"
16
+ }