@mx-space/api-client 1.19.0 → 1.20.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.
Files changed (71) hide show
  1. package/dist/adaptors/axios.d.cts +1 -1
  2. package/dist/adaptors/axios.d.mts +1 -1
  3. package/dist/adaptors/fetch.d.cts +1 -1
  4. package/dist/adaptors/fetch.d.mts +1 -1
  5. package/dist/adaptors/umi-request.d.cts +1 -1
  6. package/dist/adaptors/umi-request.d.mts +1 -1
  7. package/dist/index.cjs +15 -2
  8. package/dist/index.d.cts +31 -3
  9. package/dist/index.d.mts +31 -3
  10. package/dist/index.mjs +15 -2
  11. package/package.json +5 -2
  12. package/controllers/ack.ts +0 -42
  13. package/controllers/activity.ts +0 -108
  14. package/controllers/aggregate.ts +0 -75
  15. package/controllers/ai.ts +0 -70
  16. package/controllers/base.ts +0 -36
  17. package/controllers/category.ts +0 -118
  18. package/controllers/comment.ts +0 -71
  19. package/controllers/index.ts +0 -97
  20. package/controllers/link.ts +0 -46
  21. package/controllers/note.ts +0 -128
  22. package/controllers/page.ts +0 -64
  23. package/controllers/post.ts +0 -93
  24. package/controllers/project.ts +0 -27
  25. package/controllers/recently.ts +0 -82
  26. package/controllers/say.ts +0 -40
  27. package/controllers/search.ts +0 -108
  28. package/controllers/severless.ts +0 -31
  29. package/controllers/snippet.ts +0 -35
  30. package/controllers/subscribe.ts +0 -58
  31. package/controllers/topic.ts +0 -37
  32. package/controllers/user.ts +0 -61
  33. package/dtos/comment.ts +0 -12
  34. package/dtos/index.ts +0 -1
  35. package/index.ts +0 -12
  36. package/interfaces/adapter.ts +0 -36
  37. package/interfaces/client.ts +0 -20
  38. package/interfaces/controller.ts +0 -5
  39. package/interfaces/instance.ts +0 -8
  40. package/interfaces/options.ts +0 -1
  41. package/interfaces/params.ts +0 -4
  42. package/interfaces/request.ts +0 -87
  43. package/interfaces/types.ts +0 -3
  44. package/mod-dts.mjs +0 -21
  45. package/models/activity.ts +0 -133
  46. package/models/aggregate.ts +0 -97
  47. package/models/ai.ts +0 -17
  48. package/models/auth.ts +0 -9
  49. package/models/base.ts +0 -48
  50. package/models/category.ts +0 -25
  51. package/models/comment.ts +0 -44
  52. package/models/index.ts +0 -20
  53. package/models/link.ts +0 -25
  54. package/models/note.ts +0 -41
  55. package/models/page.ts +0 -20
  56. package/models/post.ts +0 -28
  57. package/models/project.ts +0 -12
  58. package/models/reader.ts +0 -9
  59. package/models/recently.ts +0 -24
  60. package/models/say.ts +0 -7
  61. package/models/setting.ts +0 -73
  62. package/models/snippet.ts +0 -19
  63. package/models/subscribe.ts +0 -5
  64. package/models/topic.ts +0 -9
  65. package/models/user.ts +0 -27
  66. package/test.d.ts +0 -3
  67. package/tsconfig.json +0 -37
  68. package/tsdown.config.ts +0 -18
  69. package/vitest.config.ts +0 -13
  70. /package/dist/{adapter-B1dtiutp.d.cts → adapter-D1g1obyM.d.mts} +0 -0
  71. /package/dist/{adapter-CRsPadpS.d.mts → adapter-DLzJOGbI.d.cts} +0 -0
