Skip to content

Commit 8f10f2b

Browse files
committed
refactor(yogurt): bundle milky types
1 parent 07b54ac commit 8f10f2b

6 files changed

Lines changed: 2080 additions & 138 deletions

File tree

yogurt-scripting/pnpm-lock.yaml

Lines changed: 5 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,26 @@
1-
/* eslint-disable */
2-
import * as types from '@saltify/milky-types';
31
import type z from 'zod';
42

5-
export interface ApiCollection {
6-
// system API
7-
get_login_info: () => Promise<types.GetLoginInfoOutput>;
8-
get_impl_info: () => Promise<types.GetImplInfoOutput>;
9-
get_user_profile: (input: z.input<typeof types.GetUserProfileInput>) => Promise<types.GetUserProfileOutput>;
10-
get_friend_list: (input: z.input<typeof types.GetFriendListInput>) => Promise<types.GetFriendListOutput>;
11-
get_friend_info: (input: z.input<typeof types.GetFriendInfoInput>) => Promise<types.GetFriendInfoOutput>;
12-
get_group_list: (input: z.input<typeof types.GetGroupListInput>) => Promise<types.GetGroupListOutput>;
13-
get_group_info: (input: z.input<typeof types.GetGroupInfoInput>) => Promise<types.GetGroupInfoOutput>;
14-
get_group_member_list: (input: z.input<typeof types.GetGroupMemberListInput>) => Promise<types.GetGroupMemberListOutput>;
15-
get_group_member_info: (input: z.input<typeof types.GetGroupMemberInfoInput>) => Promise<types.GetGroupMemberInfoOutput>;
16-
get_peer_pins: () => Promise<types.GetPeerPinsOutput>;
17-
set_peer_pin: (input: z.input<typeof types.SetPeerPinInput>) => Promise<void>;
18-
set_avatar: (input: z.input<typeof types.SetAvatarInput>) => Promise<void>;
19-
set_nickname: (input: z.input<typeof types.SetNicknameInput>) => Promise<void>;
20-
set_bio: (input: z.input<typeof types.SetBioInput>) => Promise<void>;
21-
get_custom_face_url_list: () => Promise<types.GetCustomFaceUrlListOutput>;
22-
get_cookies: (input: z.input<typeof types.GetCookiesInput>) => Promise<types.GetCookiesOutput>;
23-
get_csrf_token: () => Promise<types.GetCSRFTokenOutput>;
3+
import type { zodApiEndpoints } from './milky-types.js';
244

25-
// message API
26-
send_private_message: (input: z.input<typeof types.SendPrivateMessageInput>) => Promise<types.SendPrivateMessageOutput>;
27-
send_group_message: (input: z.input<typeof types.SendGroupMessageInput>) => Promise<types.SendGroupMessageOutput>;
28-
recall_private_message: (input: z.input<typeof types.RecallPrivateMessageInput>) => Promise<void>;
29-
recall_group_message: (input: z.input<typeof types.RecallGroupMessageInput>) => Promise<void>;
30-
get_message: (input: z.input<typeof types.GetMessageInput>) => Promise<types.GetMessageOutput>;
31-
get_history_messages: (input: z.input<typeof types.GetHistoryMessagesInput>) => Promise<types.GetHistoryMessagesOutput>;
32-
get_resource_temp_url: (input: z.input<typeof types.GetResourceTempUrlInput>) => Promise<types.GetResourceTempUrlOutput>;
33-
get_forwarded_messages: (input: z.input<typeof types.GetForwardedMessagesInput>) => Promise<types.GetForwardedMessagesOutput>;
34-
mark_message_as_read: (input: z.input<typeof types.MarkMessageAsReadInput>) => Promise<void>;
5+
type ZodApiEndpoints = typeof zodApiEndpoints;
356

36-
// friend API
37-
send_friend_nudge: (input: z.input<typeof types.SendFriendNudgeInput>) => Promise<void>;
38-
send_profile_like: (input: z.input<typeof types.SendProfileLikeInput>) => Promise<void>;
39-
delete_friend: (input: z.input<typeof types.DeleteFriendInput>) => Promise<void>;
40-
get_friend_requests: (input: z.input<typeof types.GetFriendRequestsInput>) => Promise<types.GetFriendRequestsOutput>;
41-
accept_friend_request: (input: z.input<typeof types.AcceptFriendRequestInput>) => Promise<void>;
42-
reject_friend_request: (input: z.input<typeof types.RejectFriendRequestInput>) => Promise<void>;
7+
type RequiredKeys<T> = {
8+
[K in keyof T]-?: {} extends Pick<T, K> ? never : K;
9+
}[keyof T];
4310

44-
// group API
45-
set_group_name: (input: z.input<typeof types.SetGroupNameInput>) => Promise<void>;
46-
set_group_avatar: (input: z.input<typeof types.SetGroupAvatarInput>) => Promise<void>;
47-
set_group_member_card: (input: z.input<typeof types.SetGroupMemberCardInput>) => Promise<void>;
48-
set_group_member_special_title: (input: z.input<typeof types.SetGroupMemberSpecialTitleInput>) => Promise<void>;
49-
set_group_member_admin: (input: z.input<typeof types.SetGroupMemberAdminInput>) => Promise<void>;
50-
set_group_member_mute: (input: z.input<typeof types.SetGroupMemberMuteInput>) => Promise<void>;
51-
set_group_whole_mute: (input: z.input<typeof types.SetGroupWholeMuteInput>) => Promise<void>;
52-
kick_group_member: (input: z.input<typeof types.KickGroupMemberInput>) => Promise<void>;
53-
get_group_announcements: (input: z.input<typeof types.GetGroupAnnouncementsInput>) => Promise<types.GetGroupAnnouncementsOutput>;
54-
send_group_announcement: (input: z.input<typeof types.SendGroupAnnouncementInput>) => Promise<void>;
55-
delete_group_announcement: (input: z.input<typeof types.DeleteGroupAnnouncementInput>) => Promise<void>;
56-
get_group_essence_messages: (input: z.input<typeof types.GetGroupEssenceMessagesInput>) => Promise<types.GetGroupEssenceMessagesOutput>;
57-
set_group_essence_message: (input: z.input<typeof types.SetGroupEssenceMessageInput>) => Promise<void>;
58-
quit_group: (input: z.input<typeof types.QuitGroupInput>) => Promise<void>;
59-
send_group_message_reaction: (input: z.input<typeof types.SendGroupMessageReactionInput>) => Promise<void>;
60-
send_group_nudge: (input: z.input<typeof types.SendGroupNudgeInput>) => Promise<void>;
61-
get_group_notifications: (input: z.input<typeof types.GetGroupNotificationsInput>) => Promise<types.GetGroupNotificationsOutput>;
62-
accept_group_request: (input: z.input<typeof types.AcceptGroupRequestInput>) => Promise<void>;
63-
reject_group_request: (input: z.input<typeof types.RejectGroupRequestInput>) => Promise<void>;
64-
accept_group_invitation: (input: z.input<typeof types.AcceptGroupInvitationInput>) => Promise<void>;
65-
reject_group_invitation: (input: z.input<typeof types.RejectGroupInvitationInput>) => Promise<void>;
11+
type AllOptional<T> = RequiredKeys<T> extends never ? true : false;
6612

67-
// file API
68-
upload_private_file: (input: z.input<typeof types.UploadPrivateFileInput>) => Promise<types.UploadPrivateFileOutput>;
69-
upload_group_file: (input: z.input<typeof types.UploadGroupFileInput>) => Promise<types.UploadGroupFileOutput>;
70-
get_private_file_download_url: (input: z.input<typeof types.GetPrivateFileDownloadUrlInput>) => Promise<types.GetPrivateFileDownloadUrlOutput>;
71-
get_group_file_download_url: (input: z.input<typeof types.GetGroupFileDownloadUrlInput>) => Promise<types.GetGroupFileDownloadUrlOutput>;
72-
get_group_files: (input: z.input<typeof types.GetGroupFilesInput>) => Promise<types.GetGroupFilesOutput>;
73-
move_group_file: (input: z.input<typeof types.MoveGroupFileInput>) => Promise<void>;
74-
rename_group_file: (input: z.input<typeof types.RenameGroupFileInput>) => Promise<void>;
75-
delete_group_file: (input: z.input<typeof types.DeleteGroupFileInput>) => Promise<void>;
76-
create_group_folder: (input: z.input<typeof types.CreateGroupFolderInput>) => Promise<types.CreateGroupFolderOutput>;
77-
rename_group_folder: (input: z.input<typeof types.RenameGroupFolderInput>) => Promise<void>;
78-
delete_group_folder: (input: z.input<typeof types.DeleteGroupFolderInput>) => Promise<void>;
13+
type RawApiEndpoint<E extends keyof ZodApiEndpoints> = {
14+
request: ZodApiEndpoints[E]['requestSchema'] extends null ? null : z.input<ZodApiEndpoints[E]['requestSchema']>;
15+
response: ZodApiEndpoints[E]['responseSchema'] extends null ? null : z.output<ZodApiEndpoints[E]['responseSchema']>;
16+
};
7917

80-
}
18+
type ApiEndpointFunction<E extends keyof ZodApiEndpoints> = RawApiEndpoint<E>['request'] extends null
19+
? () => Promise<RawApiEndpoint<E>['response']>
20+
: AllOptional<RawApiEndpoint<E>['request']> extends true
21+
? (params?: RawApiEndpoint<E>['request']) => Promise<RawApiEndpoint<E>['response']>
22+
: (params: RawApiEndpoint<E>['request']) => Promise<RawApiEndpoint<E>['response']>;
23+
24+
export type ApiCollection = {
25+
[E in keyof ZodApiEndpoints]: ApiEndpointFunction<E>;
26+
};

yogurt-scripting/script-api/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Event } from "@saltify/milky-types";
1+
import type { Event } from "./milky-types.js";
22
import type { ApiCollection } from "./api.js";
33

44
export interface HttpRequestOptions {

0 commit comments

Comments
 (0)