@mx-space/api-client 0.3.3 → 0.3.7
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.cjs.js +59 -9
- package/build/index.cjs.js.map +1 -1
- package/build/index.cjs.min.js +1 -1
- package/build/index.cjs.min.js.map +1 -1
- package/build/index.d.ts +217 -128
- package/build/index.esm.js +59 -9
- package/build/index.esm.js.map +1 -1
- package/build/index.esm.min.js +1 -1
- package/build/index.esm.min.js.map +1 -1
- package/build/index.umd.js +59 -9
- package/build/index.umd.js.map +1 -1
- package/build/index.umd.min.js +1 -1
- package/build/index.umd.min.js.map +1 -1
- package/esm/adaptors/axios.d.ts +3 -0
- package/esm/adaptors/axios.js +46 -0
- package/esm/adaptors/axios.js.map +1 -0
- package/esm/adaptors/umi-request.d.ts +3 -0
- package/esm/adaptors/umi-request.js +27 -0
- package/esm/adaptors/umi-request.js.map +1 -0
- package/esm/core/client.d.ts +1 -1
- package/esm/core/controllers/aggregate.d.ts +5 -7
- package/esm/core/controllers/aggregate.js +2 -0
- package/esm/core/controllers/aggregate.js.map +1 -1
- package/esm/core/controllers/base.d.ts +5 -7
- package/esm/core/controllers/base.js +2 -0
- package/esm/core/controllers/base.js.map +1 -1
- package/esm/core/controllers/category.d.ts +6 -16
- package/esm/core/controllers/category.js +4 -2
- package/esm/core/controllers/category.js.map +1 -1
- package/esm/core/controllers/comment.d.ts +6 -8
- package/esm/core/controllers/comment.js +2 -0
- package/esm/core/controllers/comment.js.map +1 -1
- package/esm/core/controllers/link.js +2 -0
- package/esm/core/controllers/link.js.map +1 -1
- package/esm/core/controllers/note.d.ts +8 -10
- package/esm/core/controllers/note.js +2 -0
- package/esm/core/controllers/note.js.map +1 -1
- package/esm/core/controllers/page.js +2 -0
- package/esm/core/controllers/page.js.map +1 -1
- package/esm/core/controllers/post.js +2 -0
- package/esm/core/controllers/post.js.map +1 -1
- package/esm/core/controllers/project.js +2 -0
- package/esm/core/controllers/project.js.map +1 -1
- package/esm/core/controllers/recently.js +2 -0
- package/esm/core/controllers/recently.js.map +1 -1
- package/esm/core/controllers/say.js +2 -0
- package/esm/core/controllers/say.js.map +1 -1
- package/esm/core/controllers/search.d.ts +6 -6
- package/esm/core/controllers/search.js +2 -0
- package/esm/core/controllers/search.js.map +1 -1
- package/esm/core/controllers/snippet.js +2 -0
- package/esm/core/controllers/snippet.js.map +1 -1
- package/esm/core/controllers/user.js +2 -0
- package/esm/core/controllers/user.js.map +1 -1
- package/esm/interfaces/instance.d.ts +11 -6
- package/esm/models/aggregate.d.ts +2 -1
- package/esm/models/aggregate.js.map +1 -1
- package/esm/models/post.d.ts +1 -9
- package/esm/utils/auto-bind.d.ts +4 -0
- package/esm/utils/auto-bind.js +36 -0
- package/esm/utils/auto-bind.js.map +1 -0
- package/lib/adaptors/axios.d.ts +3 -0
- package/lib/adaptors/axios.js +52 -0
- package/lib/adaptors/axios.js.map +1 -0
- package/lib/adaptors/umi-request.d.ts +3 -0
- package/lib/adaptors/umi-request.js +30 -0
- package/lib/adaptors/umi-request.js.map +1 -0
- package/lib/core/client.d.ts +1 -1
- package/lib/core/controllers/aggregate.d.ts +5 -7
- package/lib/core/controllers/aggregate.js +2 -0
- package/lib/core/controllers/aggregate.js.map +1 -1
- package/lib/core/controllers/base.d.ts +5 -7
- package/lib/core/controllers/base.js +2 -0
- package/lib/core/controllers/base.js.map +1 -1
- package/lib/core/controllers/category.d.ts +6 -16
- package/lib/core/controllers/category.js +5 -3
- package/lib/core/controllers/category.js.map +1 -1
- package/lib/core/controllers/comment.d.ts +6 -8
- package/lib/core/controllers/comment.js +2 -0
- package/lib/core/controllers/comment.js.map +1 -1
- package/lib/core/controllers/link.js +2 -0
- package/lib/core/controllers/link.js.map +1 -1
- package/lib/core/controllers/note.d.ts +8 -10
- package/lib/core/controllers/note.js +2 -0
- package/lib/core/controllers/note.js.map +1 -1
- package/lib/core/controllers/page.js +2 -0
- package/lib/core/controllers/page.js.map +1 -1
- package/lib/core/controllers/post.js +2 -0
- package/lib/core/controllers/post.js.map +1 -1
- package/lib/core/controllers/project.js +2 -0
- package/lib/core/controllers/project.js.map +1 -1
- package/lib/core/controllers/recently.js +2 -0
- package/lib/core/controllers/recently.js.map +1 -1
- package/lib/core/controllers/say.js +2 -0
- package/lib/core/controllers/say.js.map +1 -1
- package/lib/core/controllers/search.d.ts +6 -6
- package/lib/core/controllers/search.js +2 -0
- package/lib/core/controllers/search.js.map +1 -1
- package/lib/core/controllers/snippet.js +2 -0
- package/lib/core/controllers/snippet.js.map +1 -1
- package/lib/core/controllers/user.js +2 -0
- package/lib/core/controllers/user.js.map +1 -1
- package/lib/interfaces/instance.d.ts +11 -6
- package/lib/models/aggregate.d.ts +2 -1
- package/lib/models/aggregate.js.map +1 -1
- package/lib/models/post.d.ts +1 -9
- package/lib/utils/auto-bind.d.ts +4 -0
- package/lib/utils/auto-bind.js +40 -0
- package/lib/utils/auto-bind.js.map +1 -0
- package/package.json +21 -17
- package/readme.md +77 -57
- package/esm/types/helper.d.ts +0 -2
- package/esm/types/helper.js +0 -2
- package/esm/types/helper.js.map +0 -1
- package/lib/types/helper.d.ts +0 -2
- package/lib/types/helper.js +0 -3
- package/lib/types/helper.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IController } from "../../interfaces/controller";
|
|
2
|
-
import { RequestProxyResult } from "../../interfaces/request";
|
|
2
|
+
import { IRequestHandler, RequestProxyResult } from "../../interfaces/request";
|
|
3
3
|
import { PaginateResult } from "../../models/base";
|
|
4
4
|
import { NoteModel } from "../../models/note";
|
|
5
5
|
import { PostModel } from "../../models/post";
|
|
@@ -14,7 +14,7 @@ export declare class SearchController implements IController {
|
|
|
14
14
|
base: string;
|
|
15
15
|
name: string;
|
|
16
16
|
constructor(client: HTTPClient);
|
|
17
|
-
get proxy():
|
|
17
|
+
get proxy(): IRequestHandler;
|
|
18
18
|
search(type: 'note', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'>>>>;
|
|
19
19
|
search(type: 'post', keyword: string, options?: Omit<SearchOption, 'rawAlgolia'>): Promise<RequestProxyResult<PaginateResult<Pick<PostModel, 'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'>>>>;
|
|
20
20
|
/**
|
|
@@ -24,14 +24,14 @@ export declare class SearchController implements IController {
|
|
|
24
24
|
* @param options
|
|
25
25
|
* @returns
|
|
26
26
|
*/
|
|
27
|
-
searchByAlgolia(keyword: string, options?: SearchOption): RequestProxyResult<RequestProxyResult<PaginateResult<Pick<PostModel, "
|
|
27
|
+
searchByAlgolia(keyword: string, options?: SearchOption): RequestProxyResult<RequestProxyResult<PaginateResult<Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category">> & {
|
|
28
28
|
/**
|
|
29
29
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
30
30
|
*/
|
|
31
31
|
raw?: any;
|
|
32
32
|
}, {
|
|
33
33
|
[key: string]: any;
|
|
34
|
-
data: PaginateResult<Pick<PostModel, "
|
|
34
|
+
data: PaginateResult<Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category">> & {
|
|
35
35
|
/**
|
|
36
36
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
37
37
|
*/
|
|
@@ -39,14 +39,14 @@ export declare class SearchController implements IController {
|
|
|
39
39
|
};
|
|
40
40
|
}>, {
|
|
41
41
|
[key: string]: any;
|
|
42
|
-
data: RequestProxyResult<PaginateResult<Pick<PostModel, "
|
|
42
|
+
data: RequestProxyResult<PaginateResult<Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category">> & {
|
|
43
43
|
/**
|
|
44
44
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
45
45
|
*/
|
|
46
46
|
raw?: any;
|
|
47
47
|
}, {
|
|
48
48
|
[key: string]: any;
|
|
49
|
-
data: PaginateResult<Pick<PostModel, "
|
|
49
|
+
data: PaginateResult<Pick<PostModel, "id" | "title" | "slug" | "modified" | "created" | "category">> & {
|
|
50
50
|
/**
|
|
51
51
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
52
52
|
*/
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SearchController = void 0;
|
|
4
|
+
const auto_bind_1 = require("../../utils/auto-bind");
|
|
4
5
|
class SearchController {
|
|
5
6
|
constructor(client) {
|
|
6
7
|
this.client = client;
|
|
7
8
|
this.base = 'search';
|
|
8
9
|
this.name = 'search';
|
|
10
|
+
(0, auto_bind_1.autoBind)(this);
|
|
9
11
|
}
|
|
10
12
|
get proxy() {
|
|
11
13
|
return this.client.proxy(this.base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/core/controllers/search.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../../src/core/controllers/search.ts"],"names":[],"mappings":";;;AAKA,qDAA4C;AAU5C,MAAa,gBAAgB;IAI3B,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAH/C,SAAI,GAAG,QAAQ,CAAA;QACf,SAAI,GAAG,QAAQ,CAAA;QAGb,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IA2BD,MAAM,CACJ,IAAgB,EAChB,OAAe,EACf,UAA4C,EAAE;QAE9C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC;YAC1B,MAAM,kBAAI,OAAO,IAAK,OAAO,CAAE;SAChC,CAAC,CAAA;IACJ,CAAC;IACD;;;;;;OAMG;IACH,eAAe,CAAC,OAAe,EAAE,OAAsB;QACrD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,GAAG,CAc9B,EAAE,MAAM,kBAAI,OAAO,IAAK,OAAO,CAAE,EAAE,CAAC,CAAA;IACxC,CAAC;CACF;AAtED,4CAsEC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.SnippetController = void 0;
|
|
4
|
+
const auto_bind_1 = require("../../utils/auto-bind");
|
|
4
5
|
class SnippetController {
|
|
5
6
|
constructor(client) {
|
|
6
7
|
this.client = client;
|
|
7
8
|
this.base = 'snippets';
|
|
8
9
|
this.name = 'snippet';
|
|
10
|
+
(0, auto_bind_1.autoBind)(this);
|
|
9
11
|
}
|
|
10
12
|
get proxy() {
|
|
11
13
|
return this.client.proxy(this.base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../../src/core/controllers/snippet.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"snippet.js","sourceRoot":"","sources":["../../../src/core/controllers/snippet.ts"],"names":[],"mappings":";;;AAEA,qDAA4C;AAG5C,MAAa,iBAAiB;IAI5B,YAAsB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAHxC,SAAI,GAAG,UAAU,CAAA;QACjB,SAAI,GAAG,SAAS,CAAA;QAGd,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,OAAO,CAAC,EAAU;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,EAAgB,CAAA;IAC3C,CAAC;IAED,qBAAqB,CAAC,SAAiB,EAAE,IAAY;QACnD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAgB,CAAA;IACxD,CAAC;CACF;AAnBD,8CAmBC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UserController = void 0;
|
|
4
|
+
const auto_bind_1 = require("../../utils/auto-bind");
|
|
4
5
|
class UserController {
|
|
5
6
|
constructor(client) {
|
|
6
7
|
this.client = client;
|
|
7
8
|
this.base = 'master';
|
|
8
9
|
this.name = 'user';
|
|
10
|
+
(0, auto_bind_1.autoBind)(this);
|
|
9
11
|
}
|
|
10
12
|
get proxy() {
|
|
11
13
|
return this.client.proxy(this.base);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/core/controllers/user.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/core/controllers/user.ts"],"names":[],"mappings":";;;AAEA,qDAA4C;AAG5C,MAAa,cAAc;IACzB,YAA6B,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;QAI/C,SAAI,GAAG,QAAQ,CAAA;QAEf,SAAI,GAAG,MAAM,CAAA;QALX,IAAA,oBAAQ,EAAC,IAAI,CAAC,CAAA;IAChB,CAAC;IAMD,IAAc,KAAK;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,CAAC;IAED,aAAa;QACX,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,EAAa,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,QAAgB,EAAE,QAAgB;QACtC,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAS;YACnC,IAAI,EAAE;gBACJ,QAAQ;gBACR,QAAQ;aACT;SACF,CAAC,CAAA;IACJ,CAAC;IAED,eAAe,CAAC,KAAa;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAmC;YACnE,MAAM,EAAE;gBACN,KAAK;aACN;SACF,CAAC,CAAA;IACJ,CAAC;CACF;AAjCD,wCAiCC"}
|
|
@@ -5,10 +5,15 @@ export interface RequestOptions {
|
|
|
5
5
|
headers?: Record<string, string>;
|
|
6
6
|
[key: string]: any;
|
|
7
7
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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 {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { CategoryModel } from './category';
|
|
1
2
|
import { NoteModel } from './note';
|
|
2
3
|
import { PageModel } from './page';
|
|
3
|
-
import {
|
|
4
|
+
import { PostModel } from './post';
|
|
4
5
|
import { SayModel } from './say';
|
|
5
6
|
import { SeoOptionModel } from './setting';
|
|
6
7
|
import { UserModel } from './user';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../src/models/aggregate.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"aggregate.js","sourceRoot":"","sources":["../../src/models/aggregate.ts"],"names":[],"mappings":";;;AAsBA,IAAY,YAGX;AAHD,WAAY,YAAY;IACtB,+CAAI,CAAA;IACJ,+CAAI,CAAA;AACN,CAAC,EAHW,YAAY,GAAZ,oBAAY,KAAZ,oBAAY,QAGvB"}
|
package/lib/models/post.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Count, Image } from './base';
|
|
2
|
+
import { CategoryModel } from './category';
|
|
2
3
|
export interface PostModel {
|
|
3
4
|
commentsIndex: number;
|
|
4
5
|
allowComment: boolean;
|
|
@@ -16,12 +17,3 @@ export interface PostModel {
|
|
|
16
17
|
created: string;
|
|
17
18
|
category: CategoryModel;
|
|
18
19
|
}
|
|
19
|
-
export interface CategoryModel {
|
|
20
|
-
type: number;
|
|
21
|
-
count: number;
|
|
22
|
-
id: string;
|
|
23
|
-
name: string;
|
|
24
|
-
slug: string;
|
|
25
|
-
created: Date;
|
|
26
|
-
categoryId: string;
|
|
27
|
-
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// @copy: https://github.com/sindresorhus/auto-bind/blob/main/index.js
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.autoBind = void 0;
|
|
6
|
+
// Gets all non-builtin properties up the prototype chain.
|
|
7
|
+
const getAllProperties = (object) => {
|
|
8
|
+
const properties = new Set();
|
|
9
|
+
do {
|
|
10
|
+
for (const key of Reflect.ownKeys(object)) {
|
|
11
|
+
properties.add([object, key]);
|
|
12
|
+
}
|
|
13
|
+
} while ((object = Reflect.getPrototypeOf(object)) &&
|
|
14
|
+
object !== Object.prototype);
|
|
15
|
+
return properties;
|
|
16
|
+
};
|
|
17
|
+
function autoBind(self, { include, exclude } = {}) {
|
|
18
|
+
const filter = (key) => {
|
|
19
|
+
const match = (pattern) => typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
|
20
|
+
if (include) {
|
|
21
|
+
return include.some(match);
|
|
22
|
+
}
|
|
23
|
+
if (exclude) {
|
|
24
|
+
return !exclude.some(match);
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
};
|
|
28
|
+
for (const [object, key] of getAllProperties(self.constructor.prototype)) {
|
|
29
|
+
if (key === 'constructor' || !filter(key)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(object, key);
|
|
33
|
+
if (descriptor && typeof descriptor.value === 'function') {
|
|
34
|
+
self[key] = self[key].bind(self);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return self;
|
|
38
|
+
}
|
|
39
|
+
exports.autoBind = autoBind;
|
|
40
|
+
//# sourceMappingURL=auto-bind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-bind.js","sourceRoot":"","sources":["../../src/utils/auto-bind.ts"],"names":[],"mappings":";AAAA,cAAc;AACd,sEAAsE;;;AAEtE,0DAA0D;AAC1D,MAAM,gBAAgB,GAAG,CAAC,MAAM,EAAE,EAAE;IAClC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;IAE5B,GAAG;QACD,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;YACzC,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;SAC9B;KACF,QACC,CAAC,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QACzC,MAAM,KAAK,MAAM,CAAC,SAAS,EAC5B;IAED,OAAO,UAAU,CAAA;AACnB,CAAC,CAAA;AAED,SAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE;IACtD,MAAM,MAAM,GAAG,CAAC,GAAG,EAAE,EAAE;QACrB,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,EAAE,CACxB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QAEnE,IAAI,OAAO,EAAE;YACX,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC3B;QAED,IAAI,OAAO,EAAE;YACX,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;SAC5B;QAED,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,EAAE;QACxE,IAAI,GAAG,KAAK,aAAa,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;YACzC,SAAQ;SACT;QAED,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;QAChE,IAAI,UAAU,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE;YACxD,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;SACjC;KACF;IAED,OAAO,IAAI,CAAA;AACb,CAAC;AA5BD,4BA4BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mx-space/api-client",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "A api client for mx-space server@next",
|
|
5
5
|
"author": "Innei",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,52 +43,56 @@
|
|
|
43
43
|
"scripts": {
|
|
44
44
|
"prepare": "husky install",
|
|
45
45
|
"predeploy": "rm -rf dist",
|
|
46
|
+
"prebuild": "rm -rf rm -rf lib && rm -rf esm",
|
|
46
47
|
"build": "ttsc --build src/tsconfig.build.json && ttsc --build src/tsconfig.cjs.json",
|
|
47
48
|
"package": "NODE_ENV=production npm run build && rollup -c",
|
|
48
49
|
"postpackage": "dts-bundle-generator -o build/index.d.ts src/index.ts --project tsconfig.json --no-check",
|
|
49
|
-
"prepackage": "rm -rf
|
|
50
|
+
"prepackage": "rm -rf build",
|
|
50
51
|
"release": "vv",
|
|
51
52
|
"dev": "vite",
|
|
52
53
|
"build:vite": "vite build",
|
|
53
54
|
"preview": "vite preview --port 2323",
|
|
54
55
|
"deploy": "vite build && gh-pages -d dist",
|
|
55
56
|
"test": "jest --env=jsdom --colors --coverage test",
|
|
56
|
-
"test:watch": "jest --env=jsdom --colors --coverage test --watch"
|
|
57
|
+
"test:watch": "jest --env=jsdom --colors --coverage test --watch -i --detectOpenHandles"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@innei-util/eslint-config-ts": "latest",
|
|
60
61
|
"@innei-util/prettier": "latest",
|
|
61
62
|
"@innei/bump-version": "0.1.5",
|
|
62
63
|
"@rollup/plugin-commonjs": "21.0.1",
|
|
63
|
-
"@rollup/plugin-node-resolve": "13.
|
|
64
|
+
"@rollup/plugin-node-resolve": "13.1.1",
|
|
64
65
|
"@rollup/plugin-typescript": "8.3.0",
|
|
66
|
+
"@types/express": "4.17.13",
|
|
65
67
|
"@types/jest": "27.0.3",
|
|
66
|
-
"@types/lodash": "4.14.
|
|
67
|
-
"@types/node": "16.11.
|
|
68
|
+
"@types/lodash": "4.14.178",
|
|
69
|
+
"@types/node": "16.11.12",
|
|
68
70
|
"@types/react": "17.0.37",
|
|
69
71
|
"@types/react-dom": "17.0.11",
|
|
70
72
|
"@zerollup/ts-transform-paths": "1.7.18",
|
|
71
73
|
"axios": "0.24.0",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
+
"cors": "2.8.5",
|
|
75
|
+
"dts-bundle-generator": "6.2.0",
|
|
76
|
+
"esbuild": "0.14.3",
|
|
77
|
+
"express": "4.17.1",
|
|
74
78
|
"gh-pages": "3.2.3",
|
|
75
79
|
"husky": "7.0.4",
|
|
76
|
-
"jest": "27.
|
|
77
|
-
"lint-staged": "
|
|
80
|
+
"jest": "27.4.5",
|
|
81
|
+
"lint-staged": "12.1.2",
|
|
78
82
|
"lodash": "4.17.21",
|
|
79
|
-
"prettier": "2.5.
|
|
80
|
-
"react": "18.0.0-
|
|
81
|
-
"react-dom": "18.0.0-
|
|
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",
|
|
82
86
|
"react-json-view": "1.21.3",
|
|
83
|
-
"rollup": "2.
|
|
87
|
+
"rollup": "2.61.0",
|
|
84
88
|
"rollup-plugin-peer-deps-external": "2.2.4",
|
|
85
89
|
"rollup-plugin-terser": "7.0.2",
|
|
86
|
-
"ts-jest": "27.
|
|
87
|
-
"tsconfig-replace-paths": "0.0.11",
|
|
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
|
-
"
|
|
94
|
+
"umi-request": "1.4.0",
|
|
95
|
+
"vite": "2.7.2",
|
|
92
96
|
"vite-tsconfig-paths": "3.3.17"
|
|
93
97
|
},
|
|
94
98
|
"dependencies": {
|
package/readme.md
CHANGED
|
@@ -1,64 +1,84 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
# MApi Client
|
|
2
|
+
|
|
3
|
+
这是一个适用于 MServer v3 的 JS SDK,封装了常用接口请求方法以及返回类型的声明,以快速开发前端应用。
|
|
4
|
+
|
|
5
|
+
## 如何使用
|
|
6
|
+
|
|
7
|
+
此 SDK 设计之初不捆绑任何第三方网络请求库,同时也不使用任何请求方法。 使用适配器设计模式实现,你需要手动传入符合接口标准的适配器。
|
|
8
|
+
|
|
9
|
+
此项目提供 `axios` 和 `umi-request` 两个适配器。
|
|
10
|
+
|
|
11
|
+
以 `axios` 为例。
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// esm format (spa recommend)
|
|
15
|
+
import { axiosAdaptor } from '@mx-space/api-client/esm/adaptors/axios'
|
|
16
|
+
// cjs format (ssr recommend)
|
|
17
|
+
// import { axiosAdaptor } from '@mx-space/api-client/lib/adaptors/axios'
|
|
18
|
+
import {
|
|
19
|
+
AggregateController,
|
|
20
|
+
CategoryController,
|
|
21
|
+
createClient,
|
|
22
|
+
NoteController,
|
|
23
|
+
PostController,
|
|
24
|
+
allControllers,
|
|
25
|
+
// ...
|
|
26
|
+
} from '@mx-space/api-client'
|
|
27
|
+
|
|
28
|
+
const endpoint = 'https://api.innei.dev/v2'
|
|
29
|
+
const client = createClient(axiosAdaptor)(endpoint)
|
|
30
|
+
|
|
31
|
+
// `default` is AxiosInstance
|
|
32
|
+
// you can do anything else on this
|
|
33
|
+
// interceptor or re-configure
|
|
34
|
+
const $axios = axiosAdaptor.default
|
|
35
|
+
// re-config (optional)
|
|
36
|
+
$axios.defaults.timeout = 10000
|
|
37
|
+
// set interceptors (optional)
|
|
38
|
+
$axios.interceptors.request.use(
|
|
39
|
+
(config) => {
|
|
40
|
+
const token = getToken()
|
|
41
|
+
if (token) {
|
|
42
|
+
config.headers!['Authorization'] = 'bearer ' + getToken()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return config
|
|
46
|
+
},
|
|
47
|
+
(error) => {
|
|
48
|
+
if (__DEV__) {
|
|
49
|
+
console.log(error.message)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return Promise.reject(error)
|
|
53
|
+
},
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
// inject controller first.
|
|
57
|
+
client.injectControllers([
|
|
58
|
+
PostController,
|
|
59
|
+
NoteController,
|
|
60
|
+
AggregateController,
|
|
61
|
+
CategoryController,
|
|
62
|
+
])
|
|
63
|
+
|
|
64
|
+
// or you can inject allControllers
|
|
65
|
+
client.injectControllers(allControllers)
|
|
66
|
+
|
|
67
|
+
// then you can request `post` `note` and `aggregate` controller
|
|
68
|
+
|
|
69
|
+
client.post.post.getList(page, 10, { year }).then((data) => {
|
|
70
|
+
// do anything
|
|
71
|
+
})
|
|
7
72
|
```
|
|
8
73
|
|
|
9
|
-
|
|
74
|
+
**为什么要手动注入控制器**
|
|
10
75
|
|
|
11
|
-
|
|
76
|
+
按需加载,可以减少打包体积 (Tree Shake)
|
|
12
77
|
|
|
13
|
-
|
|
78
|
+
**为什么不依赖请求库**
|
|
14
79
|
|
|
15
|
-
|
|
16
|
-
yarn package
|
|
17
|
-
```
|
|
80
|
+
可以防止项目中出现两个请求库,减少打包体积
|
|
18
81
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
Start dev mode by Vite.
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
yarn dev
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### Delopy
|
|
28
|
-
|
|
29
|
-
Delopy example to GitHub Pages.
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
yarn delopy
|
|
33
|
-
yarn publish
|
|
34
|
-
```
|
|
82
|
+
**如果不使用 axios,应该如何编写适配器**
|
|
35
83
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
If you want to bundle React JSX with rollup. Add additional packages.
|
|
39
|
-
|
|
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`
|
|
53
|
-
|
|
54
|
-
```js
|
|
55
|
-
import { babel } from '@rollup/plugin-babel'
|
|
56
|
-
|
|
57
|
-
// ...
|
|
58
|
-
|
|
59
|
-
plugins: [
|
|
60
|
-
// ...
|
|
61
|
-
babel({}),
|
|
62
|
-
],
|
|
63
|
-
//...
|
|
64
|
-
```
|
|
84
|
+
参考 `src/adaptors/axios.ts` 和 `src/adaptors/umi-request.ts`
|
package/esm/types/helper.d.ts
DELETED
package/esm/types/helper.js
DELETED
package/esm/types/helper.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/types/helper.ts"],"names":[],"mappings":""}
|
package/lib/types/helper.d.ts
DELETED
package/lib/types/helper.js
DELETED
package/lib/types/helper.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"helper.js","sourceRoot":"","sources":["../../src/types/helper.ts"],"names":[],"mappings":""}
|