@mx-space/api-client 0.3.5 → 0.3.6

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/build/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- // Generated by dts-bundle-generator v6.1.0
1
+ // Generated by dts-bundle-generator v6.2.0
2
2
 
3
3
  export type Class<T> = new (...args: any[]) => T;
4
4
  export type SelectFields<T extends string> = `${"+" | "-" | ""}${T}`[];
@@ -16,12 +16,16 @@ export interface RequestOptions {
16
16
  headers?: Record<string, string>;
17
17
  [key: string]: any;
18
18
  }
19
- export interface IRequestAdapter {
20
- get<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
21
- post<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
22
- patch<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
23
- delete<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
24
- put<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
19
+ export declare type RequestResponseType<P> = Promise<Record<string, any> & {
20
+ data: P;
21
+ }>;
22
+ export interface IRequestAdapter<T = any> {
23
+ default: T;
24
+ get<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
25
+ post<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
26
+ patch<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
27
+ delete<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
28
+ put<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
25
29
  }
26
30
  export declare type NoStringIndex<T> = {
27
31
  [K in keyof T as string extends K ? never : K]: T[K];
@@ -764,7 +768,7 @@ export declare class HTTPClient extends HTTPControllerDefine {
764
768
  injectControllers(...Controller: Class<IController>[]): void;
765
769
  injectControllers(Controller: Class<IController>[]): void;
766
770
  get endpoint(): string;
767
- get instance(): IRequestAdapter;
771
+ get instance(): IRequestAdapter<any>;
768
772
  request(options: {
769
773
  url: string;
770
774
  method?: string;
@@ -0,0 +1,3 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { IRequestAdapter } from "../interfaces/instance";
3
+ export declare const axiosAdaptor: IRequestAdapter<AxiosInstance>;
@@ -0,0 +1,46 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import axios from 'axios';
13
+ const $http = axios.create({});
14
+ // ignore axios `method` declare not assignable to `Method`
15
+ export const axiosAdaptor = {
16
+ get default() {
17
+ return $http;
18
+ },
19
+ get(url, options) {
20
+ // @ts-ignore
21
+ return $http.get(url, options);
22
+ },
23
+ post(url, options) {
24
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
25
+ // @ts-ignore
26
+ return $http.post(url, data, config);
27
+ },
28
+ put(url, options) {
29
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
30
+ // @ts-ignore
31
+ return $http.put(url, data, config);
32
+ },
33
+ delete(url, options) {
34
+ const config = __rest(options || {}
35
+ // @ts-ignore
36
+ , []);
37
+ // @ts-ignore
38
+ return $http.delete(url, config);
39
+ },
40
+ patch(url, options) {
41
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
42
+ // @ts-ignore
43
+ return $http.patch(url, data, config);
44
+ },
45
+ };
46
+ //# sourceMappingURL=axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.js","sourceRoot":"","sources":["../../src/adaptors/axios.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAE5C,MAAM,KAAK,GAAG,KAAK,C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od } from 'umi-request';
2
+ import { IRequestAdapter } from "../interfaces/instance";
3
+ export declare const umiAdaptor: IRequestAdapter<RequestMethod<true>>;
@@ -0,0 +1,27 @@
1
+ import { extend } from 'umi-request';
2
+ const $http = extend({
3
+ getResponse: true,
4
+ requestType: 'json',
5
+ responseType: 'json',
6
+ });
7
+ export const umiAdaptor = {
8
+ get default() {
9
+ return $http;
10
+ },
11
+ get(url, options) {
12
+ return $http.get(url, options);
13
+ },
14
+ post(url, options) {
15
+ return $http.post(url, options);
16
+ },
17
+ put(url, options) {
18
+ return $http.put(url, options);
19
+ },
20
+ delete(url, options) {
21
+ return $http.delete(url, options);
22
+ },
23
+ patch(url, options) {
24
+ return $http.patch(url, options);
25
+ },
26
+ };
27
+ //# sourceMappingURL=umi-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"umi-request.js","sourceRoot":"","sources":["../../src/adaptors/umi-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAiB,MAAM,aAAa,CAAA;AAEnD,MAAM,KAAK,GAAG,MAAM,CAAC;IACnB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,MAAM;CACrB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,UAAU,GAAyC;IAC9D,IAAI,OAAO;QACT,OAAO,KAAK,CAAA;IACd,CAAC;IACD,GAAG,CAAC,GAAG,EAAE,OAAO;QACd,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,OAAO;QACf,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC;IACD,GAAG,CAAC,GAAG,EAAE,OAAO;QACd,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IACD,MAAM,CAAC,GAAG,EAAE,OAAO;QACjB,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,OAAO;QAChB,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAClC,CAAC;CACF,CAAA"}
@@ -13,7 +13,7 @@ export declare class HTTPClient extends HTTPControllerDefine {
13
13
  injectControllers(...Controller: Class<IController>[]): void;
14
14
  injectControllers(Controller: Class<IController>[]): void;
15
15
  get endpoint(): string;
16
- get instance(): IRequestAdapter;
16
+ get instance(): IRequestAdapter<any>;
17
17
  request(options: {
18
18
  url: string;
19
19
  method?: string;
@@ -5,10 +5,15 @@ export interface RequestOptions {
5
5
  headers?: Record<string, string>;
6
6
  [key: string]: any;
7
7
  }
8
- export interface IRequestAdapter {
9
- get<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
10
- post<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
11
- patch<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
12
- delete<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
13
- put<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
8
+ declare type RequestResponseType<P> = Promise<Record<string, any> & {
9
+ data: P;
10
+ }>;
11
+ export interface IRequestAdapter<T = any> {
12
+ default: T;
13
+ get<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
14
+ post<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
15
+ patch<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
16
+ delete<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
17
+ put<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
14
18
  }
19
+ export {};
@@ -0,0 +1,3 @@
1
+ import { AxiosInstance } from 'axios';
2
+ import { IRequestAdapter } from "../interfaces/instance";
3
+ export declare const axiosAdaptor: IRequestAdapter<AxiosInstance>;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.axiosAdaptor = void 0;
18
+ const axios_1 = __importDefault(require("axios"));
19
+ const $http = axios_1.default.create({});
20
+ // ignore axios `method` declare not assignable to `Method`
21
+ exports.axiosAdaptor = {
22
+ get default() {
23
+ return $http;
24
+ },
25
+ get(url, options) {
26
+ // @ts-ignore
27
+ return $http.get(url, options);
28
+ },
29
+ post(url, options) {
30
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
31
+ // @ts-ignore
32
+ return $http.post(url, data, config);
33
+ },
34
+ put(url, options) {
35
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
36
+ // @ts-ignore
37
+ return $http.put(url, data, config);
38
+ },
39
+ delete(url, options) {
40
+ const config = __rest(options || {}
41
+ // @ts-ignore
42
+ , []);
43
+ // @ts-ignore
44
+ return $http.delete(url, config);
45
+ },
46
+ patch(url, options) {
47
+ const _a = options || {}, { data } = _a, config = __rest(_a, ["data"]);
48
+ // @ts-ignore
49
+ return $http.patch(url, data, config);
50
+ },
51
+ };
52
+ //# sourceMappingURL=axios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"axios.js","sourceRoot":"","sources":["../../src/adaptors/axios.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAA4C;AAE5C,MAAM,KAAK,GAAG,eAAK,CAAC,M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import { IRequestAdapter } from "../interfaces/instance";
3
+ export declare const umiAdaptor: IRequestAdapter<RequestMethod<true>>;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.umiAdaptor = void 0;
4
+ const umi_request_1 = require("umi-request");
5
+ const $http = (0, umi_request_1.extend)({
6
+ getResponse: true,
7
+ requestType: 'json',
8
+ responseType: 'json',
9
+ });
10
+ exports.umiAdaptor = {
11
+ get default() {
12
+ return $http;
13
+ },
14
+ get(url, options) {
15
+ return $http.get(url, options);
16
+ },
17
+ post(url, options) {
18
+ return $http.post(url, options);
19
+ },
20
+ put(url, options) {
21
+ return $http.put(url, options);
22
+ },
23
+ delete(url, options) {
24
+ return $http.delete(url, options);
25
+ },
26
+ patch(url, options) {
27
+ return $http.patch(url, options);
28
+ },
29
+ };
30
+ //# sourceMappingURL=umi-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"umi-request.js","sourceRoot":"","sources":["../../src/adaptors/umi-request.ts"],"names":[],"mappings":";;;AAAA,6CAAmD;AAEnD,MAAM,KAAK,GAAG,IAAA,oBAAM,EAAC;IACnB,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,MAAM;IACnB,YAAY,EAAE,MAAM;CACrB,CAAC,CAAA;AAEW,QAAA,UAAU,GAAyC;IAC9D,IAAI,OAAO;QACT,OAAO,KAAK,CAAA;IACd,CAAC;IACD,GAAG,CAAC,GAAG,EAAE,OAAO;QACd,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IACD,IAAI,CAAC,GAAG,EAAE,OAAO;QACf,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACjC,CAAC;IACD,GAAG,CAAC,GAAG,EAAE,OAAO;QACd,OAAO,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAChC,CAAC;IACD,MAAM,CAAC,GAAG,EAAE,OAAO;QACjB,OAAO,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACnC,CAAC;IACD,KAAK,CAAC,GAAG,EAAE,OAAO;QAChB,OAAO,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IAClC,CAAC;CACF,CAAA"}
@@ -13,7 +13,7 @@ export declare class HTTPClient extends HTTPControllerDefine {
13
13
  injectControllers(...Controller: Class<IController>[]): void;
14
14
  injectControllers(Controller: Class<IController>[]): void;
15
15
  get endpoint(): string;
16
- get instance(): IRequestAdapter;
16
+ get instance(): IRequestAdapter<any>;
17
17
  request(options: {
18
18
  url: string;
19
19
  method?: string;
@@ -5,10 +5,15 @@ export interface RequestOptions {
5
5
  headers?: Record<string, string>;
6
6
  [key: string]: any;
7
7
  }
8
- export interface IRequestAdapter {
9
- get<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
10
- post<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
11
- patch<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
12
- delete<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
13
- put<P = unknown>(url: string, options?: RequestOptions): Promise<P>;
8
+ declare type RequestResponseType<P> = Promise<Record<string, any> & {
9
+ data: P;
10
+ }>;
11
+ export interface IRequestAdapter<T = any> {
12
+ default: T;
13
+ get<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
14
+ post<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
15
+ patch<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
16
+ delete<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
17
+ put<P = unknown>(url: string, options?: RequestOptions): RequestResponseType<P>;
14
18
  }
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mx-space/api-client",
3
- "version": "0.3.5",
3
+ "version": "0.3.6",
4
4
  "description": "A api client for mx-space server@next",
5
5
  "author": "Innei",
6
6
  "license": "MIT",
@@ -54,7 +54,7 @@
54
54
  "preview": "vite preview --port 2323",
55
55
  "deploy": "vite build && gh-pages -d dist",
56
56
  "test": "jest --env=jsdom --colors --coverage test",
57
- "test:watch": "jest --env=jsdom --colors --coverage test --watch"
57
+ "test:watch": "jest --env=jsdom --colors --coverage test --watch -i --detectOpenHandles"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@innei-util/eslint-config-ts": "latest",
@@ -63,32 +63,36 @@
63
63
  "@rollup/plugin-commonjs": "21.0.1",
64
64
  "@rollup/plugin-node-resolve": "13.0.6",
65
65
  "@rollup/plugin-typescript": "8.3.0",
66
+ "@types/express": "4.17.13",
66
67
  "@types/jest": "27.0.3",
67
- "@types/lodash": "4.14.177",
68
- "@types/node": "16.11.11",
68
+ "@types/lodash": "4.14.178",
69
+ "@types/node": "16.11.12",
69
70
  "@types/react": "17.0.37",
70
71
  "@types/react-dom": "17.0.11",
71
72
  "@zerollup/ts-transform-paths": "1.7.18",
72
73
  "axios": "0.24.0",
73
- "dts-bundle-generator": "6.1.0",
74
- "esbuild": "0.14.0",
74
+ "cors": "2.8.5",
75
+ "dts-bundle-generator": "6.2.0",
76
+ "esbuild": "0.14.3",
77
+ "express": "4.17.1",
75
78
  "gh-pages": "3.2.3",
76
79
  "husky": "7.0.4",
77
- "jest": "27.4.0",
80
+ "jest": "27.4.4",
78
81
  "lint-staged": "12.1.2",
79
82
  "lodash": "4.17.21",
80
- "prettier": "2.5.0",
81
- "react": "18.0.0-beta-fdc1d617a-20211118",
82
- "react-dom": "18.0.0-beta-fdc1d617a-20211118",
83
+ "prettier": "2.5.1",
84
+ "react": "18.0.0-rc.0-next-f2a59df48-20211208",
85
+ "react-dom": "18.0.0-rc.0-next-f2a59df48-20211208",
83
86
  "react-json-view": "1.21.3",
84
- "rollup": "2.60.1",
87
+ "rollup": "2.61.0",
85
88
  "rollup-plugin-peer-deps-external": "2.2.4",
86
89
  "rollup-plugin-terser": "7.0.2",
87
- "ts-jest": "27.0.7",
90
+ "ts-jest": "27.1.1",
88
91
  "tslib": "2.3.1",
89
92
  "ttypescript": "1.5.13",
90
93
  "typescript": "4.4.4",
91
- "vite": "2.6.14",
94
+ "umi-request": "1.4.0",
95
+ "vite": "2.7.1",
92
96
  "vite-tsconfig-paths": "3.3.17"
93
97
  },
94
98
  "dependencies": {
package/readme.md CHANGED
@@ -1,64 +1,61 @@
1
- # Rollup Typescript library template
1
+ # MApi Client
2
2
 
3
- Please use pnpm do this.
3
+ 这是一个适用于 MServer v3 JS SDK,封装了常用接口请求方法以及返回类型的声明,以快速开发前端应用。
4
4
 
5
- ```sh
6
- pnpm i
7
- ```
5
+ ## 如何使用
8
6
 
9
- # Usage
7
+ SDK 设计之初不捆绑任何第三方网络请求库,同时也不使用任何请求方法。 使用适配器设计模式实现,你需要手动传入符合接口标准的适配器。
10
8
 
11
- ### Package
9
+ 此项目提供 `axios` 和 `umi-request` 两个适配器。
12
10
 
13
- Bundle your source code via tsc, rollup.
11
+ `axios` 为例。
14
12
 
15
- ```
16
- yarn package
17
- ```
13
+ ```ts
14
+ import { axiosAdaptor } from "@mx-space/api-client/esm/adaptors/axios";
15
+ import {
16
+ AggregateController,
17
+ CategoryController,
18
+ createClient,
19
+ NoteController,
20
+ PostController,
21
+ allControllers,
22
+ // ...
23
+ } from '@mx-space/api-client'
18
24
 
19
- ### Dev
25
+ const endpoint = 'https://api.innei.dev/v2'
26
+ const client = createClient(axiosAdaptor)(endpoint)
20
27
 
21
- Start dev mode by Vite.
28
+ // `default` is AxiosInstance
29
+ // you can do anything else on this
30
+ // interceptor or re-configure
31
+ const axios = axiosAdaptor.default
22
32
 
23
- ```
24
- yarn dev
25
- ```
33
+ // inject controller first.
34
+ client.injectControllers([
35
+ PostController,
36
+ NoteController,
37
+ AggregateController,
38
+ CategoryController,
39
+ ])
26
40
 
27
- ### Delopy
41
+ // or you can inject allControllers
42
+ client.injectControllers(allControllers)
28
43
 
29
- Delopy example to GitHub Pages.
44
+ // then you can request `post` `note` and `aggregate` controller
30
45
 
31
- ```
32
- yarn delopy
33
- yarn publish
46
+ client.post.post.getList(page, 10, { year }).then((data) => {
47
+ // do anything
48
+ })
34
49
  ```
35
50
 
36
- # Additional
51
+ **为什么要手动注入控制器**
37
52
 
38
- If you want to bundle React JSX with rollup. Add additional packages.
53
+ 按需加载,可以减少打包体积 (Tree Shake)
39
54
 
40
- ```
41
- pnpm i -D @babel/preset-react @babel/core @rollup/plugin-babel
42
- ```
43
-
44
- And, un-comment this in `.babelrc`.
45
-
46
- ```json
47
- {
48
- "presets": ["@babel/preset-react"]
49
- }
50
- ```
51
-
52
- Un-comment this in `rollup.config.js`
55
+ **为什么不依赖请求库**
53
56
 
54
- ```js
55
- import { babel } from '@rollup/plugin-babel'
57
+ 可以防止项目中出现两个请求库,减少打包体积
56
58
 
57
- // ...
59
+ **如果不使用 axios,应该如何编写适配器**
58
60
 
59
- plugins: [
60
- // ...
61
- babel({}),
62
- ],
63
- //...
64
- ```
61
+ 参考 `src/adaptors/axios.ts` 和 `src/adaptors/umi-request.ts`