Skip to content

Commit d3bb14c

Browse files
committed
format: prettier --write .
1 parent c98bf0e commit d3bb14c

File tree

6 files changed

+52
-92
lines changed

6 files changed

+52
-92
lines changed

src/schema.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,8 @@ import { z } from 'zod';
33
/** @see https://developer.chatwork.com/reference/get-rooms */
44
export const listRoomsParamsSchema = z
55
.object({
6-
offset: z
7-
.number()
8-
.int()
9-
.min(0)
10-
.default(0)
11-
.describe('取得開始位置'),
12-
limit: z
13-
.number()
14-
.int()
15-
.min(1)
16-
.max(100)
17-
.default(100)
18-
.describe('取得件数'),
6+
offset: z.number().int().min(0).default(0).describe('取得開始位置'),
7+
limit: z.number().int().min(1).max(100).default(100).describe('取得件数'),
198
})
209
.describe('チャット一覧取得');
2110

src/store/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const store = configureStore({
1111
serializableCheck: {
1212
ignoredPaths: ['rooms.rooms.timestamp'],
1313
},
14-
})
14+
}),
1515
});
1616

1717
export type RootState = ReturnType<typeof store.getState>;
@@ -25,4 +25,4 @@ export {
2525
selectRooms,
2626
selectPaginatedRooms,
2727
} from './roomsSlice';
28-
export type { Room } from '../types/room';
28+
export type { Room } from '../types/room';