@@ -1,118 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type {
4
- IRequestHandler,
5
- RequestProxyResult,
6
- ResponseProxyExtraRaw,
7
- } from '~/interfaces/request'
8
- import { attachRawFromOneToAnthor, destructureData } from '~/utils'
9
- import { autoBind } from '~/utils/auto-bind'
10
- import type { HTTPClient } from '../core/client'
11
- import { RequestError } from '../core/error'
12
- import type {
13
- CategoryEntries,
14
- CategoryModel,
15
- CategoryWithChildrenModel,
16
- TagModel,
17
- } from '../models/category'
18
- import { CategoryType } from '../models/category'
19
- import type { PostModel } from '../models/post'
20
-
21
- declare module '../core/client' {
22
- interface HTTPClient<
23
- T extends IRequestAdapter = IRequestAdapter,
24
- ResponseWrapper = unknown,
25
- > {
26
- category: CategoryController<ResponseWrapper>
27
- }
28
- }
29
-
30
- export class CategoryController<ResponseWrapper> implements IController {
31
- name = 'category'
32
- base = 'categories'
33
- constructor(private client: HTTPClient) {
34
- autoBind(this)
35
- }
36
-
37
- public get proxy(): IRequestHandler<ResponseWrapper> {
38
- return this.client.proxy(this.base)
39
- }
40
-
41
- getAllCategories(): RequestProxyResult<
42
- { data: CategoryModel[] },
43
- ResponseWrapper
44
- > {
45
- return this.proxy.get({
46
- params: {
47
- type: CategoryType.Category,
48
- },
49
- })
50
- }
51
-
52
- getAllTags(): RequestProxyResult<{ data: TagModel[] }, ResponseWrapper> {
53
- return this.proxy.get<{ data: TagModel[] }>({
54
- params: {
55
- type: CategoryType.Tag,
56
- },
57
- })
58
- }
59
-
60
- async getCategoryDetail(
61
- id: string,
62
- ): Promise<ResponseProxyExtraRaw<CategoryWithChildrenModel>>
63
- async getCategoryDetail(
64
- ids: string[],
65
- ): Promise<ResponseProxyExtraRaw<Map<string, CategoryWithChildrenModel>>>
66
- async getCategoryDetail(ids: string | string[]): Promise<any> {
67
- if (typeof ids === 'string') {
68
- const data = await this.proxy.get<CategoryEntries>({
69
- params: {
70
- ids,
71
- },
72
- })
73
- const result = Object.values(data.entries)[0]
74
- attachRawFromOneToAnthor(data, result)
75
- return result
76
- } else if (Array.isArray(ids)) {
77
- const data = await this.proxy.get<CategoryEntries>({
78
- params: {
79
- ids: ids.join(','),
80
- },
81
- })
82
- const entries = data?.entries
83
- if (!entries) {
84
- throw new RequestError(
85
- 'data structure error',
86
- 500,
87
- data.$request.path,
88
- data,
89
- )
90
- }
91
-
92
- const map = new Map<string, CategoryWithChildrenModel>(
93
- Object.entries(entries).map(([id, value]) => [id.toLowerCase(), value]),
94
- )
95
-
96
- attachRawFromOneToAnthor(data, map)
97
- return map
98
- }
99
- }
100
-
101
- async getCategoryByIdOrSlug(idOrSlug: string) {
102
- const res = await this.proxy(idOrSlug).get<CategoryWithChildrenModel>()
103
- return destructureData(res) as typeof res
104
- }
105
-
106
- async getTagByName(name: string) {
107
- const res = await this.proxy(name).get<{
108
- tag: string
109
- data: Pick<PostModel, 'id' | 'title' | 'slug' | 'category' | 'created'>[]
110
- }>({
111
- params: {
112
- tag: 1,
113
- },
114
- })
115
-
116
- return res
117
- }
118
- }
@@ -1,71 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type { PaginationParams } from '~/interfaces/params'
4
- import type { IRequestHandler } from '~/interfaces/request'
5
- import type { ReaderModel } from '~/models'
6
- import type { PaginateResult } from '~/models/base'
7
- import type { CommentModel } from '~/models/comment'
8
- import { autoBind } from '~/utils/auto-bind'
9
- import type { HTTPClient } from '../core'
10
- import type { CommentDto } from '../dtos/comment'
11
-
12
- declare module '../core/client' {
13
- interface HTTPClient<
14
- T extends IRequestAdapter = IRequestAdapter,
15
- ResponseWrapper = unknown,
16
- > {
17
- comment: CommentController<ResponseWrapper>
18
- }
19
- }
20
-
21
- export class CommentController<ResponseWrapper> implements IController {
22
- base = 'comments'
23
- name = 'comment'
24
-
25
- constructor(private readonly client: HTTPClient) {
26
- autoBind(this)
27
- }
28
-
29
- get proxy(): IRequestHandler<ResponseWrapper> {
30
- return this.client.proxy(this.base)
31
- }
32
-
33
- /**
34
- * 根据 comment id 获取评论,包括子评论
35
- */
36
- getById(id: string) {
37
- return this.proxy(id).get<CommentModel & { ref: string }>()
38
- }
39
-
40
- /**
41
- * 获取文章的评论列表
42
- * @param refId 文章 Id
43
- */
44
- getByRefId(refId: string, pagination: PaginationParams = {}) {
45
- const { page, size } = pagination
46
- return this.proxy.ref(refId).get<
47
- PaginateResult<CommentModel & { ref: string }> & {
48
- readers: Record<string, ReaderModel>
49
- }
50
- >({
51
- params: { page: page || 1, size: size || 10 },
52
- })
53
- }
54
- /**
55
- * 评论
56
- */
57
- comment(refId: string, data: CommentDto) {
58
- return this.proxy(refId).post<CommentModel>({
59
- data,
60
- })
61
- }
62
-
63
- /**
64
- * 回复评论
65
- */
66
- reply(commentId: string, data: CommentDto) {
67
- return this.proxy.reply(commentId).post<CommentModel>({
68
- data,
69
- })
70
- }
71
- }
@@ -1,97 +0,0 @@
1
- import { AckController } from './ack'
2
- import { ActivityController } from './activity'
3
- import { AggregateController } from './aggregate'
4
- import { AIController } from './ai'
5
- import { CategoryController } from './category'
6
- import { CommentController } from './comment'
7
- import { LinkController } from './link'
8
- import { NoteController } from './note'
9
- import { PageController } from './page'
10
- import { PostController } from './post'
11
- import { ProjectController } from './project'
12
- import {
13
- RecentlyAttitudeEnum,
14
- RecentlyAttitudeResultEnum,
15
- RecentlyController,
16
- } from './recently'
17
- import { SayController } from './say'
18
- import { SearchController } from './search'
19
- import { ServerlessController } from './severless'
20
- import { SnippetController } from './snippet'
21
- import { SubscribeController } from './subscribe'
22
- import { TopicController } from './topic'
23
- import { UserController } from './user'
24
-
25
- export const allControllers = [
26
- AckController,
27
- ActivityController,
28
- AggregateController,
29
- AIController,
30
- CategoryController,
31
- CommentController,
32
- LinkController,
33
- NoteController,
34
- PageController,
35
- PostController,
36
- ProjectController,
37
- RecentlyController,
38
- SayController,
39
- SearchController,
40
- ServerlessController,
41
- SnippetController,
42
- SubscribeController,
43
- TopicController,
44
- UserController,
45
- ]
46
-
47
- export const allControllerNames = [
48
- 'ai',
49
- 'ack',
50
- 'activity',
51
- 'aggregate',
52
- 'category',
53
- 'comment',
54
- 'link',
55
- 'note',
56
- 'page',
57
- 'post',
58
- 'project',
59
- 'topic',
60
- 'recently',
61
- 'say',
62
- 'search',
63
- 'snippet',
64
- 'serverless',
65
- 'subscribe',
66
- 'user',
67
-
68
- // alias,
69
- 'friend',
70
- 'master',
71
- 'shorthand',
72
- ] as const
73
-
74
- export {
75
- AckController,
76
- ActivityController,
77
- AggregateController,
78
- AIController,
79
- CategoryController,
80
- CommentController,
81
- LinkController,
82
- NoteController,
83
- PageController,
84
- PostController,
85
- ProjectController,
86
- // Enum
87
- RecentlyAttitudeEnum,
88
- RecentlyAttitudeResultEnum,
89
- RecentlyController,
90
- SayController,
91
- SearchController,
92
- ServerlessController,
93
- SnippetController,
94
- SubscribeController,
95
- TopicController,
96
- UserController,
97
- }
@@ -1,46 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { LinkModel } from '~/models/link'
3
- import { autoBind } from '~/utils/auto-bind'
4
- import type { HTTPClient } from '../core'
5
- import { BaseCrudController } from './base'
6
-
7
- declare module '../core/client' {
8
- interface HTTPClient<
9
- T extends IRequestAdapter = IRequestAdapter,
10
- ResponseWrapper = unknown,
11
- > {
12
- link: LinkController<ResponseWrapper>
13
- friend: LinkController<ResponseWrapper>
14
- }
15
- }
16
-
17
- export class LinkController<ResponseWrapper> extends BaseCrudController<
18
- LinkModel,
19
- ResponseWrapper
20
- > {
21
- constructor(protected readonly client: HTTPClient) {
22
- super(client)
23
- autoBind(this)
24
- }
25
-
26
- // 是否可以申请友链
27
- async canApplyLink() {
28
- const { can } = await this.proxy.audit.get<{ can: boolean }>()
29
- return can
30
- }
31
-
32
- // 申请友链
33
- async applyLink(
34
- data: Pick<
35
- LinkModel,
36
- 'avatar' | 'name' | 'description' | 'url' | 'email'
37
- > & {
38
- author: string
39
- },
40
- ) {
41
- return await this.proxy.audit.post<never>({ data })
42
- }
43
-
44
- name = ['link', 'friend']
45
- base = 'links'
46
- }
@@ -1,128 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
4
- import type { SelectFields } from '~/interfaces/types'
5
- import type { PaginateResult } from '~/models/base'
6
- import type {
7
- NoteModel,
8
- NoteWrappedPayload,
9
- NoteWrappedWithLikedPayload,
10
- } from '~/models/note'
11
- import { autoBind } from '~/utils/auto-bind'
12
- import type { HTTPClient } from '../core/client'
13
- import type { SortOptions } from './base'
14
-
15
- declare module '../core/client' {
16
- interface HTTPClient<
17
- T extends IRequestAdapter = IRequestAdapter,
18
- ResponseWrapper = unknown,
19
- > {
20
- note: NoteController<ResponseWrapper>
21
- }
22
- }
23
-
24
- export type NoteListOptions = {
25
- select?: SelectFields<keyof NoteModel>
26
- year?: number
27
- sortBy?: 'weather' | 'mood' | 'title' | 'created' | 'modified'
28
- sortOrder?: 1 | -1
29
- }
30
-
31
- export class NoteController<ResponseWrapper> implements IController {
32
- base = 'notes'
33
- name = 'note'
34
-
35
- constructor(private client: HTTPClient) {
36
- autoBind(this)
37
- }
38
- get proxy(): IRequestHandler<ResponseWrapper> {
39
- return this.client.proxy(this.base)
40
- }
41
-
42
- /**
43
- * 最新日记
44
- */
45
- getLatest() {
46
- return this.proxy.latest.get<NoteWrappedWithLikedPayload>()
47
- }
48
-
49
- /**
50
- * 获取一篇日记,根据 Id 查询需要鉴权
51
- * @param id id | nid
52
- * @param password 访问密码
53
- */
54
-
55
- getNoteById(
56
- id: string,
57
- ): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
58
- getNoteById(id: number): Promise<NoteWrappedPayload>
59
- getNoteById(id: number, password: string): Promise<NoteWrappedPayload>
60
- getNoteById(
61
- id: number,
62
- password: undefined,
63
- singleResult: true,
64
- ): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
65
- getNoteById(
66
- id: number,
67
- password: string,
68
- singleResult: true,
69
- ): Promise<RequestProxyResult<NoteModel, ResponseWrapper>>
70
- getNoteById(...rest: any[]): any {
71
- const [id, password = undefined, singleResult = false] = rest
72
-
73
- if (typeof id === 'number') {
74
- return this.proxy.nid(id.toString()).get<NoteWrappedWithLikedPayload>({
75
- params: { password, single: singleResult ? '1' : undefined },
76
- })
77
- } else {
78
- return this.proxy(id).get<NoteModel>()
79
- }
80
- }
81
-
82
- /**
83
- * 日记列表分页
84
- */
85
-
86
- getList(page = 1, perPage = 10, options: NoteListOptions = {}) {
87
- const { select, sortBy, sortOrder, year } = options
88
- return this.proxy.get<PaginateResult<NoteModel>>({
89
- params: {
90
- page,
91
- size: perPage,
92
- select: select?.join(' '),
93
- sortBy,
94
- sortOrder,
95
- year,
96
- },
97
- })
98
- }
99
-
100
- /**
101
- * 获取当前日记的上下各 n / 2 篇日记
102
- */
103
- getMiddleList(id: string, size = 5) {
104
- return this.proxy.list(id).get<{
105
- data: Pick<
106
- NoteModel,
107
- 'id' | 'title' | 'nid' | 'created' | 'isPublished'
108
- >[]
109
- size: number
110
- }>({
111
- params: { size },
112
- })
113
- }
114
-
115
- /**
116
- * 获取专栏内的所有日记
117
- */
118
- getNoteByTopicId(
119
- topicId: string,
120
- page = 1,
121
- size = 10,
122
- sortOptions: SortOptions = {},
123
- ) {
124
- return this.proxy.topics(topicId).get<PaginateResult<NoteModel>>({
125
- params: { page, size, ...sortOptions },
126
- })
127
- }
128
- }
@@ -1,64 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type { IRequestHandler } from '~/interfaces/request'
4
- import type { SelectFields } from '~/interfaces/types'
5
- import type { PaginateResult } from '~/models/base'
6
- import type { PageModel } from '~/models/page'
7
- import { autoBind } from '~/utils/auto-bind'
8
- import type { HTTPClient } from '../core'
9
-
10
- declare module '../core/client' {
11
- interface HTTPClient<
12
- T extends IRequestAdapter = IRequestAdapter,
13
- ResponseWrapper = unknown,
14
- > {
15
- page: PageController<ResponseWrapper>
16
- }
17
- }
18
-
19
- export type PageListOptions = {
20
- select?: SelectFields<keyof PageModel>
21
- sortBy?: 'order' | 'subtitle' | 'title' | 'created' | 'modified'
22
- sortOrder?: 1 | -1
23
- }
24
-
25
- export class PageController<ResponseWrapper> implements IController {
26
- constructor(private readonly client: HTTPClient) {
27
- autoBind(this)
28
- }
29
- base = 'pages'
30
- name = 'page'
31
- get proxy(): IRequestHandler<ResponseWrapper> {
32
- return this.client.proxy(this.base)
33
- }
34
- /**
35
- * 页面列表
36
- */
37
- getList(page = 1, perPage = 10, options: PageListOptions = {}) {
38
- const { select, sortBy, sortOrder } = options
39
- return this.proxy.get<PaginateResult<PageModel>>({
40
- params: {
41
- page,
42
- size: perPage,
43
- select: select?.join(' '),
44
- sortBy,
45
- sortOrder,
46
- },
47
- })
48
- }
49
-
50
- /**
51
- * 页面详情
52
- */
53
- getById(id: string) {
54
- return this.proxy(id).get<PageModel>()
55
- }
56
- /**
57
- * 根据路径获取页面
58
- * @param slug 路径
59
- * @returns
60
- */
61
- getBySlug(slug: string) {
62
- return this.proxy.slug(slug).get<PageModel>({})
63
- }
64
- }
@@ -1,93 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
4
- import type { SelectFields } from '~/interfaces/types'
5
- import type { ModelWithLiked, PaginateResult } from '~/models/base'
6
- import type { PostModel } from '~/models/post'
7
- import { autoBind } from '~/utils/auto-bind'
8
- import type { HTTPClient } from '../core/client'
9
-
10
- declare module '../core/client' {
11
- interface HTTPClient<
12
- T extends IRequestAdapter = IRequestAdapter,
13
- ResponseWrapper = unknown,
14
- > {
15
- post: PostController<ResponseWrapper>
16
- }
17
- }
18
-
19
- export type PostListOptions = {
20
- select?: SelectFields<keyof PostModel>
21
- year?: number
22
- sortBy?: 'categoryId' | 'title' | 'created' | 'modified'
23
- sortOrder?: 1 | -1
24
- truncate?: number
25
- }
26
-
27
- export class PostController<ResponseWrapper> implements IController {
28
- constructor(private client: HTTPClient) {
29
- autoBind(this)
30
- }
31
-
32
- base = 'posts'
33
-
34
- name = 'post'
35
-
36
- public get proxy(): IRequestHandler<ResponseWrapper> {
37
- return this.client.proxy(this.base)
38
- }
39
-
40
- /**
41
- * 获取文章列表分页
42
- * @param page
43
- * @param perPage
44
- * @returns
45
- */
46
- getList(page = 1, perPage = 10, options: PostListOptions = {}) {
47
- const { select, sortBy, sortOrder, year, truncate } = options
48
- return this.proxy.get<PaginateResult<PostModel>>({
49
- params: {
50
- page,
51
- size: perPage,
52
- select: select?.join(' '),
53
- sortBy,
54
- sortOrder,
55
- year,
56
- truncate,
57
- },
58
- })
59
- }
60
-
61
- /**
62
- * 根据分类和路径查找文章
63
- * @param categoryName
64
- * @param slug
65
- */
66
- getPost(
67
- categoryName: string,
68
- slug: string,
69
- ): RequestProxyResult<ModelWithLiked<PostModel>, ResponseWrapper>
70
- /**
71
- * 根据 ID 查找文章
72
- * @param id
73
- */
74
- getPost(id: string): RequestProxyResult<PostModel, ResponseWrapper>
75
- getPost(idOrCategoryName: string, slug?: string): any {
76
- if (arguments.length == 1) {
77
- return this.proxy(idOrCategoryName).get<PostModel>()
78
- } else {
79
- return this.proxy(idOrCategoryName)(slug).get<PostModel>()
80
- }
81
- }
82
-
83
- /**
84
- * 获取最新的文章
85
- */
86
- getLatest() {
87
- return this.proxy.latest.get<ModelWithLiked<PostModel>>()
88
- }
89
-
90
- getFullUrl(slug: string) {
91
- return this.proxy('get-url')(slug).get<{ path: string }>()
92
- }
93
- }
@@ -1,27 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { ProjectModel } from '~/models/project'
3
- import { autoBind } from '~/utils/auto-bind'
4
- import type { HTTPClient } from '../core'
5
- import { BaseCrudController } from './base'
6
-
7
- declare module '../core/client' {
8
- interface HTTPClient<
9
- T extends IRequestAdapter = IRequestAdapter,
10
- ResponseWrapper = unknown,
11
- > {
12
- project: ProjectController<ResponseWrapper>
13
- }
14
- }
15
-
16
- export class ProjectController<ResponseWrapper> extends BaseCrudController<
17
- ProjectModel,
18
- ResponseWrapper
19
- > {
20
- constructor(protected readonly client: HTTPClient) {
21
- super(client)
22
- autoBind(this)
23
- }
24
-
25
- base = 'projects'
26
- name = 'project'
27
- }