Skip to content

Commit 0520a34

Browse files
committed
refactor(entity): improve typings
1 parent 4f5d2b4 commit 0520a34

File tree

12 files changed

+844
-683
lines changed

12 files changed

+844
-683
lines changed

src/client/client.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { AuthorizationError } from './errors/AuthorizationError'
1010
import { JikePost } from './post'
1111
import type { PersonalUpdate } from '../types/api-responses'
1212
import type { CreatePostOption, PostType } from '../types/options'
13-
import type { Notification, PostDetail } from '../types/entity'
13+
import type { FollowingUpdate, Notification } from '../types/entity'
1414
import type { BeforeRetryState } from 'ky/distribution/types/hooks'
1515
import type { PaginatedFetcher, PaginatedOption } from './utils/paginate'
1616
import type { Api } from '../api'
@@ -202,13 +202,13 @@ export class JikeClient {
202202
*/
203203
async queryFollowingUpdates(
204204
option: PaginatedOption<
205-
PostDetail,
205+
FollowingUpdate,
206206
'createdAt',
207207
FollowingUpdatesMoreKey
208208
> = {}
209209
) {
210210
const fetcher: PaginatedFetcher<
211-
PostDetail,
211+
FollowingUpdate,
212212
FollowingUpdatesMoreKey
213213
> = async (lastKey) => {
214214
const result = await this.#client.personalUpdate.followingUpdates({

src/client/user.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ import { isSuccess, throwRequestFailureError } from './utils/response'
22
import { fetchPaginated } from './utils/paginate'
33
import { JikePostWithDetail } from './post'
44
import { rawTypeToEnum } from './utils/post'
5-
import type { PostDetail, SimpleUser } from '../types/entity'
5+
import type { PostDetail, PostTypeRaw, User } from '../types/entity'
66
import type { Users } from '../types/api-responses'
77
import type { PaginatedFetcher, PaginatedOption } from './utils/paginate'
88
import type { JikeClient } from './client'
99

1010
export interface FollowerWithTime {
1111
followTime?: string
12-
user: SimpleUser
12+
user: User
1313
}
1414

1515
/**
@@ -88,22 +88,25 @@ export class JikeUser<M extends boolean = boolean> {
8888
}),
8989
option
9090
)
91-
return data.map(
92-
(item) =>
93-
new JikePostWithDetail(
94-
this.#client,
95-
rawTypeToEnum(item.type),
96-
item.id,
97-
item
98-
)
99-
)
91+
92+
return data
93+
.filter((item) => item.type !== 'PERSONAL_UPDATE')
94+
.map(
95+
(item) =>
96+
new JikePostWithDetail(
97+
this.#client,
98+
rawTypeToEnum(item.type as PostTypeRaw),
99+
item.id,
100+
item
101+
)
102+
)
100103
}
101104

102105
/**
103106
* 查询用户被关注
104107
*/
105-
queryFollowers(option: PaginatedOption<SimpleUser, never, string> = {}) {
106-
const fetcher: PaginatedFetcher<SimpleUser, string> = async (lastKey) => {
108+
queryFollowers(option: PaginatedOption<User, never, string> = {}) {
109+
const fetcher: PaginatedFetcher<User, string> = async (lastKey) => {
107110
const result = await this.#client.apiClient.userRelation.getFollowerList(
108111
await this.getUsername(),
109112
{
@@ -162,8 +165,8 @@ export class JikeUser<M extends boolean = boolean> {
162165
/**
163166
* 查询用户关注
164167
*/
165-
queryFollowings(option: PaginatedOption<SimpleUser, never, string> = {}) {
166-
const fetcher: PaginatedFetcher<SimpleUser, string> = async (lastKey) => {
168+
queryFollowings(option: PaginatedOption<User, never, string> = {}) {
169+
const fetcher: PaginatedFetcher<User, string> = async (lastKey) => {
167170
const result = await this.#client.apiClient.userRelation.getFollowingList(
168171
await this.getUsername(),
169172
{ limit: 20, loadMoreKey: lastKey ? { createdAt: lastKey } : undefined }

src/types/api-responses.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable @typescript-eslint/no-namespace */
22
import type {
33
Comment,
4+
FollowingUpdate,
45
Notification,
56
PostDetail,
7+
Profile as ProfileEntity,
68
RecommendPost,
7-
SimpleUser,
89
TabIcons,
910
User,
1011
} from './entity'
@@ -35,14 +36,14 @@ export namespace Notifications {
3536

3637
export namespace UserRelation {
3738
export interface GetFollowingListResponse {
38-
data: SimpleUser[]
39+
data: User[]
3940
loadMoreKey?: {
4041
createdAt: string
4142
}
4243
}
4344

4445
export interface GetFollowerListResponse {
45-
data: SimpleUser[]
46+
data: User[]
4647
loadMoreKey?: {
4748
createdAt: string
4849
}
@@ -58,7 +59,7 @@ export namespace Users {
5859

5960
export interface LoginResponse {
6061
isRegister: boolean
61-
user: User
62+
user: ProfileEntity
6263
enabledFeatures: string[]
6364
agreedProtocol: string[]
6465
bioUpdateAlert: boolean
@@ -70,7 +71,7 @@ export namespace Users {
7071

7172
export interface GeneralProfile {
7273
/** 用户信息 */
73-
user: User
74+
user: ProfileEntity
7475
}
7576

7677
/**
@@ -82,7 +83,7 @@ export namespace Users {
8283
/** 关系用户,仅他人用户信息可见 */
8384
relationUsers?: {
8485
message: string
85-
users: SimpleUser[]
86+
users: User[]
8687
page: string
8788
}
8889
/** 是否**不**可见,仅他人用户信息可见 */
@@ -119,7 +120,7 @@ export namespace PersonalUpdate {
119120
}
120121

121122
export interface FollowingUpdatesResponse {
122-
data: PostDetail[]
123+
data: FollowingUpdate[]
123124
loadMoreKey?: {
124125
session: 'PopulatedUpdate'
125126
lastPageEarliestTime: number

0 commit comments

Comments
 (0)