src/store/roomsSlice.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('roomsSlice', () => {
134134
it('should handle cleanExpiredData - removes expired data', () => {
135135
const ttl = 300000; // 5 minutes
136136
const pastTime = Date.now() - ttl - 1000; // 1 second after expiry
137-
137+
138138
const initialState = {
139139
rooms: {
140140
data: mockRooms,
@@ -151,7 +151,7 @@ describe('roomsSlice', () => {
151151
it('should handle cleanExpiredData - keeps valid data', () => {
152152
const ttl = 300000; // 5 minutes
153153
const recentTime = Date.now() - 60000; // 1 minute ago
154-
154+
155155
const initialState = {
156156
rooms: {
157157
data: mockRooms,
@@ -187,7 +187,7 @@ describe('roomsSlice', () => {
187187
it('should return rooms data when not expired', () => {
188188
const ttl = 300000; // 5 minutes
189189
const recentTime = Date.now() - 60000; // 1 minute ago
190-
190+
191191
const state = {
192192
rooms: {
193193
rooms: {
@@ -206,7 +206,7 @@ describe('roomsSlice', () => {
206206
it('should return null when data is expired', () => {
207207
const ttl = 300000; // 5 minutes
208208
const pastTime = Date.now() - ttl - 1000; // 1 second after expiry
209-
209+
210210
const state = {
211211
rooms: {
212212
rooms: {
@@ -335,4 +335,4 @@ describe('roomsSlice', () => {
335335
});
336336
});
337337
});
338-
});
338+
});

src/store/roomsSlice.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@ export const { setRooms, clearRooms, cleanExpiredData } = roomsSlice.actions;
4545
// Selectors
4646
export const selectRooms = (state: { rooms: RoomsState }): Room[] | null => {
4747
if (!state.rooms.rooms) return null;
48-
48+
4949
const now = Date.now();
5050
const cachedData = state.rooms.rooms;
51-
51+
5252
if (now - cachedData.timestamp > cachedData.ttl) {
5353
return null;
5454
}
55-
55+
5656
return cachedData.data;
5757
};
5858

5959
export const selectPaginatedRooms = (
6060
state: { rooms: RoomsState },
6161
offset: number = 0,
62-
limit: number = 100
62+
limit: number = 100,
6363
): Room[] | null => {
6464
const rooms = selectRooms(state);
6565
if (!rooms) return null;
66-
66+
6767
return rooms.slice(offset, offset + limit);
6868
};
6969

70-
export default roomsSlice.reducer;
70+
export default roomsSlice.reducer;

src/toolCallbacks.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export const listContacts = () =>
112112
})
113113
.then(chatworkClientResponseToCallToolResult);
114114

115-
export const listRooms = async (args: z.infer<typeof listRoomsParamsSchema>): Promise<CallToolResult> => {
115+
export const listRooms = async (
116+
args: z.infer<typeof listRoomsParamsSchema>,
117+
): Promise<CallToolResult> => {
116118
const { offset = 0, limit = 100 } = args;
117119

118120
const CACHE_TTL = 5 * 60 * 1000; // 5分
@@ -134,12 +136,13 @@ export const listRooms = async (args: z.infer<typeof listRoomsParamsSchema>): Pr
134136
}
135137

136138
const allRooms = validateRoomsArray(JSON.parse(response.response));
137-
139+
138140
// Store in Redux with TTL
139141
store.dispatch(setRooms({ data: allRooms, ttl: CACHE_TTL }));
140-
142+
141143
// Get paginated data from updated store
142-
paginatedRooms = selectPaginatedRooms(store.getState(), offset, limit) || [];
144+
paginatedRooms =
145+
selectPaginatedRooms(store.getState(), offset, limit) || [];
143146
}
144147

145148
const paginatedResponse: ChatworkClientResponse = {

src/types/room.ts

Lines changed: 30 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,42 @@
11
import { z } from 'zod';
22

3-
/**
3+
/**
44
* Zod schema for ChatWork Room object
55
* @see https://developer.chatwork.com/reference/get-rooms
66
*/
77
export const roomSchema = z.object({
8-
room_id: z
9-
.number()
10-
.int()
11-
.positive()
12-
.describe('ルームID'),
13-
14-
name: z
15-
.string()
16-
.min(1)
17-
.describe('ルーム名'),
18-
8+
room_id: z.number().int().positive().describe('ルームID'),
9+
10+
name: z.string().min(1).describe('ルーム名'),
11+
1912
type: z
2013
.enum(['my', 'direct', 'group'])
21-
.describe('ルームタイプ (my: マイチャット, direct: ダイレクトチャット, group: グループチャット)'),
22-
14+
.describe(
15+
'ルームタイプ (my: マイチャット, direct: ダイレクトチャット, group: グループチャット)',
16+
),
17+
2318
role: z
2419
.enum(['admin', 'member', 'readonly'])
25-
.describe('ルールでの自分の権限 (admin: 管理者, member: メンバー, readonly: 閲覧のみ)'),
26-
27-
sticky: z
28-
.boolean()
29-
.describe('スティッキー (お気に入り) 設定'),
30-
31-
unread_num: z
32-
.number()
33-
.int()
34-
.min(0)
35-
.describe('未読メッセージ数'),
36-
37-
mention_num: z
38-
.number()
39-
.int()
40-
.min(0)
41-
.describe('自分宛てのメンション数'),
42-
43-
mytask_num: z
44-
.number()
45-
.int()
46-
.min(0)
47-
.describe('自分が担当者のタスク数'),
48-
49-
message_num: z
50-
.number()
51-
.int()
52-
.min(0)
53-
.describe('総メッセージ数'),
54-
55-
file_num: z
56-
.number()
57-
.int()
58-
.min(0)
59-
.describe('ファイル数'),
60-
61-
task_num: z
62-
.number()
63-
.int()
64-
.min(0)
65-
.describe('タスク数'),
66-
67-
icon_path: z
68-
.string()
69-
.url()
70-
.describe('ルームアイコンのURL'),
71-
20+
.describe(
21+
'ルールでの自分の権限 (admin: 管理者, member: メンバー, readonly: 閲覧のみ)',
22+
),
23+
24+
sticky: z.boolean().describe('スティッキー (お気に入り) 設定'),
25+
26+
unread_num: z.number().int().min(0).describe('未読メッセージ数'),
27+
28+
mention_num: z.number().int().min(0).describe('自分宛てのメンション数'),
29+
30+
mytask_num: z.number().int().min(0).describe('自分が担当者のタスク数'),
31+
32+
message_num: z.number().int().min(0).describe('総メッセージ数'),
33+
34+
file_num: z.number().int().min(0).describe('ファイル数'),
35+
36+
task_num: z.number().int().min(0).describe('タスク数'),
37+
38+
icon_path: z.string().url().describe('ルームアイコンのURL'),
39+
7240
last_update_time: z
7341
.number()
7442
.int()
@@ -108,4 +76,4 @@ export const safeValidateRoom = (data: unknown): Room | null => {
10876
export const safeValidateRoomsArray = (data: unknown): Room[] | null => {
10977
const result = roomsArraySchema.safeParse(data);
11078
return result.success ? result.data : null;
111-
};
79+
};

0 commit comments

Comments
 (0)