From 3f0e4ef05d44696b5d22a99016f1317f982acc95 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 14 Jun 2022 00:42:10 -0400 Subject: [PATCH] Add more type info. --- src/interfaces/api/community.ts | 3 ++- src/interfaces/api/person.ts | 3 ++- src/interfaces/api/site.ts | 11 +++++++++-- src/interfaces/views.ts | 6 +++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/interfaces/api/community.ts b/src/interfaces/api/community.ts index ccf0086..606b979 100644 --- a/src/interfaces/api/community.ts +++ b/src/interfaces/api/community.ts @@ -1,5 +1,5 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; import { toUndefined } from "../../utils"; import { ListingType, SortType } from "../others"; import { Site } from "../source"; @@ -38,6 +38,7 @@ export class GetCommunityResponse { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => Site) site: Option; moderators: CommunityModeratorView[]; online: number; diff --git a/src/interfaces/api/person.ts b/src/interfaces/api/person.ts index 83a63f8..531cbc5 100644 --- a/src/interfaces/api/person.ts +++ b/src/interfaces/api/person.ts @@ -1,5 +1,5 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; import { toUndefined } from "../../utils"; import { SortType } from "../others"; import { @@ -71,6 +71,7 @@ export class GetCaptchaResponse { /** * Will be undefined if captchas are disabled. */ + @Type(() => CaptchaResponse) @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index aaef3fc..68714df 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -1,5 +1,5 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; import { toUndefined } from "../../utils"; import { ListingType, SearchType, SortType } from "../others"; import { @@ -286,6 +286,7 @@ export class GetSiteResponse { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => SiteView) site_view: Option; admins: PersonViewSafe[]; online: number; @@ -296,17 +297,19 @@ export class GetSiteResponse { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => MyUserInfo) my_user: Option; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => FederatedInstances) federated_instances: Option; } /** * Your user info, such as blocks, follows, etc. */ -export interface MyUserInfo { +export class MyUserInfo { local_user_view: LocalUserSettingsView; follows: CommunityFollowerView[]; moderates: CommunityModeratorView[]; @@ -375,18 +378,22 @@ export class ResolveObjectResponse { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => CommentView) comment: Option; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PostView) post: Option; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => CommunityView) community: Option; @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PersonViewSafe) person: Option; } diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 366f560..5d64270 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -1,5 +1,5 @@ import { Option, Some } from "@sniptt/monads"; -import { Expose, Transform } from "class-transformer"; +import { Expose, Transform, Type } from "class-transformer"; import { toUndefined } from "../utils"; import { CommentAggregates, @@ -103,6 +103,7 @@ export class PostReportView { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PersonSafe) resolver: Option; } @@ -112,6 +113,7 @@ export class CommentView { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PersonSafe) recipient: Option; post: Post; community: CommunitySafe; @@ -142,6 +144,7 @@ export class CommentReportView { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PersonSafe) resolver: Option; } @@ -253,5 +256,6 @@ export class RegistrationApplicationView { @Transform(({ value }) => Some(value), { toClassOnly: true }) @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) @Expose() + @Type(() => PersonSafe) admin: Option; }