@mx-space/api-client 1.18.1 → 1.19.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.
Files changed (63) hide show
  1. package/dist/index.cjs +54 -54
  2. package/dist/index.d.cts +35 -28
  3. package/dist/index.d.mts +35 -28
  4. package/dist/index.mjs +54 -54
  5. package/package.json +15 -10
  6. package/controllers/ack.ts +0 -42
  7. package/controllers/activity.ts +0 -108
  8. package/controllers/aggregate.ts +0 -75
  9. package/controllers/ai.ts +0 -70
  10. package/controllers/base.ts +0 -36
  11. package/controllers/category.ts +0 -118
  12. package/controllers/comment.ts +0 -71
  13. package/controllers/index.ts +0 -97
  14. package/controllers/link.ts +0 -46
  15. package/controllers/note.ts +0 -128
  16. package/controllers/page.ts +0 -64
  17. package/controllers/post.ts +0 -93
  18. package/controllers/project.ts +0 -27
  19. package/controllers/recently.ts +0 -82
  20. package/controllers/say.ts +0 -40
  21. package/controllers/search.ts +0 -108
  22. package/controllers/severless.ts +0 -31
  23. package/controllers/snippet.ts +0 -35
  24. package/controllers/subscribe.ts +0 -58
  25. package/controllers/topic.ts +0 -37
  26. package/controllers/user.ts +0 -61
  27. package/dtos/comment.ts +0 -12
  28. package/dtos/index.ts +0 -1
  29. package/index.ts +0 -12
  30. package/interfaces/adapter.ts +0 -36
  31. package/interfaces/client.ts +0 -20
  32. package/interfaces/controller.ts +0 -5
  33. package/interfaces/instance.ts +0 -8
  34. package/interfaces/options.ts +0 -1
  35. package/interfaces/params.ts +0 -4
  36. package/interfaces/request.ts +0 -87
  37. package/interfaces/types.ts +0 -3
  38. package/mod-dts.mjs +0 -21
  39. package/models/activity.ts +0 -133
  40. package/models/aggregate.ts +0 -88
  41. package/models/ai.ts +0 -17
  42. package/models/auth.ts +0 -9
  43. package/models/base.ts +0 -48
  44. package/models/category.ts +0 -25
  45. package/models/comment.ts +0 -44
  46. package/models/index.ts +0 -20
  47. package/models/link.ts +0 -25
  48. package/models/note.ts +0 -41
  49. package/models/page.ts +0 -20
  50. package/models/post.ts +0 -28
  51. package/models/project.ts +0 -12
  52. package/models/reader.ts +0 -9
  53. package/models/recently.ts +0 -24
  54. package/models/say.ts +0 -7
  55. package/models/setting.ts +0 -73
  56. package/models/snippet.ts +0 -19
  57. package/models/subscribe.ts +0 -5
  58. package/models/topic.ts +0 -9
  59. package/models/user.ts +0 -27
  60. package/test.d.ts +0 -3
  61. package/tsconfig.json +0 -37
  62. package/tsdown.config.ts +0 -18
  63. package/vitest.config.ts +0 -16
