From 8065620cb5f07605141299ec20248078de70307d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 4 Jan 2023 11:29:06 -0500 Subject: [PATCH] Removing monads. Fixes #98 (#99) * Removing monads. Fixes #98 * Fixing http get params * In encode get params, dont serialize the undefineds. * v0.17.0-rc.60 --- package.json | 7 +- src/http.ts | 441 ++++++++++---------- src/index.ts | 1 - src/interfaces/api/comment.ts | 196 ++------- src/interfaces/api/community.ts | 230 ++--------- src/interfaces/api/person.ts | 508 +++++------------------ src/interfaces/api/post.ts | 244 +++-------- src/interfaces/api/site.ts | 713 +++++++------------------------- src/interfaces/others.ts | 29 +- src/interfaces/source.ts | 390 +++++------------ src/interfaces/views.ts | 303 +++----------- src/utils.ts | 15 - src/websocket.ts | 11 +- tsconfig.json | 1 + yarn.lock | 15 - 15 files changed, 764 insertions(+), 2340 deletions(-) diff --git a/package.json b/package.json index 9ca4b0a..fd57a86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lemmy-js-client", - "version": "0.17.0-rc.59", + "version": "0.17.0-rc.60", "description": "A javascript / typescript client for Lemmy", "repository": "https://github.com/LemmyNet/lemmy-js-client", "license": "AGPL-3.0", @@ -26,10 +26,7 @@ ] }, "dependencies": { - "@sniptt/monads": "^0.5.10", - "class-transformer": "^0.5.1", - "node-fetch": "2.6.6", - "reflect-metadata": "^0.1.13" + "node-fetch": "2.6.6" }, "devDependencies": { "@types/node": "^18.6.2", diff --git a/src/http.ts b/src/http.ts index c9b4397..f93231f 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,4 +1,3 @@ -import { ClassConstructor, deserialize, serialize } from "class-transformer"; import fetch from "node-fetch"; import { CommentReportResponse, @@ -166,7 +165,7 @@ export class LemmyHttp { * `HTTP.GET /site` */ async getSite(form: GetSite) { - return this.wrapper(HttpType.Get, "/site", form, GetSiteResponse); + return this.wrapper(HttpType.Get, "/site", form); } /** @@ -175,7 +174,7 @@ export class LemmyHttp { * `HTTP.POST /site` */ async createSite(form: CreateSite) { - return this.wrapper(HttpType.Post, "/site", form, SiteResponse); + return this.wrapper(HttpType.Post, "/site", form); } /** @@ -184,7 +183,7 @@ export class LemmyHttp { * `HTTP.PUT /site` */ async editSite(form: EditSite) { - return this.wrapper(HttpType.Put, "/site", form, SiteResponse); + return this.wrapper(HttpType.Put, "/site", form); } /** @@ -193,11 +192,10 @@ export class LemmyHttp { * `HTTP.POST /user/leave_admin` */ async leaveAdmin(form: LeaveAdmin) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/leave_admin", - form, - GetSiteResponse + form ); } @@ -207,7 +205,11 @@ export class LemmyHttp { * `HTTP.GET /modlog` */ async getModlog(form: GetModlog) { - return this.wrapper(HttpType.Get, "/modlog", form, GetModlogResponse); + return this.wrapper( + HttpType.Get, + "/modlog", + form + ); } /** @@ -216,7 +218,7 @@ export class LemmyHttp { * `HTTP.GET /search` */ async search(form: Search) { - return this.wrapper(HttpType.Get, "/search", form, SearchResponse); + return this.wrapper(HttpType.Get, "/search", form); } /** @@ -225,11 +227,10 @@ export class LemmyHttp { * `HTTP.GET /resolve_object` */ async resolveObject(form: ResolveObject) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/resolve_object", - form, - ResolveObjectResponse + form ); } @@ -239,7 +240,11 @@ export class LemmyHttp { * `HTTP.POST /community` */ async createCommunity(form: CreateCommunity) { - return this.wrapper(HttpType.Post, "/community", form, CommunityResponse); + return this.wrapper( + HttpType.Post, + "/community", + form + ); } /** @@ -248,7 +253,11 @@ export class LemmyHttp { * `HTTP.GET /community` */ async getCommunity(form: GetCommunity) { - return this.wrapper(HttpType.Get, "/community", form, GetCommunityResponse); + return this.wrapper( + HttpType.Get, + "/community", + form + ); } /** @@ -257,7 +266,11 @@ export class LemmyHttp { * `HTTP.PUT /community` */ async editCommunity(form: EditCommunity) { - return this.wrapper(HttpType.Put, "/community", form, CommunityResponse); + return this.wrapper( + HttpType.Put, + "/community", + form + ); } /** @@ -266,11 +279,10 @@ export class LemmyHttp { * `HTTP.GET /community/list` */ async listCommunities(form: ListCommunities) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/community/list", - form, - ListCommunitiesResponse + form ); } @@ -280,11 +292,10 @@ export class LemmyHttp { * `HTTP.POST /community/follow` */ async followCommunity(form: FollowCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/follow", - form, - CommunityResponse + form ); } @@ -294,11 +305,10 @@ export class LemmyHttp { * `HTTP.POST /community/block` */ async blockCommunity(form: BlockCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/block", - form, - BlockCommunityResponse + form ); } @@ -308,11 +318,10 @@ export class LemmyHttp { * `HTTP.POST /community/delete` */ async deleteCommunity(form: DeleteCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/delete", - form, - CommunityResponse + form ); } @@ -322,11 +331,10 @@ export class LemmyHttp { * `HTTP.POST /community/remove` */ async removeCommunity(form: RemoveCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/remove", - form, - CommunityResponse + form ); } @@ -336,11 +344,10 @@ export class LemmyHttp { * `HTTP.POST /community/transfer` */ async transferCommunity(form: TransferCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/transfer", - form, - GetCommunityResponse + form ); } @@ -350,11 +357,10 @@ export class LemmyHttp { * `HTTP.POST /community/ban_user` */ async banFromCommunity(form: BanFromCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/ban_user", - form, - BanFromCommunityResponse + form ); } @@ -364,11 +370,10 @@ export class LemmyHttp { * `HTTP.POST /community/mod` */ async addModToCommunity(form: AddModToCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/community/mod", - form, - AddModToCommunityResponse + form ); } @@ -378,7 +383,7 @@ export class LemmyHttp { * `HTTP.POST /post` */ async createPost(form: CreatePost) { - return this.wrapper(HttpType.Post, "/post", form, PostResponse); + return this.wrapper(HttpType.Post, "/post", form); } /** @@ -387,7 +392,7 @@ export class LemmyHttp { * `HTTP.GET /post` */ async getPost(form: GetPost) { - return this.wrapper(HttpType.Get, "/post", form, GetPostResponse); + return this.wrapper(HttpType.Get, "/post", form); } /** @@ -396,7 +401,7 @@ export class LemmyHttp { * `HTTP.PUT /post` */ async editPost(form: EditPost) { - return this.wrapper(HttpType.Put, "/post", form, PostResponse); + return this.wrapper(HttpType.Put, "/post", form); } /** @@ -405,7 +410,11 @@ export class LemmyHttp { * `HTTP.POST /post/delete` */ async deletePost(form: DeletePost) { - return this.wrapper(HttpType.Post, "/post/delete", form, PostResponse); + return this.wrapper( + HttpType.Post, + "/post/delete", + form + ); } /** @@ -414,7 +423,11 @@ export class LemmyHttp { * `HTTP.POST /post/remove` */ async removePost(form: RemovePost) { - return this.wrapper(HttpType.Post, "/post/remove", form, PostResponse); + return this.wrapper( + HttpType.Post, + "/post/remove", + form + ); } /** @@ -423,11 +436,10 @@ export class LemmyHttp { * `HTTP.POST /post/mark_as_read` */ async markPostAsRead(form: MarkPostAsRead) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/post/mark_as_read", - form, - PostResponse + form ); } @@ -437,7 +449,11 @@ export class LemmyHttp { * `HTTP.POST /post/lock` */ async lockPost(form: LockPost) { - return this.wrapper(HttpType.Post, "/post/lock", form, PostResponse); + return this.wrapper( + HttpType.Post, + "/post/lock", + form + ); } /** @@ -446,7 +462,11 @@ export class LemmyHttp { * `HTTP.POST /post/feature` */ async featurePost(form: FeaturePost) { - return this.wrapper(HttpType.Post, "/post/feature", form, PostResponse); + return this.wrapper( + HttpType.Post, + "/post/feature", + form + ); } /** @@ -455,7 +475,11 @@ export class LemmyHttp { * `HTTP.GET /post/list` */ async getPosts(form: GetPosts) { - return this.wrapper(HttpType.Get, "/post/list", form, GetPostsResponse); + return this.wrapper( + HttpType.Get, + "/post/list", + form + ); } /** @@ -464,7 +488,11 @@ export class LemmyHttp { * `HTTP.POST /post/like` */ async likePost(form: CreatePostLike) { - return this.wrapper(HttpType.Post, "/post/like", form, PostResponse); + return this.wrapper( + HttpType.Post, + "/post/like", + form + ); } /** @@ -473,7 +501,11 @@ export class LemmyHttp { * `HTTP.PUT /post/save` */ async savePost(form: SavePost) { - return this.wrapper(HttpType.Put, "/post/save", form, PostResponse); + return this.wrapper( + HttpType.Put, + "/post/save", + form + ); } /** @@ -482,11 +514,10 @@ export class LemmyHttp { * `HTTP.POST /post/report` */ async createPostReport(form: CreatePostReport) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/post/report", - form, - PostReportResponse + form ); } @@ -496,11 +527,10 @@ export class LemmyHttp { * `HTTP.PUT /post/report/resolve` */ async resolvePostReport(form: ResolvePostReport) { - return this.wrapper( + return this.wrapper( HttpType.Put, "/post/report/resolve", - form, - PostReportResponse + form ); } @@ -510,11 +540,10 @@ export class LemmyHttp { * `HTTP.GET /post/report/list` */ async listPostReports(form: ListPostReports) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/post/report/list", - form, - ListPostReportsResponse + form ); } @@ -524,11 +553,10 @@ export class LemmyHttp { * `HTTP.GET /post/site_metadata` */ async getSiteMetadata(form: GetSiteMetadata) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/post/site_metadata", - form, - GetSiteMetadataResponse + form ); } @@ -538,7 +566,11 @@ export class LemmyHttp { * `HTTP.POST /comment` */ async createComment(form: CreateComment) { - return this.wrapper(HttpType.Post, "/comment", form, CommentResponse); + return this.wrapper( + HttpType.Post, + "/comment", + form + ); } /** @@ -547,7 +579,11 @@ export class LemmyHttp { * `HTTP.PUT /comment` */ async editComment(form: EditComment) { - return this.wrapper(HttpType.Put, "/comment", form, CommentResponse); + return this.wrapper( + HttpType.Put, + "/comment", + form + ); } /** @@ -556,11 +592,10 @@ export class LemmyHttp { * `HTTP.POST /comment/delete` */ async deleteComment(form: DeleteComment) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/comment/delete", - form, - CommentResponse + form ); } @@ -570,11 +605,10 @@ export class LemmyHttp { * `HTTP.POST /comment/remove` */ async removeComment(form: RemoveComment) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/comment/remove", - form, - CommentResponse + form ); } @@ -584,11 +618,10 @@ export class LemmyHttp { * `HTTP.POST /comment/mark_as_read` */ async markCommentReplyAsRead(form: MarkCommentReplyAsRead) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/comment/mark_as_read", - form, - CommentResponse + form ); } @@ -598,7 +631,11 @@ export class LemmyHttp { * `HTTP.POST /comment/like` */ async likeComment(form: CreateCommentLike) { - return this.wrapper(HttpType.Post, "/comment/like", form, CommentResponse); + return this.wrapper( + HttpType.Post, + "/comment/like", + form + ); } /** @@ -607,7 +644,11 @@ export class LemmyHttp { * `HTTP.PUT /comment/save` */ async saveComment(form: SaveComment) { - return this.wrapper(HttpType.Put, "/comment/save", form, CommentResponse); + return this.wrapper( + HttpType.Put, + "/comment/save", + form + ); } /** @@ -616,11 +657,10 @@ export class LemmyHttp { * `HTTP.GET /comment/list` */ async getComments(form: GetComments) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/comment/list", - form, - GetCommentsResponse + form ); } @@ -630,11 +670,10 @@ export class LemmyHttp { * `HTTP.POST /comment/report` */ async createCommentReport(form: CreateCommentReport) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/comment/report", - form, - CommentReportResponse + form ); } @@ -644,11 +683,10 @@ export class LemmyHttp { * `HTTP.PUT /comment/report/resolve` */ async resolveCommentReport(form: ResolveCommentReport) { - return this.wrapper( + return this.wrapper( HttpType.Put, "/comment/report/resolve", - form, - CommentReportResponse + form ); } @@ -658,11 +696,10 @@ export class LemmyHttp { * `HTTP.GET /comment/report/list` */ async listCommentReports(form: ListCommentReports) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/comment/report/list", - form, - ListCommentReportsResponse + form ); } @@ -672,11 +709,10 @@ export class LemmyHttp { * `HTTP.GET /private_message/list` */ async getPrivateMessages(form: GetPrivateMessages) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/private_message/list", - form, - PrivateMessagesResponse + form ); } @@ -686,11 +722,10 @@ export class LemmyHttp { * `HTTP.POST /private_message` */ async createPrivateMessage(form: CreatePrivateMessage) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/private_message", - form, - PrivateMessageResponse + form ); } @@ -700,11 +735,10 @@ export class LemmyHttp { * `HTTP.PUT /private_message` */ async editPrivateMessage(form: EditPrivateMessage) { - return this.wrapper( + return this.wrapper( HttpType.Put, "/private_message", - form, - PrivateMessageResponse + form ); } @@ -714,11 +748,10 @@ export class LemmyHttp { * `HTTP.POST /private_message/delete` */ async deletePrivateMessage(form: DeletePrivateMessage) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/private_message/delete", - form, - PrivateMessageResponse + form ); } @@ -728,11 +761,10 @@ export class LemmyHttp { * `HTTP.POST /private_message/mark_as_read` */ async markPrivateMessageAsRead(form: MarkPrivateMessageAsRead) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/private_message/mark_as_read", - form, - PrivateMessageResponse + form ); } @@ -742,12 +774,10 @@ export class LemmyHttp { * `HTTP.POST /private_message/report` */ async createPrivateMessageReport(form: CreatePrivateMessageReport) { - return this.wrapper( - HttpType.Post, - "/private_message/report", - form, + return this.wrapper< + CreatePrivateMessageReport, PrivateMessageReportResponse - ); + >(HttpType.Post, "/private_message/report", form); } /** @@ -756,12 +786,10 @@ export class LemmyHttp { * `HTTP.PUT /private_message/report/resolve` */ async resolvePrivateMessageReport(form: ResolvePrivateMessageReport) { - return this.wrapper( - HttpType.Put, - "/private_message/report/resolve", - form, + return this.wrapper< + ResolvePrivateMessageReport, PrivateMessageReportResponse - ); + >(HttpType.Put, "/private_message/report/resolve", form); } /** @@ -770,12 +798,10 @@ export class LemmyHttp { * `HTTP.GET /private_message/report/list` */ async listPrivateMessageReports(form: ListPrivateMessageReports) { - return this.wrapper( - HttpType.Get, - "/private_message/report/list", - form, + return this.wrapper< + ListPrivateMessageReports, ListPrivateMessageReportsResponse - ); + >(HttpType.Get, "/private_message/report/list", form); } /** @@ -784,7 +810,11 @@ export class LemmyHttp { * `HTTP.POST /user/register` */ async register(form: Register) { - return this.wrapper(HttpType.Post, "/user/register", form, LoginResponse); + return this.wrapper( + HttpType.Post, + "/user/register", + form + ); } /** @@ -793,7 +823,11 @@ export class LemmyHttp { * `HTTP.POST /user/login` */ async login(form: Login) { - return this.wrapper(HttpType.Post, "/user/login", form, LoginResponse); + return this.wrapper( + HttpType.Post, + "/user/login", + form + ); } /** @@ -802,7 +836,11 @@ export class LemmyHttp { * `HTTP.GET /user` */ async getPersonDetails(form: GetPersonDetails) { - return this.wrapper(HttpType.Get, "/user", form, GetPersonDetailsResponse); + return this.wrapper( + HttpType.Get, + "/user", + form + ); } /** @@ -811,11 +849,10 @@ export class LemmyHttp { * `HTTP.GET /user/mention` */ async getPersonMentions(form: GetPersonMentions) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/mention", - form, - GetPersonMentionsResponse + form ); } @@ -825,11 +862,10 @@ export class LemmyHttp { * `HTTP.POST /user/mention/mark_as_read` */ async markPersonMentionAsRead(form: MarkPersonMentionAsRead) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/mention/mark_as_read", - form, - PersonMentionResponse + form ); } @@ -839,11 +875,10 @@ export class LemmyHttp { * `HTTP.GET /user/replies` */ async getReplies(form: GetReplies) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/replies", - form, - GetRepliesResponse + form ); } @@ -853,7 +888,11 @@ export class LemmyHttp { * `HTTP.POST /user/ban` */ async banPerson(form: BanPerson) { - return this.wrapper(HttpType.Post, "/user/ban", form, BanPersonResponse); + return this.wrapper( + HttpType.Post, + "/user/ban", + form + ); } /** @@ -862,11 +901,10 @@ export class LemmyHttp { * `HTTP.GET /user/banned` */ async getBannedPersons(form: GetBannedPersons) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/banned", - form, - BannedPersonsResponse + form ); } @@ -876,11 +914,10 @@ export class LemmyHttp { * `HTTP.POST /user/block` */ async blockPerson(form: BlockPerson) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/block", - form, - BlockPersonResponse + form ); } @@ -890,11 +927,10 @@ export class LemmyHttp { * `HTTP.GET /user/get_captcha` */ async getCaptcha() { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/get_captcha", - {}, - GetCaptchaResponse + {} ); } @@ -904,11 +940,10 @@ export class LemmyHttp { * `HTTP.POST /user/delete_account` */ async deleteAccount(form: DeleteAccount) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/delete_account", - form, - DeleteAccountResponse + form ); } @@ -918,11 +953,10 @@ export class LemmyHttp { * `HTTP.POST /user/password_reset` */ async passwordReset(form: PasswordReset) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/password_reset", - form, - PasswordResetResponse + form ); } @@ -932,11 +966,10 @@ export class LemmyHttp { * `HTTP.POST /user/password_change` */ async passwordChange(form: PasswordChange) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/password_change", - form, - LoginResponse + form ); } @@ -946,11 +979,10 @@ export class LemmyHttp { * `HTTP.POST /user/mark_all_as_read` */ async markAllAsRead(form: MarkAllAsRead) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/mark_all_as_read", - form, - GetRepliesResponse + form ); } @@ -960,11 +992,10 @@ export class LemmyHttp { * `HTTP.PUT /user/save_user_settings` */ async saveUserSettings(form: SaveUserSettings) { - return this.wrapper( + return this.wrapper( HttpType.Put, "/user/save_user_settings", - form, - LoginResponse + form ); } @@ -974,11 +1005,10 @@ export class LemmyHttp { * `HTTP.PUT /user/change_password` */ async changePassword(form: ChangePassword) { - return this.wrapper( + return this.wrapper( HttpType.Put, "/user/change_password", - form, - LoginResponse + form ); } @@ -988,11 +1018,10 @@ export class LemmyHttp { * `HTTP.GET /user/report_count` */ async getReportCount(form: GetReportCount) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/report_count", - form, - GetReportCountResponse + form ); } @@ -1002,11 +1031,10 @@ export class LemmyHttp { * `HTTP.GET /user/unread_count` */ async getUnreadCount(form: GetUnreadCount) { - return this.wrapper( + return this.wrapper( HttpType.Get, "/user/unread_count", - form, - GetUnreadCountResponse + form ); } @@ -1016,11 +1044,10 @@ export class LemmyHttp { * `HTTP.POST /user/verify_email` */ async verifyEmail(form: VerifyEmail) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/user/verify_email", - form, - VerifyEmailResponse + form ); } @@ -1030,7 +1057,11 @@ export class LemmyHttp { * `HTTP.POST /admin/add` */ async addAdmin(form: AddAdmin) { - return this.wrapper(HttpType.Post, "/admin/add", form, AddAdminResponse); + return this.wrapper( + HttpType.Post, + "/admin/add", + form + ); } /** @@ -1041,12 +1072,10 @@ export class LemmyHttp { async getUnreadRegistrationApplicationCount( form: GetUnreadRegistrationApplicationCount ) { - return this.wrapper( - HttpType.Get, - "/admin/registration_application/count", - form, + return this.wrapper< + GetUnreadRegistrationApplicationCount, GetUnreadRegistrationApplicationCountResponse - ); + >(HttpType.Get, "/admin/registration_application/count", form); } /** @@ -1055,12 +1084,10 @@ export class LemmyHttp { * `HTTP.GET /admin/registration_application/list` */ async listRegistrationApplications(form: ListRegistrationApplications) { - return this.wrapper( - HttpType.Get, - "/admin/registration_application/list", - form, + return this.wrapper< + ListRegistrationApplications, ListRegistrationApplicationsResponse - ); + >(HttpType.Get, "/admin/registration_application/list", form); } /** @@ -1069,12 +1096,10 @@ export class LemmyHttp { * `HTTP.PUT /admin/registration_application/approve` */ async approveRegistrationApplication(form: ApproveRegistrationApplication) { - return this.wrapper( - HttpType.Put, - "/admin/registration_application/approve", - form, + return this.wrapper< + ApproveRegistrationApplication, RegistrationApplicationResponse - ); + >(HttpType.Put, "/admin/registration_application/approve", form); } /** @@ -1083,11 +1108,10 @@ export class LemmyHttp { * `HTTP.POST /admin/purge/person` */ async purgePerson(form: PurgePerson) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/admin/purge/person", - form, - PurgeItemResponse + form ); } @@ -1097,11 +1121,10 @@ export class LemmyHttp { * `HTTP.POST /admin/purge/community` */ async purgeCommunity(form: PurgeCommunity) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/admin/purge/community", - form, - PurgeItemResponse + form ); } @@ -1111,11 +1134,10 @@ export class LemmyHttp { * `HTTP.POST /admin/purge/post` */ async purgePost(form: PurgePost) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/admin/purge/post", - form, - PurgeItemResponse + form ); } @@ -1125,11 +1147,10 @@ export class LemmyHttp { * `HTTP.POST /admin/purge/comment` */ async purgeComment(form: PurgeComment) { - return this.wrapper( + return this.wrapper( HttpType.Post, "/admin/purge/comment", - form, - PurgeItemResponse + form ); } @@ -1137,23 +1158,17 @@ export class LemmyHttp { return `${this.apiUrl}${endpoint}`; } - private async wrapper( + private async wrapper( type_: HttpType, endpoint: string, - form: BodyType, - responseClass: ClassConstructor + form: BodyType ): Promise { if (type_ == HttpType.Get) { let getUrl = `${this.buildFullUrl(endpoint)}?${encodeGetParams(form)}`; return fetch(getUrl, { method: "GET", headers: this.headers, - }).then( - d => - d - .text() - .then(a => deserialize(responseClass, a)) as Promise - ); + }).then(d => d.json() as Promise); } else { return fetch(this.buildFullUrl(endpoint), { method: type_, @@ -1161,21 +1176,15 @@ export class LemmyHttp { "Content-Type": "application/json", ...this.headers, }, - body: serialize(form), - }).then( - d => - d - .text() - .then(a => deserialize(responseClass, a)) as Promise - ); + body: JSON.stringify(form), + }).then(d => d.json() as Promise); } } } -function encodeGetParams(p: BodyType): string { - // Necessary to remove the Options - let serialized = JSON.parse(serialize(p)); - return Object.entries(serialized) +function encodeGetParams(p: BodyType): string { + return Object.entries(p) + .filter(kv => !!kv[1]) .map(kv => kv.map(encodeURIComponent).join("=")) .join("&"); } diff --git a/src/index.ts b/src/index.ts index 7477d8a..dc09883 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ export * from "./http"; export * from "./interfaces"; -export * from "./utils"; export * from "./websocket"; diff --git a/src/interfaces/api/comment.ts b/src/interfaces/api/comment.ts index 5f2f78c..d72d6ac 100644 --- a/src/interfaces/api/comment.ts +++ b/src/interfaces/api/comment.ts @@ -1,127 +1,71 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../../utils"; import { CommentSortType, ListingType } from "../others"; import { CommentReportView, CommentView } from "../views"; -export class CreateComment { +export interface CreateComment { content: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - parent_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - language_id: Option; + parent_id?: number; + language_id?: number; post_id: number; /** * An optional front end ID, to tell which is comment is coming back. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - form_id: Option; + form_id?: string; auth: string; - - constructor(init: CreateComment) { - Object.assign(this, init); - } } -export class EditComment { +export interface EditComment { comment_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - content: Option; + content?: string; /** * "Distinguishes" a comment, or speak officially. Only doable by community mods or admins. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - distinguished: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - language_id: Option; + distinguished?: boolean; + language_id?: number; /** * An optional front end ID, to tell which is comment is coming back. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - form_id: Option; + form_id?: string; auth: string; - - constructor(init: EditComment) { - Object.assign(this, init); - } } /** * Only the creator can delete the comment. */ -export class DeleteComment { +export interface DeleteComment { comment_id: number; deleted: boolean; auth: string; - - constructor(init: DeleteComment) { - Object.assign(this, init); - } } /** * Only a mod or admin can remove the comment. */ -export class RemoveComment { +export interface RemoveComment { comment_id: number; removed: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: RemoveComment) { - Object.assign(this, init); - } } -export class SaveComment { +export interface SaveComment { comment_id: number; save: boolean; auth: string; - - constructor(init: SaveComment) { - Object.assign(this, init); - } } -export class CommentResponse { - @Type(() => CommentView) +export interface CommentResponse { comment_view: CommentView; recipient_ids: number[]; /** * An optional front end ID, to tell which is comment is coming back. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - form_id: Option; + form_id?: string; } -export class CreateCommentLike { +export interface CreateCommentLike { comment_id: number; score: number; auth: string; - - constructor(init: CreateCommentLike) { - Object.assign(this, init); - } } /** @@ -130,122 +74,58 @@ export class CreateCommentLike { * You can use either `community_id` or `community_name` as an id. * To get posts for a federated community by name, use `name@instance.tld` . */ -export class GetComments { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - type_: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - max_depth: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - post_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - parent_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - saved_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetComments) { - Object.assign(this, init); - } +export interface GetComments { + type_?: ListingType; + sort?: CommentSortType; + max_depth?: number; + page?: number; + limit?: number; + community_id?: number; + community_name?: string; + post_id?: number; + parent_id?: number; + saved_only?: boolean; + auth?: string; } -export class GetCommentsResponse { - @Type(() => CommentView) +export interface GetCommentsResponse { comments: CommentView[]; } -export class CreateCommentReport { +export interface CreateCommentReport { comment_id: number; reason: string; auth: string; - - constructor(init: CreateCommentReport) { - Object.assign(this, init); - } } -export class CommentReportResponse { - @Type(() => CommentReportView) +export interface CommentReportResponse { comment_report_view: CommentReportView; } -export class ResolveCommentReport { +export interface ResolveCommentReport { report_id: number; /** * Either resolve or unresolve a report. */ resolved: boolean; auth: string; - - constructor(init: ResolveCommentReport) { - Object.assign(this, init); - } } -export class ListCommentReports { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; +export interface ListCommentReports { + page?: number; + limit?: number; /** * if no community is given, it returns reports for all communities moderated by the auth user. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; + community_id?: number; /** * Only shows the unresolved reports. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unresolved_only: Option; + unresolved_only?: boolean; auth: string; - - constructor(init: ListCommentReports) { - Object.assign(this, init); - } } -export class ListCommentReportsResponse { - @Type(() => CommentReportView) +export interface ListCommentReportsResponse { comment_reports: CommentReportView[]; } diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index 6130918..521cf42 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -1,7 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../../utils"; import { ListingType, SortType } from "../others"; import { Site } from "../source"; import { @@ -15,116 +11,51 @@ import { * * To get a federated community by name, use `name@instance.tld` . */ -export class GetCommunity { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetCommunity) { - Object.assign(this, init); - } +export interface GetCommunity { + id?: number; + name?: string; + auth?: string; } -export class GetCommunityResponse { - @Type(() => CommunityView) +export interface GetCommunityResponse { community_view: CommunityView; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => Site) - site: Option; - @Type(() => CommunityModeratorView) + site?: Site; moderators: CommunityModeratorView[]; online: number; discussion_languages: number[]; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_post_language: Option; + default_post_language?: number; } -export class CreateCommunity { +export interface CreateCommunity { name: string; title: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - posting_restricted_to_mods: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - discussion_languages: Option; + description?: string; + icon?: string; + banner?: string; + nsfw?: boolean; + posting_restricted_to_mods?: boolean; + discussion_languages?: number[]; auth: string; - - constructor(init: CreateCommunity) { - Object.assign(this, init); - } } -export class CommunityResponse { - @Type(() => CommunityView) +export interface CommunityResponse { community_view: CommunityView; discussion_languages: number[]; } -export class ListCommunities { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - type_: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: ListCommunities) { - Object.assign(this, init); - } +export interface ListCommunities { + type_?: ListingType; + sort?: SortType; + page?: number; + limit?: number; + auth?: string; } -export class ListCommunitiesResponse { - @Type(() => CommunityView) +export interface ListCommunitiesResponse { communities: CommunityView[]; } -export class BanFromCommunity { +export interface BanFromCommunity { community_id: number; person_id: number; ban: boolean; @@ -132,156 +63,85 @@ export class BanFromCommunity { /** * Removes/Restores their comments and posts for that community. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - remove_data: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + remove_data?: boolean; + reason?: string; /** * The expire time in Unix seconds */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + expires?: number; auth: string; - - constructor(init: BanFromCommunity) { - Object.assign(this, init); - } } -export class BanFromCommunityResponse { - @Type(() => PersonViewSafe) +export interface BanFromCommunityResponse { person_view: PersonViewSafe; banned: boolean; } -export class AddModToCommunity { +export interface AddModToCommunity { community_id: number; person_id: number; added: boolean; auth: string; - - constructor(init: AddModToCommunity) { - Object.assign(this, init); - } } -export class AddModToCommunityResponse { - @Type(() => CommunityModeratorView) +export interface AddModToCommunityResponse { moderators: CommunityModeratorView[]; } /** * Only mods can edit a community. */ -export class EditCommunity { +export interface EditCommunity { community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - title: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - posting_restricted_to_mods: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - discussion_languages: Option; + title?: string; + description?: string; + icon?: string; + banner?: string; + nsfw?: boolean; + posting_restricted_to_mods?: boolean; + discussion_languages?: number[]; auth: string; - - constructor(init: EditCommunity) { - Object.assign(this, init); - } } -export class DeleteCommunity { +export interface DeleteCommunity { community_id: number; deleted: boolean; auth: string; - - constructor(init: DeleteCommunity) { - Object.assign(this, init); - } } /** * Only admins can remove a community. */ -export class RemoveCommunity { +export interface RemoveCommunity { community_id: number; removed: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; /** * The expire time in Unix seconds */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + expires?: number; auth: string; - - constructor(init: RemoveCommunity) { - Object.assign(this, init); - } } -export class FollowCommunity { +export interface FollowCommunity { community_id: number; follow: boolean; auth: string; - - constructor(init: FollowCommunity) { - Object.assign(this, init); - } } -export class TransferCommunity { +export interface TransferCommunity { community_id: number; person_id: number; auth: string; - - constructor(init: TransferCommunity) { - Object.assign(this, init); - } } -export class BlockCommunity { +export interface BlockCommunity { community_id: number; block: boolean; auth: string; - - constructor(init: BlockCommunity) { - Object.assign(this, init); - } } -export class BlockCommunityResponse { - @Type(() => CommunityView) +export interface BlockCommunityResponse { community_view: CommunityView; blocked: boolean; } diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index 247ff6b..81dfc69 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -1,7 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../../utils"; import { CommentSortType, SortType } from "../others"; import { CommentReplyView, @@ -14,13 +10,9 @@ import { PrivateMessageView, } from "../views"; -export class Login { +export interface Login { username_or_email: string; password: string; - - constructor(init: Login) { - Object.assign(this, init); - } } /** @@ -28,60 +20,37 @@ export class Login { * * Only the first user to register will be able to be the admin. */ -export class Register { +export interface Register { username: string; /** * Email is mandatory if email verification is enabled on the server */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - email: Option; + email?: string; password: string; password_verify: string; show_nsfw: boolean; /** * Captcha is only checked if these are enabled in the server. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_uuid: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_answer: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - honeypot: Option; + captcha_uuid?: string; + captcha_answer?: string; + honeypot?: string; /** * An answer is mandatory if require application is enabled on the server */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - answer: Option; - - constructor(init: Register) { - Object.assign(this, init); - } + answer?: string; } -export class GetCaptcha {} +export interface GetCaptcha {} -export class GetCaptchaResponse { +export interface GetCaptchaResponse { /** * Will be undefined if captchas are disabled. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => CaptchaResponse) - ok: Option; + ok?: CaptchaResponse; } -export class CaptchaResponse { +export interface CaptchaResponse { /** * A Base64 encoded png. */ @@ -90,10 +59,7 @@ export class CaptchaResponse { /** * A Base64 encoded wav file. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - wav: Option; + wav?: string; /** * A UUID to match the one given on request. @@ -101,563 +67,299 @@ export class CaptchaResponse { uuid: string; } -export class SaveUserSettings { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_nsfw: Option; +export interface SaveUserSettings { + show_nsfw?: boolean; /** * Default for this is `browser`. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - theme: Option; + theme?: string; /** * The [[SortType]]. * * The Sort types from above, zero indexed as a number */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_sort_type: Option; + default_sort_type?: number; /** * The [[ListingType]]. * * Post listing types are `All, Subscribed, Community` */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_listing_type: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - interface_language: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - avatar: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - display_name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - email: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - bio: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - matrix_user_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_avatars: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_scores: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - send_notifications_to_email: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - bot_account: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_bot_accounts: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_read_posts: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - show_new_post_notifs: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - discussion_languages: Option; + default_listing_type?: number; + interface_language?: string; + avatar?: string; + banner?: string; + display_name?: string; + email?: string; + bio?: string; + matrix_user_id?: string; + show_avatars?: boolean; + show_scores?: boolean; + send_notifications_to_email?: boolean; + bot_account?: boolean; + show_bot_accounts?: boolean; + show_read_posts?: boolean; + show_new_post_notifs?: boolean; + discussion_languages?: number[]; auth: string; - - constructor(init: SaveUserSettings) { - Object.assign(this, init); - } } -export class ChangePassword { +export interface ChangePassword { new_password: string; new_password_verify: string; old_password: string; auth: string; - - constructor(init: ChangePassword) { - Object.assign(this, init); - } } /** * The `jwt` string should be stored and used anywhere `auth` is called for. */ -export class LoginResponse { +export interface LoginResponse { /** * This is None in response to `Register` if email verification is enabled, or the server requires registration applications. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - jwt: Option; + jwt?: string; verify_email_sent: boolean; registration_created: boolean; } -export class GetPersonDetails { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - person_id: Option; +export interface GetPersonDetails { + person_id?: number; /** * To get details for a federated user, use `person@instance.tld`. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - username: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - saved_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetPersonDetails) { - Object.assign(this, init); - } + username?: string; + sort?: SortType; + page?: number; + limit?: number; + community_id?: number; + saved_only?: boolean; + auth?: string; } -export class GetPersonDetailsResponse { - @Type(() => PersonViewSafe) +export interface GetPersonDetailsResponse { person_view: PersonViewSafe; - @Type(() => CommentView) comments: CommentView[]; - @Type(() => PostView) posts: PostView[]; - @Type(() => CommunityModeratorView) moderates: CommunityModeratorView[]; } -export class GetRepliesResponse { - @Type(() => CommentReplyView) +export interface GetRepliesResponse { replies: CommentReplyView[]; } -export class GetPersonMentionsResponse { - @Type(() => PersonMentionView) +export interface GetPersonMentionsResponse { mentions: PersonMentionView[]; } -export class MarkAllAsRead { +export interface MarkAllAsRead { auth: string; - - constructor(auth: string) { - this.auth = auth; - } } -export class AddAdmin { +export interface AddAdmin { person_id: number; added: boolean; auth: string; - - constructor(init: AddAdmin) { - Object.assign(this, init); - } } -export class AddAdminResponse { - @Type(() => PersonViewSafe) +export interface AddAdminResponse { admins: PersonViewSafe[]; } -export class BanPerson { +export interface BanPerson { person_id: number; ban: boolean; /** * Removes/Restores their comments, posts, and communities */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - remove_data: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + remove_data?: boolean; + reason?: string; /** * The expire time in Unix seconds */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + expires?: number; auth: string; - - constructor(init: BanPerson) { - Object.assign(this, init); - } } -export class BanPersonResponse { - @Type(() => PersonViewSafe) +export interface BanPersonResponse { person_view: PersonViewSafe; banned: boolean; } -export class GetReplies { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unread_only: Option; +export interface GetReplies { + sort?: CommentSortType; + page?: number; + limit?: number; + unread_only?: boolean; auth: string; - - constructor(init: GetReplies) { - Object.assign(this, init); - } } -export class GetPersonMentions { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unread_only: Option; +export interface GetPersonMentions { + sort?: CommentSortType; + page?: number; + limit?: number; + unread_only?: boolean; auth: string; - - constructor(init: GetPersonMentions) { - Object.assign(this, init); - } } -export class MarkPersonMentionAsRead { +export interface MarkPersonMentionAsRead { person_mention_id: number; read: boolean; auth: string; - - constructor(init: MarkPersonMentionAsRead) { - Object.assign(this, init); - } } -export class PersonMentionResponse { - @Type(() => PersonMentionView) +export interface PersonMentionResponse { person_mention_view: PersonMentionView; } -export class MarkCommentReplyAsRead { +export interface MarkCommentReplyAsRead { comment_reply_id: number; read: boolean; auth: string; - - constructor(init: MarkCommentReplyAsRead) { - Object.assign(this, init); - } } -export class CommentReplyResponse { - @Type(() => CommentReplyView) +export interface CommentReplyResponse { comment_reply_view: CommentReplyView; } /** * Permanently deletes your posts and comments */ -export class DeleteAccount { +export interface DeleteAccount { password: string; auth: string; - - constructor(init: DeleteAccount) { - Object.assign(this, init); - } } -export class DeleteAccountResponse {} +export interface DeleteAccountResponse {} -export class PasswordReset { +export interface PasswordReset { email: string; - - constructor(init: PasswordReset) { - Object.assign(this, init); - } } -export class PasswordResetResponse {} +export interface PasswordResetResponse {} -export class PasswordChange { +export interface PasswordChange { token: string; password: string; password_verify: string; - - constructor(init: PasswordChange) { - Object.assign(this, init); - } } -export class CreatePrivateMessage { +export interface CreatePrivateMessage { content: string; recipient_id: number; auth: string; - - constructor(init: CreatePrivateMessage) { - Object.assign(this, init); - } } -export class EditPrivateMessage { +export interface EditPrivateMessage { private_message_id: number; content: string; auth: string; - - constructor(init: EditPrivateMessage) { - Object.assign(this, init); - } } -export class DeletePrivateMessage { +export interface DeletePrivateMessage { private_message_id: number; deleted: boolean; auth: string; - - constructor(init: DeletePrivateMessage) { - Object.assign(this, init); - } } -export class MarkPrivateMessageAsRead { +export interface MarkPrivateMessageAsRead { private_message_id: number; read: boolean; auth: string; - - constructor(init: MarkPrivateMessageAsRead) { - Object.assign(this, init); - } } -export class GetPrivateMessages { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unread_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; +export interface GetPrivateMessages { + unread_only?: boolean; + page?: number; + limit?: number; auth: string; - - constructor(init: GetPrivateMessages) { - Object.assign(this, init); - } } -export class PrivateMessagesResponse { - @Type(() => PrivateMessageView) +export interface PrivateMessagesResponse { private_messages: PrivateMessageView[]; } -export class PrivateMessageResponse { - @Type(() => PrivateMessageView) +export interface PrivateMessageResponse { private_message_view: PrivateMessageView; } -export class CreatePrivateMessageReport { +export interface CreatePrivateMessageReport { private_message_id: number; reason: string; auth: string; - - constructor(init: CreatePrivateMessageReport) { - Object.assign(this, init); - } } -export class PrivateMessageReportResponse { - @Type(() => PrivateMessageReportView) +export interface PrivateMessageReportResponse { private_message_report_view: PrivateMessageReportView; } -export class ResolvePrivateMessageReport { +export interface ResolvePrivateMessageReport { report_id: number; resolved: boolean; auth: string; - - constructor(init: ResolvePrivateMessageReport) { - Object.assign(this, init); - } } -export class ListPrivateMessageReports { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; +export interface ListPrivateMessageReports { + page?: number; + limit?: number; /// Only shows the unresolved reports - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unresolved_only: Option; + unresolved_only?: boolean; auth: string; - - constructor(init: ListPrivateMessageReports) { - Object.assign(this, init); - } } -export class ListPrivateMessageReportsResponse { - @Type(() => PrivateMessageReportView) +export interface ListPrivateMessageReportsResponse { private_message_reports: PrivateMessageReportView[]; } -export class GetReportCount { +export interface GetReportCount { /** * If a community is supplied, returns the report count for only that community, otherwise returns the report count for all communities the user moderates. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; + community_id?: number; auth: string; - - constructor(init: GetReportCount) { - Object.assign(this, init); - } } -export class GetReportCountResponse { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; +export interface GetReportCountResponse { + community_id?: number; comment_reports: number; post_reports: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - private_message_reports: Option; + private_message_reports?: number; } -export class GetUnreadCount { +export interface GetUnreadCount { auth: string; - - constructor(init: GetUnreadCount) { - Object.assign(this, init); - } } -export class GetUnreadCountResponse { +export interface GetUnreadCountResponse { replies: number; mentions: number; private_messages: number; } -export class VerifyEmail { +export interface VerifyEmail { token: string; - - constructor(init: VerifyEmail) { - Object.assign(this, init); - } } -export class VerifyEmailResponse {} +export interface VerifyEmailResponse {} -export class BlockPerson { +export interface BlockPerson { person_id: number; block: boolean; auth: string; - - constructor(init: BlockPerson) { - Object.assign(this, init); - } } -export class BlockPersonResponse { - @Type(() => PersonViewSafe) +export interface BlockPersonResponse { person_view: PersonViewSafe; blocked: boolean; } -export class GetBannedPersons { +export interface GetBannedPersons { auth: string; - - constructor(init: GetBannedPersons) { - Object.assign(this, init); - } } -export class BannedPersonsResponse { - @Type(() => PersonViewSafe) +export interface BannedPersonsResponse { banned: PersonViewSafe[]; } diff --git a/src/interfaces/api/post.ts b/src/interfaces/api/post.ts index 5ba1d35..333305d 100644 --- a/src/interfaces/api/post.ts +++ b/src/interfaces/api/post.ts @@ -1,7 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../../utils"; import { ListingType, PostFeatureType, @@ -15,118 +11,53 @@ import { PostView, } from "../views"; -export class CreatePost { +export interface CreatePost { name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - body: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - language_id: Option; + url?: string; + body?: string; + nsfw?: boolean; + language_id?: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - honeypot: Option; + honeypot?: string; auth: string; - - constructor(init: CreatePost) { - Object.assign(this, init); - } } -export class PostResponse { - @Type(() => PostView) +export interface PostResponse { post_view: PostView; } -export class GetPost { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - comment_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetPost) { - Object.assign(this, init); - } +export interface GetPost { + id?: number; + comment_id?: number; + auth?: string; } -export class GetPostResponse { - @Type(() => PostView) +export interface GetPostResponse { post_view: PostView; - @Type(() => CommunityView) community_view: CommunityView; - @Type(() => CommunityModeratorView) moderators: CommunityModeratorView[]; online: number; } -export class GetPosts { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - type_: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; +export interface GetPosts { + type_?: ListingType; + sort?: SortType; + page?: number; + limit?: number; + community_id?: number; /** * To get posts for a federated community by name, use `name@instance.tld` . */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - saved_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetPosts) { - Object.assign(this, init); - } + community_name?: string; + saved_only?: boolean; + auth?: string; } -export class GetPostsResponse { - @Type(() => PostView) +export interface GetPostsResponse { posts: PostView[]; } -export class CreatePostLike { +export interface CreatePostLike { post_id: number; /** @@ -134,190 +65,109 @@ export class CreatePostLike { */ score: number; auth: string; - - constructor(init: CreatePostLike) { - Object.assign(this, init); - } } -export class EditPost { +export interface EditPost { post_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - body: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - language_id: Option; + name?: string; + url?: string; + body?: string; + nsfw?: boolean; + language_id?: number; auth: string; - - constructor(init: EditPost) { - Object.assign(this, init); - } } -export class DeletePost { +export interface DeletePost { post_id: number; deleted: boolean; auth: string; - - constructor(init: DeletePost) { - Object.assign(this, init); - } } /** * Only admins and mods can remove a post. */ -export class RemovePost { +export interface RemovePost { post_id: number; removed: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: RemovePost) { - Object.assign(this, init); - } } /** * Marks a post as read. */ -export class MarkPostAsRead { +export interface MarkPostAsRead { post_id: number; read: boolean; auth: string; - - constructor(init: MarkPostAsRead) { - Object.assign(this, init); - } } /** * Only admins and mods can lock a post. */ -export class LockPost { +export interface LockPost { post_id: number; locked: boolean; auth: string; - - constructor(init: LockPost) { - Object.assign(this, init); - } } /** * Only admins and mods can feature a community post. */ -export class FeaturePost { +export interface FeaturePost { post_id: number; featured: boolean; feature_type: PostFeatureType; auth: string; - - constructor(init: FeaturePost) { - Object.assign(this, init); - } } -export class SavePost { +export interface SavePost { post_id: number; save: boolean; auth: string; - - constructor(init: SavePost) { - Object.assign(this, init); - } } -export class CreatePostReport { +export interface CreatePostReport { post_id: number; reason: string; auth: string; - - constructor(init: CreatePostReport) { - Object.assign(this, init); - } } -export class PostReportResponse { - @Type(() => PostReportView) +export interface PostReportResponse { post_report_view: PostReportView; } -export class ResolvePostReport { +export interface ResolvePostReport { report_id: number; /** * Either resolve or unresolve a report. */ resolved: boolean; auth: string; - - constructor(init: ResolvePostReport) { - Object.assign(this, init); - } } -export class ListPostReports { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; +export interface ListPostReports { + page?: number; + limit?: number; /** * if no community is given, it returns reports for all communities moderated by the auth user. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; + community_id?: number; /** * Only shows the unresolved reports. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unresolved_only: Option; + unresolved_only?: boolean; auth: string; - - constructor(init: ListPostReports) { - Object.assign(this, init); - } } -export class ListPostReportsResponse { - @Type(() => PostReportView) +export interface ListPostReportsResponse { post_reports: PostReportView[]; } -export class GetSiteMetadata { +export interface GetSiteMetadata { url: string; - - constructor(init: GetSiteMetadata) { - Object.assign(this, init); - } } -export class GetSiteMetadataResponse { - @Type(() => SiteMetadata) +export interface GetSiteMetadataResponse { metadata: SiteMetadata; } diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index fc5c2ca..d8fd8bb 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -1,7 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../../utils"; import { ListingType, ModlogActionType, SearchType, SortType } from "../others"; import { Language, RegistrationMode, Tagline } from "../source"; import { @@ -35,695 +31,262 @@ import { /** * Search lemmy for different types of data. */ -export class Search { +export interface Search { /** * The search query string. */ q: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - type_: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - creator_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sort: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - listing_type: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: Search) { - Object.assign(this, init); - } + type_?: SearchType; + community_id?: number; + community_name?: string; + creator_id?: number; + sort?: SortType; + listing_type?: ListingType; + page?: number; + limit?: number; + auth?: string; } -export class SearchResponse { +export interface SearchResponse { /** * The [[SearchType]]. */ type_: string; - @Type(() => CommentView) comments: CommentView[]; - @Type(() => PostView) posts: PostView[]; - @Type(() => CommunityView) communities: CommunityView[]; - @Type(() => PersonViewSafe) users: PersonViewSafe[]; } -export class GetModlog { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - mod_person_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; +export interface GetModlog { + mod_person_id?: number; + community_id?: number; + page?: number; + limit?: number; + auth?: string; type_: ModlogActionType; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - other_person_id: Option; - constructor(init: GetModlog) { - Object.assign(this, init); - } + other_person_id?: number; } -export class GetModlogResponse { - @Type(() => ModRemovePostView) +export interface GetModlogResponse { removed_posts: ModRemovePostView[]; - @Type(() => ModLockPostView) locked_posts: ModLockPostView[]; - @Type(() => ModFeaturePostView) featured_posts: ModFeaturePostView[]; - @Type(() => ModRemoveCommentView) removed_comments: ModRemoveCommentView[]; - @Type(() => ModRemoveCommunityView) removed_communities: ModRemoveCommunityView[]; - @Type(() => ModBanFromCommunityView) banned_from_community: ModBanFromCommunityView[]; - @Type(() => ModBanView) banned: ModBanView[]; - @Type(() => ModAddCommunityView) added_to_community: ModAddCommunityView[]; - @Type(() => ModTransferCommunityView) transferred_to_community: ModTransferCommunityView[]; - @Type(() => ModAddView) added: ModAddView[]; - @Type(() => AdminPurgePersonView) admin_purged_persons: AdminPurgePersonView[]; - @Type(() => AdminPurgeCommunityView) admin_purged_communities: AdminPurgeCommunityView[]; - @Type(() => AdminPurgePostView) admin_purged_posts: AdminPurgePostView[]; - @Type(() => AdminPurgeCommentView) admin_purged_comments: AdminPurgeCommentView[]; } -export class CreateSite { +export interface CreateSite { name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sidebar: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - enable_downvotes: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - enable_nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_creation_admin_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - require_email_verification: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - registration_mode: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - application_question: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - private_instance: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_theme: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_post_listing_type: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - application_email_admins: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - hide_modlog_mod_names: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - discussion_languages: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - legal_information: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - slur_filter_regex: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - actor_name_max_length: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_message: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_message_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_post: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_post_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_register: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_register_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_image: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_image_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_comment: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_comment_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_search: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_search_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_enabled: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_debug: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_worker_count: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_enabled: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_difficulty: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - allowed_instances: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - blocked_instances: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - taglines: Option; + sidebar?: string; + description?: string; + icon?: string; + banner?: string; + enable_downvotes?: boolean; + enable_nsfw?: boolean; + community_creation_admin_only?: boolean; + require_email_verification?: boolean; + registration_mode?: RegistrationMode; + application_question?: string; + private_instance?: boolean; + default_theme?: string; + default_post_listing_type?: string; + application_email_admins?: boolean; + hide_modlog_mod_names?: boolean; + discussion_languages?: number[]; + legal_information?: string; + slur_filter_regex?: string; + actor_name_max_length?: number; + rate_limit_message?: number; + rate_limit_message_per_second?: number; + rate_limit_post?: number; + rate_limit_post_per_second?: number; + rate_limit_register?: number; + rate_limit_register_per_second?: number; + rate_limit_image?: number; + rate_limit_image_per_second?: number; + rate_limit_comment?: number; + rate_limit_comment_per_second?: number; + rate_limit_search?: number; + rate_limit_search_per_second?: number; + federation_enabled?: boolean; + federation_debug?: boolean; + federation_worker_count?: number; + captcha_enabled?: boolean; + captcha_difficulty?: string; + allowed_instances?: string[]; + blocked_instances?: string[]; + taglines?: string[]; auth: string; - constructor(init: CreateSite) { - Object.assign(this, init); - } } -export class EditSite { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sidebar: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - enable_downvotes: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - enable_nsfw: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - community_creation_admin_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - require_email_verification: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - registration_mode: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - application_question: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - private_instance: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_theme: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - default_post_listing_type: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - legal_information: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - application_email_admins: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - hide_modlog_mod_names: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - discussion_languages: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - slur_filter_regex: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - actor_name_max_length: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_message: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_message_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_post: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_post_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_register: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_register_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_image: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_image_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_comment: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_comment_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_search: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - rate_limit_search_per_second: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_enabled: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_debug: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - federation_worker_count: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_enabled: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - captcha_difficulty: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - allowed_instances: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - blocked_instances: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - taglines: Option; +export interface EditSite { + name?: string; + sidebar?: string; + description?: string; + icon?: string; + banner?: string; + enable_downvotes?: boolean; + enable_nsfw?: boolean; + community_creation_admin_only?: boolean; + require_email_verification?: boolean; + registration_mode?: RegistrationMode; + application_question?: string; + private_instance?: boolean; + default_theme?: string; + default_post_listing_type?: string; + legal_information?: string; + application_email_admins?: boolean; + hide_modlog_mod_names?: boolean; + discussion_languages?: number[]; + slur_filter_regex?: string; + actor_name_max_length?: number; + rate_limit_message?: number; + rate_limit_message_per_second?: number; + rate_limit_post?: number; + rate_limit_post_per_second?: number; + rate_limit_register?: number; + rate_limit_register_per_second?: number; + rate_limit_image?: number; + rate_limit_image_per_second?: number; + rate_limit_comment?: number; + rate_limit_comment_per_second?: number; + rate_limit_search?: number; + rate_limit_search_per_second?: number; + federation_enabled?: boolean; + federation_debug?: boolean; + federation_worker_count?: number; + captcha_enabled?: boolean; + captcha_difficulty?: string; + allowed_instances?: string[]; + blocked_instances?: string[]; + taglines?: string[]; auth: string; - - constructor(init: EditSite) { - Object.assign(this, init); - } } -export class GetSite { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: GetSite) { - Object.assign(this, init); - } +export interface GetSite { + auth?: string; } -export class SiteResponse { - @Type(() => SiteView) +export interface SiteResponse { site_view: SiteView; } -export class GetSiteResponse { - @Type(() => SiteView) +export interface GetSiteResponse { site_view: SiteView; - @Type(() => PersonViewSafe) admins: PersonViewSafe[]; online: number; version: string; /** * If you're logged in, you'll get back extra user info. */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => MyUserInfo) - my_user: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => FederatedInstances) - federated_instances: Option; - @Type(() => Language) + my_user?: MyUserInfo; + federated_instances?: FederatedInstances; all_languages: Language[]; discussion_languages: number[]; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => Tagline) - taglines: Option; + taglines?: Tagline[]; } /** * Your user info, such as blocks, follows, etc. */ -export class MyUserInfo { - @Type(() => LocalUserSettingsView) +export interface MyUserInfo { local_user_view: LocalUserSettingsView; - @Type(() => CommunityFollowerView) follows: CommunityFollowerView[]; - @Type(() => CommunityModeratorView) moderates: CommunityModeratorView[]; - @Type(() => CommunityBlockView) community_blocks: CommunityBlockView[]; - @Type(() => PersonBlockView) person_blocks: PersonBlockView[]; discussion_languages: number[]; } -export class LeaveAdmin { +export interface LeaveAdmin { auth: string; - - constructor(init: LeaveAdmin) { - Object.assign(this, init); - } } -export class FederatedInstances { +export interface FederatedInstances { linked: string[]; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - allowed: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - blocked: Option; - - constructor(init: FederatedInstances) { - Object.assign(this, init); - } + allowed?: string[]; + blocked?: string[]; } -export class ResolveObject { +export interface ResolveObject { q: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - auth: Option; - - constructor(init: ResolveObject) { - Object.assign(this, init); - } + auth?: string; } -export class ResolveObjectResponse { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => CommentView) - comment: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PostView) - post: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => CommunityView) - community: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonViewSafe) - person: Option; +export interface ResolveObjectResponse { + comment?: CommentView; + post?: PostView; + community?: CommunityView; + person?: PersonViewSafe; } -export class PurgePerson { +export interface PurgePerson { person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: PurgePerson) { - Object.assign(this, init); - } } -export class PurgeCommunity { +export interface PurgeCommunity { community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: PurgeCommunity) { - Object.assign(this, init); - } } -export class PurgePost { +export interface PurgePost { post_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: PurgePost) { - Object.assign(this, init); - } } -export class PurgeComment { +export interface PurgeComment { comment_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; auth: string; - - constructor(init: PurgeComment) { - Object.assign(this, init); - } } -export class PurgeItemResponse { +export interface PurgeItemResponse { success: boolean; } -export class ListRegistrationApplications { +export interface ListRegistrationApplications { /** * Only shows the unread applications (IE those without an admin actor) */ - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - unread_only: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - page: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - limit: Option; + unread_only?: boolean; + page?: number; + limit?: number; auth: string; - - constructor(init: ListRegistrationApplications) { - Object.assign(this, init); - } } -export class ListRegistrationApplicationsResponse { - @Type(() => RegistrationApplicationView) +export interface ListRegistrationApplicationsResponse { registration_applications: RegistrationApplicationView[]; } -export class ApproveRegistrationApplication { +export interface ApproveRegistrationApplication { id: number; approve: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - deny_reason: Option; + deny_reason?: string; auth: string; - - constructor(init: ApproveRegistrationApplication) { - Object.assign(this, init); - } } -export class RegistrationApplicationResponse { - @Type(() => RegistrationApplicationView) +export interface RegistrationApplicationResponse { registration_application: RegistrationApplicationView; } -export class GetUnreadRegistrationApplicationCount { +export interface GetUnreadRegistrationApplicationCount { auth: string; - - constructor(init: GetUnreadRegistrationApplicationCount) { - Object.assign(this, init); - } } -export class GetUnreadRegistrationApplicationCountResponse { +export interface GetUnreadRegistrationApplicationCountResponse { registration_applications: number; } diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index 933d2ef..ea79e06 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -1,6 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; -import { toOption, toUndefined } from "../utils"; export const VERSION = "v3"; /** @@ -227,25 +224,9 @@ export enum PostFeatureType { /** * A holder for a site's metadata ( such as opengraph tags ), used for post links. */ -export class SiteMetadata { - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - title: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - image: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - html: Option; - - constructor(init: SiteMetadata) { - Object.assign(this, init); - } +export interface SiteMetadata { + title?: string; + description?: string; + image?: string; + html?: string; } diff --git a/src/interfaces/source.ts b/src/interfaces/source.ts index 38d29be..9c0949c 100644 --- a/src/interfaces/source.ts +++ b/src/interfaces/source.ts @@ -1,14 +1,7 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; -import { toOption, toUndefined } from "../utils"; - -export class LocalUserSettings { +export interface LocalUserSettings { id: number; person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - email: Option; + email?: string; show_nsfw: boolean; theme: string; default_sort_type: number; @@ -25,80 +18,41 @@ export class LocalUserSettings { accepted_application: boolean; } -export class PersonSafe { +export interface PersonSafe { id: number; name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - display_name: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - avatar: Option; + display_name?: string; + avatar?: string; banned: boolean; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; actor_id: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - bio: Option; + bio?: string; local: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; + banner?: string; deleted: boolean; inbox_url: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - shared_inbox_url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - matrix_user_id: Option; + shared_inbox_url?: string; + matrix_user_id?: string; admin: boolean; bot_account: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - ban_expires: Option; + ban_expires?: string; instance_id: number; } -export class Site { +export interface Site { id: number; name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - sidebar: Option; + sidebar?: string; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; + updated?: string; + icon?: string; + banner?: string; + description?: string; actor_id: string; last_refreshed_at: string; inbox_url: string; - private_key: Option; + private_key?: string; public_key: string; instance_id: number; } @@ -109,7 +63,7 @@ export enum RegistrationMode { Open = "open", } -export class LocalSite { +export interface LocalSite { id: number; site_id: number; site_setup: boolean; @@ -118,23 +72,14 @@ export class LocalSite { enable_nsfw: boolean; community_creation_admin_only: boolean; require_email_verification: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - application_question: Option; + application_question?: string; private_instance: boolean; default_theme: string; default_post_listing_type: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - legal_information: Option; + legal_information?: string; hide_modlog_mod_names: boolean; application_email_admins: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - slur_filter_regex: Option; + slur_filter_regex?: string; actor_name_max_length: number; federation_enabled: boolean; federation_debug: boolean; @@ -142,13 +87,10 @@ export class LocalSite { captcha_enabled: boolean; captcha_difficulty: string; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } -export class LocalSiteRateLimit { +export interface LocalSiteRateLimit { id: number; local_site_id: number; message: number; @@ -164,13 +106,10 @@ export class LocalSiteRateLimit { search: number; search_per_second: number; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } -export class PrivateMessage { +export interface PrivateMessage { id: number; creator_id: number; recipient_id: number; @@ -178,78 +117,42 @@ export class PrivateMessage { deleted: boolean; read: boolean; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; ap_id: string; local: boolean; } -export class PostReport { +export interface PostReport { id: number; creator_id: number; post_id: number; original_post_name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - original_post_url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - original_post_body: Option; + original_post_url?: string; + original_post_body?: string; reason: string; resolved: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - resolver_id: Option; + resolver_id?: number; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } -export class Post { +export interface Post { id: number; name: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - body: Option; + url?: string; + body?: string; creator_id: number; community_id: number; removed: boolean; locked: boolean; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; deleted: boolean; nsfw: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - embed_title: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - embed_description: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - embed_video_url: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - thumbnail_url: Option; + embed_title?: string; + embed_description?: string; + embed_video_url?: string; + thumbnail_url?: string; ap_id: string; local: boolean; language_id: number; @@ -257,40 +160,31 @@ export class Post { featured_local: boolean; } -export class PasswordResetRequest { +export interface PasswordResetRequest { id: number; local_user_id: number; token_encrypted: string; published: string; } -export class ModRemovePost { +export interface ModRemovePost { id: number; mod_person_id: number; post_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; + reason?: string; + removed?: boolean; when_: string; } -export class ModLockPost { +export interface ModLockPost { id: number; mod_person_id: number; post_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - locked: Option; + locked?: boolean; when_: string; } -export class ModFeaturePost { +export interface ModFeaturePost { id: number; mod_person_id: number; post_id: number; @@ -299,216 +193,141 @@ export class ModFeaturePost { when_: string; } -export class ModRemoveComment { +export interface ModRemoveComment { id: number; mod_person_id: number; comment_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; + reason?: string; + removed?: boolean; when_: string; } -export class ModRemoveCommunity { +export interface ModRemoveCommunity { id: number; mod_person_id: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + reason?: string; + removed?: boolean; + expires?: string; when_: string; } -export class ModBanFromCommunity { +export interface ModBanFromCommunity { id: number; mod_person_id: number; other_person_id: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banned: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + reason?: string; + banned?: boolean; + expires?: string; when_: string; } -export class ModBan { +export interface ModBan { id: number; mod_person_id: number; other_person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banned: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - expires: Option; + reason?: string; + banned?: boolean; + expires?: string; when_: string; } -export class ModAddCommunity { +export interface ModAddCommunity { id: number; mod_person_id: number; other_person_id: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; + removed?: boolean; when_: string; } -export class ModTransferCommunity { +export interface ModTransferCommunity { id: number; mod_person_id: number; other_person_id: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; + removed?: boolean; when_: string; } -export class ModAdd { +export interface ModAdd { id: number; mod_person_id: number; other_person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - removed: Option; + removed?: boolean; when_: string; } -export class AdminPurgePerson { +export interface AdminPurgePerson { id: number; admin_person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; when_: string; } -export class AdminPurgeCommunity { +export interface AdminPurgeCommunity { id: number; admin_person_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; when_: string; } -export class AdminPurgePost { +export interface AdminPurgePost { id: number; admin_person_id: number; community_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; when_: string; } -export class AdminPurgeComment { +export interface AdminPurgeComment { id: number; admin_person_id: number; post_id: number; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - reason: Option; + reason?: string; when_: string; } -export class CommunitySafe { +export interface CommunitySafe { id: number; name: string; title: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - description: Option; + description?: string; removed: boolean; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; deleted: boolean; nsfw: boolean; actor_id: string; local: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - icon: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - banner: Option; + icon?: string; + banner?: string; hidden: boolean; posting_restricted_to_mods: boolean; instance_id: number; } -export class CommentReport { +export interface CommentReport { id: number; creator_id: number; comment_id: number; original_comment_text: string; reason: string; resolved: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - resolver_id: Option; + resolver_id?: number; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } -export class Comment { +export interface Comment { id: number; creator_id: number; post_id: number; content: string; removed: boolean; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; deleted: boolean; ap_id: string; local: boolean; @@ -517,7 +336,7 @@ export class Comment { language_id: number; } -export class PersonMention { +export interface PersonMention { id: number; recipient_id: number; comment_id: number; @@ -525,7 +344,7 @@ export class PersonMention { published: string; } -export class CommentReply { +export interface CommentReply { id: number; recipient_id: number; comment_id: number; @@ -533,52 +352,37 @@ export class CommentReply { published: string; } -export class RegistrationApplication { +export interface RegistrationApplication { id: number; local_user_id: number; answer: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - admin_id: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - deny_reason: Option; + admin_id?: number; + deny_reason?: string; published: string; } -export class Language { +export interface Language { id: number; code: string; name: string; } -export class PrivateMessageReport { +export interface PrivateMessageReport { id: number; creator_id: number; private_message_id: number; original_pm_text: string; reason: string; resolved: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - resolver_id: Option; + resolver_id?: number; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } -export class Tagline { +export interface Tagline { id: number; local_site_id: number; content: string; published: string; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - updated: Option; + updated?: string; } diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 79c3cd9..40a95c9 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -1,7 +1,3 @@ -import { Option } from "@sniptt/monads"; -import { Expose, Transform, Type } from "class-transformer"; -import "reflect-metadata"; -import { toOption, toUndefined } from "../utils"; import { CommentAggregates, CommunityAggregates, @@ -43,73 +39,49 @@ import { Tagline, } from "./source"; -export class PersonViewSafe { - @Type(() => PersonSafe) +export interface PersonViewSafe { person: PersonSafe; counts: PersonAggregates; } -export class PersonMentionView { - @Type(() => PersonMention) +export interface PersonMentionView { person_mention: PersonMention; - @Type(() => Comment) comment: Comment; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; - @Type(() => PersonSafe) recipient: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; subscribed: SubscribedType; saved: boolean; creator_blocked: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; + my_vote?: number; } -export class LocalUserSettingsView { - @Type(() => LocalUserSettings) +export interface LocalUserSettingsView { local_user: LocalUserSettings; - @Type(() => PersonSafe) person: PersonSafe; counts: PersonAggregates; } -export class SiteView { - @Type(() => Site) +export interface SiteView { site: Site; - @Type(() => LocalSite) local_site: LocalSite; - @Type(() => LocalSiteRateLimit) local_site_rate_limit: LocalSiteRateLimit; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - taglines: Option; + taglines?: Tagline[]; counts: SiteAggregates; } -export class PrivateMessageView { - @Type(() => PrivateMessage) +export interface PrivateMessageView { private_message: PrivateMessage; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => PersonSafe) recipient: PersonSafe; } -export class PostView { - @Type(() => Post) +export interface PostView { post: Post; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => CommunitySafe) community: CommunitySafe; creator_banned_from_community: boolean; counts: PostAggregates; @@ -117,344 +89,191 @@ export class PostView { saved: boolean; read: boolean; creator_blocked: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; + my_vote?: number; unread_comments: number; } -export class PostReportView { - @Type(() => PostReport) +export interface PostReportView { post_report: PostReport; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => PersonSafe) post_creator: PersonSafe; creator_banned_from_community: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; + my_vote?: number; counts: PostAggregates; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - resolver: Option; + resolver?: PersonSafe; } -export class CommentView { - @Type(() => Comment) +export interface CommentView { comment: Comment; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; counts: CommentAggregates; creator_banned_from_community: boolean; subscribed: SubscribedType; saved: boolean; creator_blocked: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; + my_vote?: number; } -export class CommentReplyView { - @Type(() => CommentReply) +export interface CommentReplyView { comment_reply: CommentReply; - @Type(() => Comment) comment: Comment; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; - @Type(() => PersonSafe) recipient: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; subscribed: SubscribedType; saved: boolean; creator_blocked: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; + my_vote?: number; } -export class CommentReportView { - @Type(() => CommentReport) +export interface CommentReportView { comment_report: CommentReport; - @Type(() => Comment) comment: Comment; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; - @Type(() => PersonSafe) creator: PersonSafe; - @Type(() => PersonSafe) comment_creator: PersonSafe; counts: CommentAggregates; creator_banned_from_community: boolean; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - my_vote: Option; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - resolver: Option; + my_vote?: number; + resolver?: PersonSafe; } -export class ModAddCommunityView { - @Type(() => ModAddCommunity) +export interface ModAddCommunityView { mod_add_community: ModAddCommunity; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => CommunitySafe) + moderator?: PersonSafe; community: CommunitySafe; - @Type(() => PersonSafe) modded_person: PersonSafe; } -export class ModTransferCommunityView { - @Type(() => ModTransferCommunity) +export interface ModTransferCommunityView { mod_transfer_community: ModTransferCommunity; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => CommunitySafe) + moderator?: PersonSafe; community: CommunitySafe; - @Type(() => PersonSafe) modded_person: PersonSafe; } -export class ModAddView { - @Type(() => ModAdd) +export interface ModAddView { mod_add: ModAdd; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => PersonSafe) + moderator?: PersonSafe; modded_person: PersonSafe; } -export class ModBanFromCommunityView { - @Type(() => ModBanFromCommunity) +export interface ModBanFromCommunityView { mod_ban_from_community: ModBanFromCommunity; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => CommunitySafe) + moderator?: PersonSafe; community: CommunitySafe; - @Type(() => PersonSafe) banned_person: PersonSafe; } -export class ModBanView { - @Type(() => ModBan) +export interface ModBanView { mod_ban: ModBan; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => PersonSafe) + moderator?: PersonSafe; banned_person: PersonSafe; } -export class ModLockPostView { - @Type(() => ModLockPost) +export interface ModLockPostView { mod_lock_post: ModLockPost; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => Post) + moderator?: PersonSafe; post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; } -export class ModRemoveCommentView { - @Type(() => ModRemoveComment) +export interface ModRemoveCommentView { mod_remove_comment: ModRemoveComment; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => Comment) + moderator?: PersonSafe; comment: Comment; - @Type(() => PersonSafe) commenter: PersonSafe; - @Type(() => Post) post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; } -export class ModRemoveCommunityView { - @Type(() => ModRemoveCommunity) +export interface ModRemoveCommunityView { mod_remove_community: ModRemoveCommunity; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => CommunitySafe) + moderator?: PersonSafe; community: CommunitySafe; } -export class ModRemovePostView { - @Type(() => ModRemovePost) +export interface ModRemovePostView { mod_remove_post: ModRemovePost; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => Post) + moderator?: PersonSafe; post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; } -export class ModFeaturePostView { - @Type(() => ModFeaturePost) +export interface ModFeaturePostView { mod_feature_post: ModFeaturePost; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - moderator: Option; - @Type(() => Post) + moderator?: PersonSafe; post: Post; - @Type(() => CommunitySafe) community: CommunitySafe; } -export class AdminPurgeCommunityView { - @Type(() => AdminPurgeCommunity) +export interface AdminPurgeCommunityView { admin_purge_community: AdminPurgeCommunity; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - admin: Option; + admin?: PersonSafe; } -export class AdminPurgePersonView { - @Type(() => AdminPurgePerson) +export interface AdminPurgePersonView { admin_purge_person: AdminPurgePerson; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - admin: Option; + admin?: PersonSafe; } -export class AdminPurgePostView { - @Type(() => AdminPurgePost) +export interface AdminPurgePostView { admin_purge_post: AdminPurgePost; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - admin: Option; - @Type(() => CommunitySafe) + admin?: PersonSafe; community: CommunitySafe; } -export class AdminPurgeCommentView { - @Type(() => AdminPurgeComment) +export interface AdminPurgeCommentView { admin_purge_comment: AdminPurgeComment; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - admin: Option; - @Type(() => Post) + admin?: PersonSafe; post: Post; } -export class CommunityFollowerView { - @Type(() => CommunitySafe) +export interface CommunityFollowerView { community: CommunitySafe; - @Type(() => PersonSafe) follower: PersonSafe; } -export class CommunityBlockView { - @Type(() => PersonSafe) +export interface CommunityBlockView { person: PersonSafe; - @Type(() => CommunitySafe) community: CommunitySafe; } -export class CommunityModeratorView { - @Type(() => CommunitySafe) +export interface CommunityModeratorView { community: CommunitySafe; - @Type(() => PersonSafe) moderator: PersonSafe; } -export class CommunityPersonBanView { - @Type(() => CommunitySafe) +export interface CommunityPersonBanView { community: CommunitySafe; - @Type(() => PersonSafe) person: PersonSafe; } -export class PersonBlockView { - @Type(() => PersonSafe) +export interface PersonBlockView { person: PersonSafe; - @Type(() => PersonSafe) target: PersonSafe; } -export class CommunityView { - @Type(() => CommunitySafe) +export interface CommunityView { community: CommunitySafe; subscribed: SubscribedType; blocked: boolean; counts: CommunityAggregates; } -export class RegistrationApplicationView { - @Type(() => RegistrationApplication) +export interface RegistrationApplicationView { registration_application: RegistrationApplication; - @Type(() => LocalUserSettings) creator_local_user: LocalUserSettings; - @Type(() => PersonSafe) creator: PersonSafe; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - admin: Option; + admin?: PersonSafe; } export interface CommentNode { @@ -463,18 +282,10 @@ export interface CommentNode { depth: number; } -export class PrivateMessageReportView { - @Type(() => PrivateMessageReport) +export interface PrivateMessageReportView { private_message_report: PrivateMessageReport; - @Type(() => PrivateMessage) private_message: PrivateMessage; - @Type(() => PersonSafe) private_message_creator: PersonSafe; - @Type(() => PersonSafe) creator: PersonSafe; - @Transform(({ value }) => toOption(value), { toClassOnly: true }) - @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) - @Expose() - @Type(() => PersonSafe) - resolver: Option; + resolver?: PersonSafe; } diff --git a/src/utils.ts b/src/utils.ts index 2fb61f1..e69de29 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,15 +0,0 @@ -import { Option, Some } from "@sniptt/monads"; - -/** - * Converts an option to an undefined. Necessary for API requests. - */ -export function toUndefined(opt: Option) { - return opt.isSome() ? opt.unwrap() : undefined; -} - -/** - * Converts a null value to an option. - */ -export function toOption(val: T): Option { - return Some(val || undefined); -} diff --git a/src/websocket.ts b/src/websocket.ts index e70adb6..2afce29 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -1,4 +1,3 @@ -import { ClassConstructor, deserialize, serialize } from "class-transformer"; import { CreateComment, CreateCommentLike, @@ -686,7 +685,7 @@ export class LemmyWebsocket { } function wrapper(op: UserOperation, data: MessageType) { - let send = serialize({ op: UserOperation[op], data }); + let send = JSON.stringify({ op: UserOperation[op], data }); return send; } @@ -698,10 +697,8 @@ export function wsUserOp(msg: any): UserOperation { /** * Converts a websocket string response to a usable result */ -export function wsJsonToRes( - msg: any, - responseClass: ClassConstructor -): ResponseType { +// TODO is this still necessary? +export function wsJsonToRes(msg: any): ResponseType { // Have to deserialize the response again into the correct class - return deserialize(responseClass, serialize(msg.data)); + return msg.data as ResponseType; } diff --git a/tsconfig.json b/tsconfig.json index 77d0598..67a72e7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,7 @@ "outDir": "./dist", "target": "ES5", "experimentalDecorators": true, + "strictNullChecks": true, "moduleResolution": "Node" }, "include": [ diff --git a/yarn.lock b/yarn.lock index a6ab72f..6ae092d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -285,11 +285,6 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" -"@sniptt/monads@^0.5.10": - version "0.5.10" - resolved "https://registry.yarnpkg.com/@sniptt/monads/-/monads-0.5.10.tgz#a80cd00738bbd682d36d36dd36bdc0bddc96eb76" - integrity sha512-+agDOv9DpDV+9e2zN/Vmdk+XaqGx5Sykl0fqhqgiJ90r18nsBkxe44DmZ2sA1HYK+MSsBeZBiAr6pq4w+5uhfw== - "@types/glob@^7.1.1": version "7.2.0" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb" @@ -581,11 +576,6 @@ chalk@^4.0.0: ansi-styles "^4.1.0" supports-color "^7.1.0" -class-transformer@^0.5.1: - version "0.5.1" - resolved "https://registry.yarnpkg.com/class-transformer/-/class-transformer-0.5.1.tgz#24147d5dffd2a6cea930a3250a677addf96ab336" - integrity sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw== - clean-stack@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" @@ -1720,11 +1710,6 @@ queue-microtask@^1.2.2: resolved "https://registry.yarnpkg.com/queue-microtask/-/queue-microtask-1.2.3.tgz#4929228bbc724dfac43e0efb058caf7b6cfb6243" integrity sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A== -reflect-metadata@^0.1.13: - version "0.1.13" - resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08" - integrity sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg== - regexpp@^3.2.0: version "3.2.0" resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-3.2.0.tgz#0425a2768d8f23bad70ca4b90461fa2f1213e1b2"