@mx-space/api-client 0.7.0 → 0.7.1
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/adaptors/axios.ts +34 -32
- package/adaptors/umi-request.ts +25 -22
- package/build/index.cjs.js +12 -32
- 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.esm.js +13 -32
- 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 +12 -32
- 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/controllers/aggregate.ts +9 -5
- package/controllers/base.ts +3 -3
- package/controllers/category.ts +18 -7
- package/controllers/comment.ts +10 -6
- package/controllers/link.ts +11 -4
- package/controllers/note.ts +11 -7
- package/controllers/page.ts +10 -5
- package/controllers/post.ts +15 -8
- package/controllers/project.ts +10 -3
- package/controllers/recently.ts +10 -5
- package/controllers/say.ts +10 -5
- package/controllers/search.ts +14 -7
- package/controllers/snippet.ts +9 -4
- package/controllers/user.ts +10 -5
- package/core/attach-request.ts +1 -1
- package/core/client.ts +37 -47
- package/coverage/clover.xml +281 -274
- package/coverage/coverage-final.json +20 -20
- package/coverage/lcov-report/adaptors/axios.ts.html +48 -42
- package/coverage/lcov-report/adaptors/index.html +24 -24
- package/coverage/lcov-report/adaptors/umi-request.ts.html +42 -33
- package/coverage/lcov-report/auto-bind.ts.html +229 -0
- package/coverage/lcov-report/controllers/aggregate.ts.html +20 -8
- package/coverage/lcov-report/controllers/base.ts.html +4 -4
- package/coverage/lcov-report/controllers/category.ts.html +43 -10
- package/coverage/lcov-report/controllers/comment.ts.html +21 -9
- package/coverage/lcov-report/controllers/index.html +1 -1
- package/coverage/lcov-report/controllers/index.ts.html +2 -2
- package/coverage/lcov-report/controllers/link.ts.html +28 -7
- package/coverage/lcov-report/controllers/note.ts.html +21 -9
- package/coverage/lcov-report/controllers/page.ts.html +22 -7
- package/coverage/lcov-report/controllers/post.ts.html +37 -16
- package/coverage/lcov-report/controllers/project.ts.html +27 -6
- package/coverage/lcov-report/controllers/recently.ts.html +23 -8
- package/coverage/lcov-report/controllers/say.ts.html +23 -8
- package/coverage/lcov-report/controllers/search.ts.html +31 -10
- package/coverage/lcov-report/controllers/snippet.ts.html +22 -7
- package/coverage/lcov-report/controllers/user.ts.html +23 -8
- package/coverage/lcov-report/core/attach-request.ts.html +13 -13
- package/coverage/lcov-report/core/client.ts.html +120 -150
- package/coverage/lcov-report/core/error.ts.html +1 -1
- package/coverage/lcov-report/core/index.html +18 -18
- package/coverage/lcov-report/core/index.ts.html +1 -1
- package/coverage/lcov-report/index.html +26 -26
- package/coverage/lcov-report/index.ts.html +244 -0
- package/coverage/lcov-report/models/aggregate.ts.html +1 -1
- package/coverage/lcov-report/models/category.ts.html +1 -1
- package/coverage/lcov-report/models/index.html +1 -1
- package/coverage/lcov-report/utils/auto-bind.ts.html +18 -18
- package/coverage/lcov-report/utils/index.html +1 -1
- package/coverage/lcov-report/utils/index.ts.html +3 -3
- package/coverage/lcov.info +496 -485
- package/esm/adaptors/axios.d.ts +2 -2
- package/esm/adaptors/axios.js +1 -0
- package/esm/adaptors/axios.js.map +1 -1
- package/esm/adaptors/umi-request.d.ts +2 -2
- package/esm/adaptors/umi-request.js +1 -0
- package/esm/adaptors/umi-request.js.map +1 -1
- package/esm/controllers/aggregate.d.ts +25 -8
- package/esm/controllers/aggregate.js.map +1 -1
- package/esm/controllers/base.d.ts +17 -5
- package/esm/controllers/category.d.ts +64 -13
- package/esm/controllers/category.js.map +1 -1
- package/esm/controllers/comment.d.ts +42 -10
- package/esm/controllers/comment.js.map +1 -1
- package/esm/controllers/link.d.ts +5 -4
- package/esm/controllers/link.js.map +1 -1
- package/esm/controllers/note.d.ts +42 -12
- package/esm/controllers/note.js.map +1 -1
- package/esm/controllers/page.d.ts +22 -8
- package/esm/controllers/page.js.map +1 -1
- package/esm/controllers/post.d.ts +24 -11
- package/esm/controllers/post.js.map +1 -1
- package/esm/controllers/project.d.ts +4 -3
- package/esm/controllers/project.js.map +1 -1
- package/esm/controllers/recently.d.ts +30 -8
- package/esm/controllers/recently.js.map +1 -1
- package/esm/controllers/say.d.ts +15 -5
- package/esm/controllers/say.js.map +1 -1
- package/esm/controllers/search.d.ts +168 -9
- package/esm/controllers/search.js.map +1 -1
- package/esm/controllers/snippet.d.ts +16 -6
- package/esm/controllers/snippet.js.map +1 -1
- package/esm/controllers/user.d.ts +28 -8
- package/esm/controllers/user.js.map +1 -1
- package/esm/core/attach-request.d.ts +1 -1
- package/esm/core/attach-request.js.map +1 -1
- package/esm/core/client.d.ts +9 -6
- package/esm/core/client.js +13 -32
- package/esm/core/client.js.map +1 -1
- package/esm/index.d.ts +2 -1
- package/esm/index.js +1 -1
- package/esm/index.js.map +1 -1
- package/esm/interfaces/adapter.d.ts +9 -8
- package/esm/interfaces/client.d.ts +1 -1
- package/esm/interfaces/request.d.ts +22 -13
- package/esm/interfaces/types.d.ts +2 -0
- package/esm/interfaces/types.js +2 -0
- package/esm/interfaces/types.js.map +1 -0
- package/index.ts +2 -1
- package/interfaces/adapter.ts +29 -24
- package/interfaces/client.ts +1 -1
- package/interfaces/request.ts +45 -20
- package/{types/helper.d.ts → interfaces/types.ts} +0 -0
- package/lib/adaptors/axios.d.ts +2 -2
- package/lib/adaptors/axios.js +1 -0
- package/lib/adaptors/axios.js.map +1 -1
- package/lib/adaptors/umi-request.d.ts +2 -2
- package/lib/adaptors/umi-request.js +1 -0
- package/lib/adaptors/umi-request.js.map +1 -1
- package/lib/controllers/aggregate.d.ts +25 -8
- package/lib/controllers/aggregate.js.map +1 -1
- package/lib/controllers/base.d.ts +17 -5
- package/lib/controllers/category.d.ts +64 -13
- package/lib/controllers/category.js.map +1 -1
- package/lib/controllers/comment.d.ts +42 -10
- package/lib/controllers/comment.js.map +1 -1
- package/lib/controllers/link.d.ts +5 -4
- package/lib/controllers/link.js.map +1 -1
- package/lib/controllers/note.d.ts +42 -12
- package/lib/controllers/note.js.map +1 -1
- package/lib/controllers/page.d.ts +22 -8
- package/lib/controllers/page.js.map +1 -1
- package/lib/controllers/post.d.ts +24 -11
- package/lib/controllers/post.js.map +1 -1
- package/lib/controllers/project.d.ts +4 -3
- package/lib/controllers/project.js.map +1 -1
- package/lib/controllers/recently.d.ts +30 -8
- package/lib/controllers/recently.js.map +1 -1
- package/lib/controllers/say.d.ts +15 -5
- package/lib/controllers/say.js.map +1 -1
- package/lib/controllers/search.d.ts +168 -9
- package/lib/controllers/search.js.map +1 -1
- package/lib/controllers/snippet.d.ts +16 -6
- package/lib/controllers/snippet.js.map +1 -1
- package/lib/controllers/user.d.ts +28 -8
- package/lib/controllers/user.js.map +1 -1
- package/lib/core/attach-request.d.ts +1 -1
- package/lib/core/attach-request.js.map +1 -1
- package/lib/core/client.d.ts +9 -6
- package/lib/core/client.js +13 -33
- package/lib/core/client.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces/adapter.d.ts +9 -8
- package/lib/interfaces/client.d.ts +1 -1
- package/lib/interfaces/request.d.ts +22 -13
- package/lib/interfaces/types.d.ts +2 -0
- package/lib/interfaces/types.js +3 -0
- package/lib/interfaces/types.js.map +1 -0
- package/package.json +5 -5
- package/tsconfig.json +25 -4
- package/tsconfig.types.json +18 -0
- package/types/adaptors/axios.d.ts +3 -0
- package/types/adaptors/umi-request.d.ts +3 -0
- package/types/controllers/aggregate.d.ts +64 -0
- package/types/controllers/base.d.ts +39 -0
- package/types/controllers/category.d.ts +114 -0
- package/types/controllers/comment.d.ts +81 -0
- package/types/controllers/index.d.ts +16 -0
- package/types/controllers/link.d.ts +16 -0
- package/types/controllers/note.d.ts +94 -0
- package/types/controllers/page.d.ts +59 -0
- package/types/controllers/post.d.ts +72 -0
- package/types/controllers/project.d.ts +15 -0
- package/types/controllers/recently.d.ts +61 -0
- package/types/controllers/say.d.ts +37 -0
- package/types/controllers/search.d.ts +247 -0
- package/types/controllers/snippet.d.ts +33 -0
- package/types/controllers/user.d.ts +54 -0
- package/types/core/attach-request.d.ts +2 -0
- package/types/core/client.d.ts +29 -0
- package/types/core/error.d.ts +6 -0
- package/types/core/index.d.ts +2 -0
- package/types/dtos/comment.d.ts +6 -0
- package/types/index.d.ts +7 -0
- package/types/interfaces/adapter.d.ts +14 -0
- package/types/interfaces/client.d.ts +5 -0
- package/types/interfaces/controller.d.ts +4 -0
- package/types/interfaces/instance.d.ts +7 -0
- package/types/interfaces/options.d.ts +1 -0
- package/types/interfaces/params.d.ts +4 -0
- package/types/interfaces/request.d.ts +43 -0
- package/types/interfaces/types.d.ts +2 -0
- package/types/models/aggregate.d.ts +53 -0
- package/types/models/base.d.ts +37 -0
- package/types/models/category.d.ts +22 -0
- package/types/models/comment.d.ts +34 -0
- package/types/models/index.d.ts +14 -0
- package/types/models/link.d.ts +20 -0
- package/types/models/note.d.ts +30 -0
- package/types/models/page.d.ts +14 -0
- package/types/models/post.d.ts +15 -0
- package/types/models/project.d.ts +11 -0
- package/types/models/recently.d.ts +6 -0
- package/types/models/say.d.ts +6 -0
- package/types/models/setting.d.ts +66 -0
- package/types/models/snippet.d.ts +16 -0
- package/types/models/user.d.ts +21 -0
- package/types/utils/auto-bind.d.ts +4 -0
- package/types/utils/index.d.ts +5 -0
package/controllers/base.ts
CHANGED
|
@@ -3,16 +3,16 @@ import { PaginateResult } from '~/models/base'
|
|
|
3
3
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
4
|
import { HTTPClient } from '../core'
|
|
5
5
|
|
|
6
|
-
export abstract class BaseCrudController<T> {
|
|
6
|
+
export abstract class BaseCrudController<T, ResponseWrapper> {
|
|
7
7
|
base!: string
|
|
8
8
|
constructor(protected client: HTTPClient) {
|
|
9
9
|
autoBind(this)
|
|
10
10
|
}
|
|
11
|
-
public get proxy(): IRequestHandler {
|
|
11
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
12
12
|
return this.client.proxy(this.base)
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
getById(id: string): RequestProxyResult<T> {
|
|
15
|
+
getById(id: string): RequestProxyResult<T, ResponseWrapper> {
|
|
16
16
|
return this.proxy(id).get<T>()
|
|
17
17
|
}
|
|
18
18
|
|
package/controllers/category.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
2
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
IRequestHandler,
|
|
5
|
+
RequestProxyResult,
|
|
6
|
+
ResponseProxyExtraRaw,
|
|
7
|
+
} from '~/interfaces/request'
|
|
3
8
|
import { attachRawFromOneToAnthor, destructureData } from '~/utils'
|
|
4
9
|
import { autoBind } from '~/utils/auto-bind'
|
|
5
10
|
import { HTTPClient } from '../core/client'
|
|
@@ -14,23 +19,29 @@ import {
|
|
|
14
19
|
import { PostModel } from '../models/post'
|
|
15
20
|
|
|
16
21
|
declare module '../core/client' {
|
|
17
|
-
interface HTTPClient
|
|
18
|
-
|
|
22
|
+
interface HTTPClient<
|
|
23
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
24
|
+
ResponseWrapper = unknown,
|
|
25
|
+
> {
|
|
26
|
+
category: CategoryController<ResponseWrapper>
|
|
19
27
|
}
|
|
20
28
|
}
|
|
21
29
|
|
|
22
|
-
export class CategoryController implements IController {
|
|
30
|
+
export class CategoryController<ResponseWrapper> implements IController {
|
|
23
31
|
name = 'category'
|
|
24
32
|
base = 'categories'
|
|
25
33
|
constructor(private client: HTTPClient) {
|
|
26
34
|
autoBind(this)
|
|
27
35
|
}
|
|
28
36
|
|
|
29
|
-
public get proxy() {
|
|
37
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
30
38
|
return this.client.proxy(this.base)
|
|
31
39
|
}
|
|
32
40
|
|
|
33
|
-
getAllCategories(): RequestProxyResult<
|
|
41
|
+
getAllCategories(): RequestProxyResult<
|
|
42
|
+
{ data: CategoryModel[] },
|
|
43
|
+
ResponseWrapper
|
|
44
|
+
> {
|
|
34
45
|
return this.proxy.get({
|
|
35
46
|
params: {
|
|
36
47
|
type: CategoryType.Category,
|
|
@@ -38,7 +49,7 @@ export class CategoryController implements IController {
|
|
|
38
49
|
})
|
|
39
50
|
}
|
|
40
51
|
|
|
41
|
-
getAllTags(): RequestProxyResult<{ data: TagModel[] }> {
|
|
52
|
+
getAllTags(): RequestProxyResult<{ data: TagModel[] }, ResponseWrapper> {
|
|
42
53
|
return this.proxy.get<{ data: TagModel[] }>({
|
|
43
54
|
params: {
|
|
44
55
|
type: CategoryType.Tag,
|
package/controllers/comment.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
2
3
|
import { PaginationParams } from '~/interfaces/params'
|
|
3
|
-
import { IRequestHandler
|
|
4
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
4
5
|
import { PaginateResult } from '~/models/base'
|
|
5
6
|
import { CommentModel } from '~/models/comment'
|
|
6
7
|
import { autoBind } from '~/utils/auto-bind'
|
|
@@ -8,12 +9,15 @@ import { HTTPClient } from '../core'
|
|
|
8
9
|
import { CommentDto } from '../dtos/comment'
|
|
9
10
|
|
|
10
11
|
declare module '../core/client' {
|
|
11
|
-
interface HTTPClient
|
|
12
|
-
|
|
12
|
+
interface HTTPClient<
|
|
13
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
14
|
+
ResponseWrapper = unknown,
|
|
15
|
+
> {
|
|
16
|
+
comment: CommentController<ResponseWrapper>
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
|
|
16
|
-
export class CommentController implements IController {
|
|
20
|
+
export class CommentController<ResponseWrapper> implements IController {
|
|
17
21
|
base = 'comments'
|
|
18
22
|
name = 'comment'
|
|
19
23
|
|
|
@@ -21,14 +25,14 @@ export class CommentController implements IController {
|
|
|
21
25
|
autoBind(this)
|
|
22
26
|
}
|
|
23
27
|
|
|
24
|
-
get proxy(): IRequestHandler {
|
|
28
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
25
29
|
return this.client.proxy(this.base)
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
/**
|
|
29
33
|
* 根据 comment id 获取评论, 包括子评论
|
|
30
34
|
*/
|
|
31
|
-
getById(id: string)
|
|
35
|
+
getById(id: string) {
|
|
32
36
|
return this.proxy(id).get<CommentModel & { ref: string }>()
|
|
33
37
|
}
|
|
34
38
|
|
package/controllers/link.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { LinkModel } from '~/models/link'
|
|
2
3
|
import { autoBind } from '~/utils/auto-bind'
|
|
3
4
|
import { HTTPClient } from '../core'
|
|
4
5
|
import { BaseCrudController } from './base'
|
|
5
6
|
|
|
6
7
|
declare module '../core/client' {
|
|
7
|
-
interface HTTPClient
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
interface HTTPClient<
|
|
9
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
10
|
+
ResponseWrapper = unknown,
|
|
11
|
+
> {
|
|
12
|
+
link: LinkController<ResponseWrapper>
|
|
13
|
+
friend: LinkController<ResponseWrapper>
|
|
10
14
|
}
|
|
11
15
|
}
|
|
12
16
|
|
|
13
|
-
export class LinkController extends BaseCrudController<
|
|
17
|
+
export class LinkController<ResponseWrapper> extends BaseCrudController<
|
|
18
|
+
LinkModel,
|
|
19
|
+
ResponseWrapper
|
|
20
|
+
> {
|
|
14
21
|
constructor(protected readonly client: HTTPClient) {
|
|
15
22
|
super(client)
|
|
16
23
|
autoBind(this)
|
package/controllers/note.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
2
|
-
import { IRequestHandler
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
4
|
+
import { SelectFields } from '~/interfaces/types'
|
|
3
5
|
import { PaginateResult } from '~/models/base'
|
|
4
6
|
import { NoteModel, NoteWrappedPayload } from '~/models/note'
|
|
5
|
-
import { SelectFields } from '~/types/helper'
|
|
6
7
|
import { autoBind } from '~/utils/auto-bind'
|
|
7
8
|
import { HTTPClient } from '../core/client'
|
|
8
9
|
|
|
9
10
|
declare module '../core/client' {
|
|
10
|
-
interface HTTPClient
|
|
11
|
-
|
|
11
|
+
interface HTTPClient<
|
|
12
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
13
|
+
ResponseWrapper = unknown,
|
|
14
|
+
> {
|
|
15
|
+
note: NoteController<ResponseWrapper>
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -19,21 +23,21 @@ export type NoteListOptions = {
|
|
|
19
23
|
sortOrder?: 1 | -1
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
export class NoteController implements IController {
|
|
26
|
+
export class NoteController<ResponseWrapper> implements IController {
|
|
23
27
|
base = 'notes'
|
|
24
28
|
name = 'note'
|
|
25
29
|
|
|
26
30
|
constructor(private client: HTTPClient) {
|
|
27
31
|
autoBind(this)
|
|
28
32
|
}
|
|
29
|
-
get proxy(): IRequestHandler {
|
|
33
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
30
34
|
return this.client.proxy(this.base)
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
/**
|
|
34
38
|
* 最新日记
|
|
35
39
|
*/
|
|
36
|
-
getLatest()
|
|
40
|
+
getLatest() {
|
|
37
41
|
return this.proxy.latest.get<NoteWrappedPayload>()
|
|
38
42
|
}
|
|
39
43
|
|
package/controllers/page.ts
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
4
|
+
import { SelectFields } from '~/interfaces/types'
|
|
2
5
|
import { PaginateResult } from '~/models/base'
|
|
3
6
|
import { PageModel } from '~/models/page'
|
|
4
|
-
import { SelectFields } from '~/types/helper'
|
|
5
7
|
import { autoBind } from '~/utils/auto-bind'
|
|
6
8
|
import { HTTPClient } from '../core'
|
|
7
9
|
|
|
8
10
|
declare module '../core/client' {
|
|
9
|
-
interface HTTPClient
|
|
10
|
-
|
|
11
|
+
interface HTTPClient<
|
|
12
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
13
|
+
ResponseWrapper = unknown,
|
|
14
|
+
> {
|
|
15
|
+
page: PageController<ResponseWrapper>
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
|
|
@@ -17,13 +22,13 @@ export type PageListOptions = {
|
|
|
17
22
|
sortOrder?: 1 | -1
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
export class PageController implements IController {
|
|
25
|
+
export class PageController<ResponseWrapper> implements IController {
|
|
21
26
|
constructor(private readonly client: HTTPClient) {
|
|
22
27
|
autoBind(this)
|
|
23
28
|
}
|
|
24
29
|
base = 'pages'
|
|
25
30
|
name = 'page'
|
|
26
|
-
get proxy() {
|
|
31
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
27
32
|
return this.client.proxy(this.base)
|
|
28
33
|
}
|
|
29
34
|
/**
|
package/controllers/post.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
2
|
-
import { RequestProxyResult } from '~/interfaces/request'
|
|
3
|
+
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
4
|
+
import { SelectFields } from '~/interfaces/types'
|
|
3
5
|
import { PaginateResult } from '~/models/base'
|
|
4
6
|
import { PostModel } from '~/models/post'
|
|
5
|
-
import { SelectFields } from '~/types/helper'
|
|
6
7
|
import { autoBind } from '~/utils/auto-bind'
|
|
7
8
|
import { HTTPClient } from '../core/client'
|
|
8
9
|
|
|
9
10
|
declare module '../core/client' {
|
|
10
|
-
interface HTTPClient
|
|
11
|
-
|
|
11
|
+
interface HTTPClient<
|
|
12
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
13
|
+
ResponseWrapper = unknown,
|
|
14
|
+
> {
|
|
15
|
+
post: PostController<ResponseWrapper>
|
|
12
16
|
}
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -19,7 +23,7 @@ export type PostListOptions = {
|
|
|
19
23
|
sortOrder?: 1 | -1
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
export class PostController implements IController {
|
|
26
|
+
export class PostController<ResponseWrapper> implements IController {
|
|
23
27
|
constructor(private client: HTTPClient) {
|
|
24
28
|
autoBind(this)
|
|
25
29
|
}
|
|
@@ -28,7 +32,7 @@ export class PostController implements IController {
|
|
|
28
32
|
|
|
29
33
|
name = 'post'
|
|
30
34
|
|
|
31
|
-
public get proxy() {
|
|
35
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
32
36
|
return this.client.proxy(this.base)
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -57,12 +61,15 @@ export class PostController implements IController {
|
|
|
57
61
|
* @param categoryName
|
|
58
62
|
* @param slug
|
|
59
63
|
*/
|
|
60
|
-
getPost(
|
|
64
|
+
getPost(
|
|
65
|
+
categoryName: string,
|
|
66
|
+
slug: string,
|
|
67
|
+
): RequestProxyResult<PostModel, ResponseWrapper>
|
|
61
68
|
/**
|
|
62
69
|
* 根据 ID 查找文章
|
|
63
70
|
* @param id
|
|
64
71
|
*/
|
|
65
|
-
getPost(id: string): RequestProxyResult<PostModel>
|
|
72
|
+
getPost(id: string): RequestProxyResult<PostModel, ResponseWrapper>
|
|
66
73
|
getPost(idOrCategoryName: string, slug?: string): any {
|
|
67
74
|
if (arguments.length == 1) {
|
|
68
75
|
return this.proxy(idOrCategoryName).get<PostModel>()
|
package/controllers/project.ts
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { ProjectModel } from '~/models/project'
|
|
2
3
|
import { autoBind } from '~/utils/auto-bind'
|
|
3
4
|
import { HTTPClient } from '../core'
|
|
4
5
|
import { BaseCrudController } from './base'
|
|
5
6
|
|
|
6
7
|
declare module '../core/client' {
|
|
7
|
-
interface HTTPClient
|
|
8
|
-
|
|
8
|
+
interface HTTPClient<
|
|
9
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
10
|
+
ResponseWrapper = unknown,
|
|
11
|
+
> {
|
|
12
|
+
project: ProjectController<ResponseWrapper>
|
|
9
13
|
}
|
|
10
14
|
}
|
|
11
15
|
|
|
12
|
-
export class ProjectController extends BaseCrudController<
|
|
16
|
+
export class ProjectController<ResponseWrapper> extends BaseCrudController<
|
|
17
|
+
ProjectModel,
|
|
18
|
+
ResponseWrapper
|
|
19
|
+
> {
|
|
13
20
|
constructor(protected readonly client: HTTPClient) {
|
|
14
21
|
super(client)
|
|
15
22
|
autoBind(this)
|
package/controllers/recently.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
2
4
|
import { RecentlyModel } from '~/models/recently'
|
|
3
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
6
|
import { HTTPClient } from '../core'
|
|
5
7
|
|
|
6
8
|
declare module '../core/client' {
|
|
7
|
-
interface HTTPClient
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface HTTPClient<
|
|
10
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
+
ResponseWrapper = unknown,
|
|
12
|
+
> {
|
|
13
|
+
recently: RecentlyController<ResponseWrapper>
|
|
14
|
+
shorthand: RecentlyController<ResponseWrapper>
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export class RecentlyController implements IController {
|
|
18
|
+
export class RecentlyController<ResponseWrapper> implements IController {
|
|
14
19
|
base = 'recently'
|
|
15
20
|
name = ['recently', 'shorthand']
|
|
16
21
|
|
|
@@ -18,7 +23,7 @@ export class RecentlyController implements IController {
|
|
|
18
23
|
autoBind(this)
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
get proxy() {
|
|
26
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
22
27
|
return this.client.proxy(this.base)
|
|
23
28
|
}
|
|
24
29
|
/**
|
package/controllers/say.ts
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
2
4
|
import { SayModel } from '~/models/say'
|
|
3
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
6
|
import { HTTPClient } from '../core'
|
|
5
7
|
import { BaseCrudController } from './base'
|
|
6
8
|
|
|
7
9
|
declare module '../core/client' {
|
|
8
|
-
interface HTTPClient
|
|
9
|
-
|
|
10
|
+
interface HTTPClient<
|
|
11
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
12
|
+
ResponseWrapper = unknown,
|
|
13
|
+
> {
|
|
14
|
+
say: SayController<ResponseWrapper>
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export class SayController
|
|
14
|
-
extends BaseCrudController<SayModel>
|
|
18
|
+
export class SayController<ResponseWrapper>
|
|
19
|
+
extends BaseCrudController<SayModel, ResponseWrapper>
|
|
15
20
|
implements IController
|
|
16
21
|
{
|
|
17
22
|
base = 'says'
|
|
@@ -22,7 +27,7 @@ export class SayController
|
|
|
22
27
|
autoBind(this)
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
public get proxy() {
|
|
30
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
26
31
|
return this.client.proxy(this.base)
|
|
27
32
|
}
|
|
28
33
|
|
package/controllers/search.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
2
3
|
import { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
|
|
3
4
|
import { PaginateResult } from '~/models/base'
|
|
@@ -8,8 +9,11 @@ import { PageModel } from '..'
|
|
|
8
9
|
import { HTTPClient } from '../core'
|
|
9
10
|
|
|
10
11
|
declare module '../core/client' {
|
|
11
|
-
interface HTTPClient
|
|
12
|
-
|
|
12
|
+
interface HTTPClient<
|
|
13
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
14
|
+
ResponseWrapper = unknown,
|
|
15
|
+
> {
|
|
16
|
+
search: SearchController<ResponseWrapper>
|
|
13
17
|
}
|
|
14
18
|
}
|
|
15
19
|
|
|
@@ -20,7 +24,7 @@ export type SearchOption = {
|
|
|
20
24
|
order?: number
|
|
21
25
|
rawAlgolia?: boolean
|
|
22
26
|
}
|
|
23
|
-
export class SearchController implements IController {
|
|
27
|
+
export class SearchController<ResponseWrapper> implements IController {
|
|
24
28
|
base = 'search'
|
|
25
29
|
name = 'search'
|
|
26
30
|
|
|
@@ -28,7 +32,7 @@ export class SearchController implements IController {
|
|
|
28
32
|
autoBind(this)
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
get proxy(): IRequestHandler {
|
|
35
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
32
36
|
return this.client.proxy(this.base)
|
|
33
37
|
}
|
|
34
38
|
|
|
@@ -40,7 +44,8 @@ export class SearchController implements IController {
|
|
|
40
44
|
RequestProxyResult<
|
|
41
45
|
PaginateResult<
|
|
42
46
|
Pick<NoteModel, 'modified' | 'id' | 'title' | 'created' | 'nid'>
|
|
43
|
-
|
|
47
|
+
>,
|
|
48
|
+
ResponseWrapper
|
|
44
49
|
>
|
|
45
50
|
>
|
|
46
51
|
search(
|
|
@@ -54,7 +59,8 @@ export class SearchController implements IController {
|
|
|
54
59
|
PostModel,
|
|
55
60
|
'modified' | 'id' | 'title' | 'created' | 'slug' | 'category'
|
|
56
61
|
>
|
|
57
|
-
|
|
62
|
+
>,
|
|
63
|
+
ResponseWrapper
|
|
58
64
|
>
|
|
59
65
|
>
|
|
60
66
|
search(
|
|
@@ -94,7 +100,8 @@ export class SearchController implements IController {
|
|
|
94
100
|
* @see: algoliasearch <https://www.algolia.com/doc/api-reference/api-methods/search/>
|
|
95
101
|
*/
|
|
96
102
|
raw?: any
|
|
97
|
-
}
|
|
103
|
+
},
|
|
104
|
+
ResponseWrapper
|
|
98
105
|
>
|
|
99
106
|
>({ params: { keyword, ...options } })
|
|
100
107
|
}
|
package/controllers/snippet.ts
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
2
4
|
import { SnippetModel } from '~/models/snippet'
|
|
3
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
6
|
import { HTTPClient } from '../core'
|
|
5
7
|
|
|
6
8
|
declare module '../core/client' {
|
|
7
|
-
interface HTTPClient
|
|
8
|
-
|
|
9
|
+
interface HTTPClient<
|
|
10
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
+
ResponseWrapper = unknown,
|
|
12
|
+
> {
|
|
13
|
+
snippet: SnippetController<ResponseWrapper>
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
export class SnippetController implements IController {
|
|
17
|
+
export class SnippetController<ResponseWrapper> implements IController {
|
|
13
18
|
base = 'snippets'
|
|
14
19
|
name = 'snippet'
|
|
15
20
|
|
|
@@ -17,7 +22,7 @@ export class SnippetController implements IController {
|
|
|
17
22
|
autoBind(this)
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
get proxy() {
|
|
25
|
+
get proxy(): IRequestHandler<ResponseWrapper> {
|
|
21
26
|
return this.client.proxy(this.base)
|
|
22
27
|
}
|
|
23
28
|
|
package/controllers/user.ts
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
|
+
import { IRequestAdapter } from '~/interfaces/adapter'
|
|
1
2
|
import { IController } from '~/interfaces/controller'
|
|
3
|
+
import { IRequestHandler } from '~/interfaces/request'
|
|
2
4
|
import { TLogin, UserModel } from '~/models/user'
|
|
3
5
|
import { autoBind } from '~/utils/auto-bind'
|
|
4
6
|
import { HTTPClient } from '../core'
|
|
5
7
|
|
|
6
8
|
declare module '../core/client' {
|
|
7
|
-
interface HTTPClient
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
interface HTTPClient<
|
|
10
|
+
T extends IRequestAdapter = IRequestAdapter,
|
|
11
|
+
ResponseWrapper = unknown,
|
|
12
|
+
> {
|
|
13
|
+
user: UserController<ResponseWrapper>
|
|
14
|
+
master: UserController<ResponseWrapper>
|
|
10
15
|
}
|
|
11
16
|
}
|
|
12
17
|
|
|
13
|
-
export class UserController implements IController {
|
|
18
|
+
export class UserController<ResponseWrapper> implements IController {
|
|
14
19
|
constructor(private readonly client: HTTPClient) {
|
|
15
20
|
autoBind(this)
|
|
16
21
|
}
|
|
@@ -19,7 +24,7 @@ export class UserController implements IController {
|
|
|
19
24
|
|
|
20
25
|
name = ['user', 'master']
|
|
21
26
|
|
|
22
|
-
public get proxy() {
|
|
27
|
+
public get proxy(): IRequestHandler<ResponseWrapper> {
|
|
23
28
|
return this.client.proxy(this.base)
|
|
24
29
|
}
|
|
25
30
|
|
package/core/attach-request.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HTTPClient } from '.'
|
|
2
2
|
|
|
3
|
-
export function attachRequestMethod<T extends HTTPClient
|
|
3
|
+
export function attachRequestMethod<T extends HTTPClient<any, any>>(target: T) {
|
|
4
4
|
Object.defineProperty(target, '$$get', {
|
|
5
5
|
value: function (url: string, options?: any) {
|
|
6
6
|
// HINT: method get only accept search params;
|