package/dist/index.mjs CHANGED
@@ -259,10 +259,10 @@ var RequestError = class extends Error {
259
259
 
260
260
  //#endregion
261
261
  //#region models/category.ts
262
- let CategoryType = /* @__PURE__ */ function(CategoryType$1) {
263
- CategoryType$1[CategoryType$1["Category"] = 0] = "Category";
264
- CategoryType$1[CategoryType$1["Tag"] = 1] = "Tag";
265
- return CategoryType$1;
262
+ let CategoryType = /* @__PURE__ */ function(CategoryType) {
263
+ CategoryType[CategoryType["Category"] = 0] = "Category";
264
+ CategoryType[CategoryType["Tag"] = 1] = "Tag";
265
+ return CategoryType;
266
266
  }({});
267
267
 
268
268
  //#endregion
@@ -556,15 +556,15 @@ var ProjectController = class extends BaseCrudController {
556
556
 
557
557
  //#endregion
558
558
  //#region controllers/recently.ts
559
- let RecentlyAttitudeResultEnum = /* @__PURE__ */ function(RecentlyAttitudeResultEnum$1) {
560
- RecentlyAttitudeResultEnum$1[RecentlyAttitudeResultEnum$1["Inc"] = 1] = "Inc";
561
- RecentlyAttitudeResultEnum$1[RecentlyAttitudeResultEnum$1["Dec"] = -1] = "Dec";
562
- return RecentlyAttitudeResultEnum$1;
559
+ let RecentlyAttitudeResultEnum = /* @__PURE__ */ function(RecentlyAttitudeResultEnum) {
560
+ RecentlyAttitudeResultEnum[RecentlyAttitudeResultEnum["Inc"] = 1] = "Inc";
561
+ RecentlyAttitudeResultEnum[RecentlyAttitudeResultEnum["Dec"] = -1] = "Dec";
562
+ return RecentlyAttitudeResultEnum;
563
563
  }({});
564
- let RecentlyAttitudeEnum = /* @__PURE__ */ function(RecentlyAttitudeEnum$1) {
565
- RecentlyAttitudeEnum$1[RecentlyAttitudeEnum$1["Up"] = 0] = "Up";
566
- RecentlyAttitudeEnum$1[RecentlyAttitudeEnum$1["Down"] = 1] = "Down";
567
- return RecentlyAttitudeEnum$1;
564
+ let RecentlyAttitudeEnum = /* @__PURE__ */ function(RecentlyAttitudeEnum) {
565
+ RecentlyAttitudeEnum[RecentlyAttitudeEnum["Up"] = 0] = "Up";
566
+ RecentlyAttitudeEnum[RecentlyAttitudeEnum["Down"] = 1] = "Down";
567
+ return RecentlyAttitudeEnum;
568
568
  }({});
569
569
  var RecentlyController = class {
570
570
  constructor(client) {
@@ -1005,10 +1005,10 @@ function createClient(adapter) {
1005
1005
 
1006
1006
  //#endregion
1007
1007
  //#region models/aggregate.ts
1008
- let TimelineType = /* @__PURE__ */ function(TimelineType$1) {
1009
- TimelineType$1[TimelineType$1["Post"] = 0] = "Post";
1010
- TimelineType$1[TimelineType$1["Note"] = 1] = "Note";
1011
- return TimelineType$1;
1008
+ let TimelineType = /* @__PURE__ */ function(TimelineType) {
1009
+ TimelineType[TimelineType["Post"] = 0] = "Post";
1010
+ TimelineType[TimelineType["Note"] = 1] = "Note";
1011
+ return TimelineType;
1012
1012
  }({});
1013
1013
 
1014
1014
  //#endregion
@@ -1017,65 +1017,65 @@ const POST_COLLECTION_NAME = "posts";
1017
1017
  const NOTE_COLLECTION_NAME = "notes";
1018
1018
  const PAGE_COLLECTION_NAME = "pages";
1019
1019
  const RECENTLY_COLLECTION_NAME = "recentlies";
1020
- let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes$1) {
1021
- CollectionRefTypes$1[CollectionRefTypes$1["Post"] = POST_COLLECTION_NAME] = "Post";
1022
- CollectionRefTypes$1[CollectionRefTypes$1["Note"] = NOTE_COLLECTION_NAME] = "Note";
1023
- CollectionRefTypes$1[CollectionRefTypes$1["Page"] = PAGE_COLLECTION_NAME] = "Page";
1024
- CollectionRefTypes$1[CollectionRefTypes$1["Recently"] = RECENTLY_COLLECTION_NAME] = "Recently";
1025
- return CollectionRefTypes$1;
1020
+ let CollectionRefTypes = /* @__PURE__ */ function(CollectionRefTypes) {
1021
+ CollectionRefTypes[CollectionRefTypes["Post"] = POST_COLLECTION_NAME] = "Post";
1022
+ CollectionRefTypes[CollectionRefTypes["Note"] = NOTE_COLLECTION_NAME] = "Note";
1023
+ CollectionRefTypes[CollectionRefTypes["Page"] = PAGE_COLLECTION_NAME] = "Page";
1024
+ CollectionRefTypes[CollectionRefTypes["Recently"] = RECENTLY_COLLECTION_NAME] = "Recently";
1025
+ return CollectionRefTypes;
1026
1026
  }({});
1027
1027
 
1028
1028
  //#endregion
1029
1029
  //#region models/comment.ts
1030
- let CommentState = /* @__PURE__ */ function(CommentState$1) {
1031
- CommentState$1[CommentState$1["Unread"] = 0] = "Unread";
1032
- CommentState$1[CommentState$1["Read"] = 1] = "Read";
1033
- CommentState$1[CommentState$1["Junk"] = 2] = "Junk";
1034
- return CommentState$1;
1030
+ let CommentState = /* @__PURE__ */ function(CommentState) {
1031
+ CommentState[CommentState["Unread"] = 0] = "Unread";
1032
+ CommentState[CommentState["Read"] = 1] = "Read";
1033
+ CommentState[CommentState["Junk"] = 2] = "Junk";
1034
+ return CommentState;
1035
1035
  }({});
1036
1036
 
1037
1037
  //#endregion
1038
1038
  //#region models/link.ts
1039
- let LinkType = /* @__PURE__ */ function(LinkType$1) {
1040
- LinkType$1[LinkType$1["Friend"] = 0] = "Friend";
1041
- LinkType$1[LinkType$1["Collection"] = 1] = "Collection";
1042
- return LinkType$1;
1039
+ let LinkType = /* @__PURE__ */ function(LinkType) {
1040
+ LinkType[LinkType["Friend"] = 0] = "Friend";
1041
+ LinkType[LinkType["Collection"] = 1] = "Collection";
1042
+ return LinkType;
1043
1043
  }({});
1044
- let LinkState = /* @__PURE__ */ function(LinkState$1) {
1045
- LinkState$1[LinkState$1["Pass"] = 0] = "Pass";
1046
- LinkState$1[LinkState$1["Audit"] = 1] = "Audit";
1047
- LinkState$1[LinkState$1["Outdate"] = 2] = "Outdate";
1048
- LinkState$1[LinkState$1["Banned"] = 3] = "Banned";
1049
- LinkState$1[LinkState$1["Reject"] = 4] = "Reject";
1050
- return LinkState$1;
1044
+ let LinkState = /* @__PURE__ */ function(LinkState) {
1045
+ LinkState[LinkState["Pass"] = 0] = "Pass";
1046
+ LinkState[LinkState["Audit"] = 1] = "Audit";
1047
+ LinkState[LinkState["Outdate"] = 2] = "Outdate";
1048
+ LinkState[LinkState["Banned"] = 3] = "Banned";
1049
+ LinkState[LinkState["Reject"] = 4] = "Reject";
1050
+ return LinkState;
1051
1051
  }({});
1052
1052
 
1053
1053
  //#endregion
1054
1054
  //#region models/page.ts
1055
- let EnumPageType = /* @__PURE__ */ function(EnumPageType$1) {
1056
- EnumPageType$1["md"] = "md";
1057
- EnumPageType$1["html"] = "html";
1058
- EnumPageType$1["frame"] = "frame";
1059
- return EnumPageType$1;
1055
+ let EnumPageType = /* @__PURE__ */ function(EnumPageType) {
1056
+ EnumPageType["md"] = "md";
1057
+ EnumPageType["html"] = "html";
1058
+ EnumPageType["frame"] = "frame";
1059
+ return EnumPageType;
1060
1060
  }({});
1061
1061
 
1062
1062
  //#endregion
1063
1063
  //#region models/recently.ts
1064
- let RecentlyRefTypes = /* @__PURE__ */ function(RecentlyRefTypes$1) {
1065
- RecentlyRefTypes$1["Post"] = "Post";
1066
- RecentlyRefTypes$1["Note"] = "Note";
1067
- RecentlyRefTypes$1["Page"] = "Page";
1068
- return RecentlyRefTypes$1;
1064
+ let RecentlyRefTypes = /* @__PURE__ */ function(RecentlyRefTypes) {
1065
+ RecentlyRefTypes["Post"] = "Post";
1066
+ RecentlyRefTypes["Note"] = "Note";
1067
+ RecentlyRefTypes["Page"] = "Page";
1068
+ return RecentlyRefTypes;
1069
1069
  }({});
1070
1070
 
1071
1071
  //#endregion
1072
1072
  //#region models/snippet.ts
1073
- let SnippetType = /* @__PURE__ */ function(SnippetType$1) {
1074
- SnippetType$1["JSON"] = "json";
1075
- SnippetType$1["Function"] = "function";
1076
- SnippetType$1["Text"] = "text";
1077
- SnippetType$1["YAML"] = "yaml";
1078
- return SnippetType$1;
1073
+ let SnippetType = /* @__PURE__ */ function(SnippetType) {
1074
+ SnippetType["JSON"] = "json";
1075
+ SnippetType["Function"] = "function";
1076
+ SnippetType["Text"] = "text";
1077
+ SnippetType["YAML"] = "yaml";
1078
+ return SnippetType;
1079
1079
  }({});
1080
1080
 
1081
1081
  //#endregion
package/package.json CHANGED
@@ -1,13 +1,19 @@
1
1
  {
2
2
  "name": "@mx-space/api-client",
3
- "version": "1.18.1",
3
+ "version": "1.19.1",
4
4
  "description": "A api client for mx-space server@next",
5
5
  "type": "module",
6
+ "engines": {
7
+ "node": ">=22"
8
+ },
6
9
  "license": "MIT",
7
10
  "author": "Innei",
11
+ "files": [
12
+ "dist"
13
+ ],
8
14
  "main": "dist/index.cjs",
9
15
  "module": "dist/index.js",
10
- "types": "dist/index.d.ts",
16
+ "types": "dist/index.d.mts",
11
17
  "exports": {
12
18
  ".": {
13
19
  "types": "./dist/index.d.mts",
@@ -46,17 +52,16 @@
46
52
  "devDependencies": {
47
53
  "@types/cors": "2.8.19",
48
54
  "@types/express": "5.0.6",
49
- "@types/lodash": "4.17.21",
50
55
  "abort-controller": "3.0.0",
51
- "axios": "^1.13.2",
52
- "camelcase-keys": "^9.1.3",
53
- "cors": "2.8.5",
56
+ "axios": "^1.13.3",
57
+ "camelcase-keys": "^10.0.2",
58
+ "cors": "2.8.6",
59
+ "es-toolkit": "1.44.0",
54
60
  "express": "4.21.2",
55
61
  "form-data": "4.0.5",
56
- "lodash": "^4.17.21",
57
- "tsdown": "0.18.3",
62
+ "tsdown": "0.20.1",
58
63
  "umi-request": "1.4.0",
59
- "vite": "^6.0.3",
60
- "vitest": "2.1.8"
64
+ "vite": "^7.3.1",
65
+ "vitest": "4.0.18"
61
66
  }
62
67
  }
@@ -1,42 +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 { autoBind } from '~/utils/auto-bind'
5
- import type { HTTPClient } from '../core'
6
-
7
- declare module '../core/client' {
8
- interface HTTPClient<
9
- T extends IRequestAdapter = IRequestAdapter,
10
- ResponseWrapper = unknown,
11
- > {
12
- ack: AckController<ResponseWrapper>
13
- }
14
- }
15
-
16
- /**
17
- * @support core >= 4.4.0
18
- */
19
- export class AckController<ResponseWrapper> implements IController {
20
- base = 'ack'
21
- name = 'ack'
22
-
23
- constructor(private client: HTTPClient) {
24
- autoBind(this)
25
- }
26
-
27
- public get proxy(): IRequestHandler<ResponseWrapper> {
28
- return this.client.proxy(this.base)
29
- }
30
-
31
- read(type: 'post' | 'note', id: string) {
32
- return this.proxy.post<never>({
33
- data: {
34
- type: 'read',
35
- payload: {
36
- type,
37
- id,
38
- },
39
- },
40
- })
41
- }
42
- }
@@ -1,108 +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 { AuthUser } from '~/models'
5
- import type {
6
- ActivityPresence,
7
- LastYearPublication,
8
- RecentActivities,
9
- RoomsData,
10
- } from '~/models/activity'
11
- import { autoBind } from '~/utils/auto-bind'
12
- import type { HTTPClient } from '../core'
13
-
14
- declare module '../core/client' {
15
- interface HTTPClient<
16
- T extends IRequestAdapter = IRequestAdapter,
17
- ResponseWrapper = unknown,
18
- > {
19
- activity: ActivityController<ResponseWrapper>
20
- }
21
- }
22
-
23
- /**
24
- * @support core >= 4.3.0
25
- */
26
- export class ActivityController<ResponseWrapper> implements IController {
27
- base = 'activity'
28
- name = 'activity'
29
-
30
- constructor(private client: HTTPClient) {
31
- autoBind(this)
32
- }
33
-
34
- public get proxy(): IRequestHandler<ResponseWrapper> {
35
- return this.client.proxy(this.base)
36
- }
37
-
38
- likeIt(type: 'Post' | 'Note', id: string) {
39
- return this.proxy.like.post<never>({
40
- data: {
41
- type: type.toLowerCase(),
42
- id,
43
- },
44
- })
45
- }
46
-
47
- /**
48
- *
49
- * @support core >= 5.0.0
50
- */
51
- getPresence(roomName: string) {
52
- return this.proxy.presence.get<{
53
- data: Record<string, ActivityPresence>
54
- readers: Record<string, AuthUser>
55
- }>({
56
- params: {
57
- room_name: roomName,
58
- },
59
- })
60
- }
61
-
62
- /**
63
- *
64
- * @support core >= 5.0.0
65
- */
66
- updatePresence({
67
- identity,
68
- position,
69
- roomName,
70
- sid,
71
- ts,
72
- displayName,
73
- readerId,
74
- }: {
75
- roomName: string
76
- position: number
77
- identity: string
78
- sid: string
79
-
80
- displayName?: string
81
- ts?: number
82
- readerId?: string
83
- }) {
84
- return this.proxy.presence.update.post({
85
- data: {
86
- identity,
87
- position,
88
- ts: ts || Date.now(),
89
- roomName,
90
- sid,
91
- readerId,
92
- displayName,
93
- },
94
- })
95
- }
96
-
97
- async getRoomsInfo() {
98
- return this.proxy.rooms.get<RoomsData>()
99
- }
100
-
101
- async getRecentActivities() {
102
- return this.proxy.recent.get<RecentActivities>()
103
- }
104
-
105
- async getLastYearPublication(): Promise<LastYearPublication> {
106
- return this.proxy(`last-year`).publication.get<LastYearPublication>()
107
- }
108
- }
@@ -1,75 +0,0 @@
1
- import type { IRequestAdapter } from '~/interfaces/adapter'
2
- import type { IController } from '~/interfaces/controller'
3
- import type { SortOrder } from '~/interfaces/options'
4
- import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
5
- import type {
6
- AggregateRootWithTheme,
7
- AggregateStat,
8
- AggregateTop,
9
- TimelineData,
10
- TimelineType,
11
- } from '~/models/aggregate'
12
- import { sortOrderToNumber } from '~/utils'
13
- import { autoBind } from '~/utils/auto-bind'
14
- import type { HTTPClient } from '../core'
15
-
16
- declare module '../core/client' {
17
- interface HTTPClient<
18
- T extends IRequestAdapter = IRequestAdapter,
19
- ResponseWrapper = unknown,
20
- > {
21
- aggregate: AggregateController<ResponseWrapper>
22
- }
23
- }
24
-
25
- export class AggregateController<ResponseWrapper> implements IController {
26
- base = 'aggregate'
27
- name = 'aggregate'
28
- constructor(private client: HTTPClient) {
29
- autoBind(this)
30
- }
31
- public get proxy(): IRequestHandler<ResponseWrapper> {
32
- return this.client.proxy(this.base)
33
- }
34
-
35
- /**
36
- * 获取聚合数据
37
- */
38
- getAggregateData<Theme>(
39
- theme?: string,
40
- ): RequestProxyResult<AggregateRootWithTheme<Theme>, ResponseWrapper> {
41
- return this.proxy.get<AggregateRootWithTheme<Theme>>({
42
- params: {
43
- theme,
44
- },
45
- })
46
- }
47
-
48
- /**
49
- * 获取最新发布的内容
50
- */
51
- getTop(size = 5) {
52
- return this.proxy.top.get<AggregateTop>({ params: { size } })
53
- }
54
-
55
- getTimeline(options?: {
56
- sort?: SortOrder
57
- type?: TimelineType
58
- year?: number
59
- }) {
60
- const { sort, type, year } = options || {}
61
- return this.proxy.timeline.get<{ data: TimelineData }>({
62
- params: {
63
- sort: sort && sortOrderToNumber(sort),
64
- type,
65
- year,
66
- },
67
- })
68
- }
69
- /**
70
- * 获取聚合数据统计
71
- */
72
- getStat() {
73
- return this.proxy.stat.get<AggregateStat>()
74
- }
75
- }
package/controllers/ai.ts DELETED
@@ -1,70 +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 { autoBind } from '~/utils/auto-bind'
5
- import type { HTTPClient } from '../core'
6
- import type { AIDeepReadingModel, AISummaryModel } from '../models/ai'
7
-
8
- declare module '../core/client' {
9
- interface HTTPClient<
10
- T extends IRequestAdapter = IRequestAdapter,
11
- ResponseWrapper = unknown,
12
- > {
13
- ai: AIController<ResponseWrapper>
14
- }
15
- }
16
-
17
- /**
18
- * @support core >= 5.6.0
19
- */
20
- export class AIController<ResponseWrapper> implements IController {
21
- base = 'ai'
22
- name = 'ai'
23
-
24
- constructor(private client: HTTPClient) {
25
- autoBind(this)
26
- }
27
-
28
- public get proxy(): IRequestHandler<ResponseWrapper> {
29
- return this.client.proxy(this.base)
30
- }
31
-
32
- async getSummary({
33
- articleId,
34
- lang = 'zh-CN',
35
- onlyDb,
36
- }: {
37
- articleId: string
38
- lang?: string
39
- onlyDb?: boolean
40
- }) {
41
- return this.proxy.summaries.article(articleId).get<AISummaryModel>({
42
- params: {
43
- lang,
44
- onlyDb,
45
- },
46
- })
47
- }
48
-
49
- async generateSummary(articleId: string, lang = 'zh-CN', token = '') {
50
- return this.proxy.summaries.generate.post<AISummaryModel>({
51
- params: {
52
- token,
53
- },
54
- data: {
55
- lang,
56
- refId: articleId,
57
- },
58
- })
59
- }
60
-
61
- /**
62
- * Core >= 8.3.0
63
- * @param articleId
64
- */
65
- async getDeepReading(articleId: string) {
66
- return this.proxy('deep-readings')
67
- .article(articleId)
68
- .get<AIDeepReadingModel>()
69
- }
70
- }
@@ -1,36 +0,0 @@
1
- import type { IRequestHandler, RequestProxyResult } from '~/interfaces/request'
2
- import type { PaginateResult } from '~/models/base'
3
- import { autoBind } from '~/utils/auto-bind'
4
- import type { HTTPClient } from '../core'
5
-
6
- export type SortOptions = {
7
- sortBy?: string
8
- sortOrder?: 1 | -1 | 'asc' | 'desc'
9
- }
10
- export abstract class BaseCrudController<T, ResponseWrapper> {
11
- base!: string
12
- constructor(protected client: HTTPClient) {
13
- autoBind(this)
14
- }
15
- public get proxy(): IRequestHandler<ResponseWrapper> {
16
- return this.client.proxy(this.base)
17
- }
18
-
19
- getById(id: string): RequestProxyResult<T, ResponseWrapper> {
20
- return this.proxy(id).get<T>()
21
- }
22
-
23
- getAll() {
24
- return this.proxy.all.get<{ data: T[] }>()
25
- }
26
- /**
27
- * 带分页的查询
28
- * @param page
29
- * @param perPage
30
- */
31
- getAllPaginated(page?: number, perPage?: number, sortOption?: SortOptions) {
32
- return this.proxy.get<PaginateResult<T>>({
33
- params: { page, size: perPage, ...sortOption },
34
- })
35
- }
36
- }
@@ -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
- }