Use import type in entities where possible

This commit is contained in:
Rory&
2026-03-20 11:00:41 +01:00
parent 99c92775a9
commit 5c018daba4
38 changed files with 118 additions and 113 deletions
+3 -3
View File
@@ -18,9 +18,9 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Team } from "./Team";
import { User } from "./User";
import { Guild } from "./Guild";
import type { Guild } from "./Guild";
import type { Team } from "./Team";
import type { User } from "./User";
@Entity({
name: "applications",
+1 -1
View File
@@ -17,7 +17,6 @@
*/
import { Column, Entity } from "typeorm";
import { BaseClass } from "./BaseClass";
import {
ApplicationCommandHandlerType,
ApplicationCommandOption,
@@ -27,6 +26,7 @@ import {
ApplicationIntegrationType,
InteractionContextType,
} from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
@Entity({
name: "application_commands",
+4 -3
View File
@@ -18,8 +18,9 @@
import { BeforeRemove, Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { deleteFile } from "../util";
import { BaseClass } from "./BaseClass";
import { getUrlSignature, NewUrlUserSignatureData, NewUrlSignatureData } from "../Signing";
import { BaseClass } from "./BaseClass";
import type { Message } from "./Message";
@Entity({
name: "attachments",
@@ -51,10 +52,10 @@ export class Attachment extends BaseClass {
message_id: string;
@JoinColumn({ name: "message_id" })
@ManyToOne(() => require("./Message").Message, (message: import("./Message").Message) => message.attachments, {
@ManyToOne(() => require("./Message").Message, (message: Message) => message.attachments, {
onDelete: "CASCADE",
})
message: import("./Message").Message;
message: Message;
@BeforeRemove()
onDelete() {
+2 -2
View File
@@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { AuditLogChange, AuditLogEvents } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "audit_logs",
+2 -2
View File
@@ -16,10 +16,10 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { BaseClass } from "./BaseClass";
import { Entity, JoinColumn, ManyToOne, Column } from "typeorm";
import { User } from "./User";
import { AutomodAction, AutomodRuleEventType, AutomodRuleTriggerMetadata, AutomodRuleTriggerType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "automod_rules",
+2 -2
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import crypto from "crypto";
import { Config } from "../util";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "backup_codes",
+2 -2
View File
@@ -18,8 +18,8 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
import type { Guild } from "./Guild";
import type { User } from "./User";
@Entity({
name: "bans",
+11 -11
View File
@@ -21,19 +21,19 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "ty
import { DmChannelDTO } from "../dtos";
import { ChannelCreateEvent, ChannelRecipientRemoveEvent, ThreadCreateEvent, ThreadMembersUpdateEvent } from "../interfaces";
import { InvisibleCharacters, Snowflake, emitEvent, getPermission, trimSpecial, Permissions, Config, DiscordApiErrors } from "../util";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { Invite } from "./Invite";
import { Message } from "./Message";
import { Tag } from "./Tag";
import { ReadState } from "./ReadState";
import { Recipient } from "./Recipient";
import { User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
import { Member } from "./Member";
import { ChannelPermissionOverwrite, ChannelType, PublicUserProjection, ThreadMetadata } from "@spacebar/schemas";
import { OrmUtils } from "../imports";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import type { Invite } from "./Invite";
import type { Message } from "./Message";
import type { Tag } from "./Tag";
import type { ReadState } from "./ReadState";
import { Recipient } from "./Recipient";
import { User } from "./User";
import type { VoiceState } from "./VoiceState";
import type { Webhook } from "./Webhook";
import { Member } from "./Member";
import { ThreadMember } from "./ThreadMember";
@Entity({
+2 -2
View File
@@ -18,8 +18,8 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { Channel } from "./Channel";
import type { User } from "./User";
import type { Channel } from "./Channel";
@Entity({
name: "cloud_attachments",
+2 -2
View File
@@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { ConnectedAccountTokenData } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "connected_accounts",
+1 -1
View File
@@ -16,9 +16,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { BaseClass } from "./BaseClass";
import { Entity, Column } from "typeorm";
import { Embed } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
@Entity({
name: "embed_cache",
+2 -2
View File
@@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import type { User } from "./User";
import type { Guild } from "./Guild";
@Entity({
name: "emojis",
+9 -9
View File
@@ -18,19 +18,19 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { Config, GuildWelcomeScreen, Snowflake, handleFile } from "..";
import { Ban } from "./Ban";
import { arrayRemove } from "@spacebar/util";
import { BaseClass } from "./BaseClass";
import type { Ban } from "./Ban";
import { Channel } from "./Channel";
import { Emoji } from "./Emoji";
import { Invite } from "./Invite";
import type { Emoji } from "./Emoji";
import type { Invite } from "./Invite";
import { Member } from "./Member";
import { Role } from "./Role";
import { Sticker } from "./Sticker";
import { Template } from "./Template";
import { User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
import { arrayRemove } from "@spacebar/util";
import type { Sticker } from "./Sticker";
import type { Template } from "./Template";
import type { User } from "./User";
import type { VoiceState } from "./VoiceState";
import type { Webhook } from "./Webhook";
// TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0}
// TODO: guild_scheduled_events
// TODO: stage_instances
+3 -3
View File
@@ -18,10 +18,10 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import type { Channel } from "./Channel";
import type { Guild } from "./Guild";
import { Member } from "./Member";
import { User } from "./User";
import type { User } from "./User";
export const PublicInviteRelation = ["inviter", "guild", "channel"];
+2 -2
View File
@@ -21,14 +21,14 @@ import { BeforeInsert, BeforeUpdate, Column, Entity, Index, JoinColumn, JoinTabl
import { ReadyGuildDTO } from "../dtos";
import { GuildCreateEvent, GuildDeleteEvent, GuildMemberAddEvent, GuildMemberRemoveEvent, GuildMemberUpdateEvent, MessageCreateEvent } from "../interfaces";
import { Config, emitEvent, DiscordApiErrors } from "../util";
import { Ban } from "./Ban";
import { AvatarDecorationData, Collectibles, DisplayNameStyle, PublicMember, PublicMemberProjection, UserGuildSettings } from "@spacebar/schemas";
import { BaseClassWithoutId } from "./BaseClass";
import { Ban } from "./Ban";
import { Channel } from "./Channel";
import { Guild, PublicGuildRelations } from "./Guild";
import { Message } from "./Message";
import { Role } from "./Role";
import { User } from "./User";
import { AvatarDecorationData, Collectibles, DisplayNameStyle, PublicMember, PublicMemberProjection, UserGuildSettings } from "@spacebar/schemas";
export const MemberPrivateProjection: (keyof Member)[] = [
"id",
+11 -11
View File
@@ -16,22 +16,22 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { User } from "./User";
import { Member } from "./Member";
import { Role } from "./Role";
import { Channel } from "./Channel";
import { InteractionType } from "../interfaces";
import { Application } from "./Application";
import { Column, CreateDateColumn, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, OneToMany, RelationId, FindOneOptions, Raw, Not, BaseEntity, In } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { Webhook } from "./Webhook";
import { Sticker } from "./Sticker";
import { Attachment } from "./Attachment";
import { NewUrlUserSignatureData } from "../Signing";
import { ActionRowComponent, ApplicationCommandType, Embed, MessageSnapshot, MessageType, PartialMessage, Poll, Reaction } from "@spacebar/schemas";
import { MessageFlags } from "@spacebar/util";
import { JsonRemoveEmpty } from "../util/Decorators";
import { InteractionType } from "../interfaces";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { Member } from "./Member";
import type { Role } from "./Role";
import { Channel } from "./Channel";
import type { Application } from "./Application";
import { Guild } from "./Guild";
import type { Webhook } from "./Webhook";
import type { Sticker } from "./Sticker";
import { Attachment } from "./Attachment";
@Entity({
name: "messages",
+1 -1
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne, Unique } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import type { User } from "./User";
@Entity({
name: "notes",
+3 -3
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { User } from "./User";
import { ReadStateFlags, ReadStateType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { Channel } from "./Channel";
import type { User } from "./User";
// for read receipts
// notification cursor and public read receipt need to be forwards-only (the former to prevent re-pinging when marked as unread, and the latter to be acceptable as a legal acknowledgement in criminal proceedings), and private read marker needs to be advance-rewind capable
+4 -2
View File
@@ -18,6 +18,8 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import type { Channel } from "./Channel";
import type { User } from "./User";
@Entity({
name: "recipients",
@@ -31,7 +33,7 @@ export class Recipient extends BaseClass {
@ManyToOne(() => require("./Channel").Channel, {
onDelete: "CASCADE",
})
channel: import("./Channel").Channel;
channel: Channel;
@Column()
@RelationId((recipient: Recipient) => recipient.user)
@@ -41,7 +43,7 @@ export class Recipient extends BaseClass {
@ManyToOne(() => require("./User").User, {
onDelete: "CASCADE",
})
user: import("./User").User;
user: User;
@Column({ default: false })
closed: boolean;
+2 -2
View File
@@ -17,9 +17,9 @@
*/
import { Column, Entity, Index, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { RelationshipType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "relationships",
+1 -1
View File
@@ -16,9 +16,9 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { BaseClass } from "./BaseClass";
import { Entity, Column } from "typeorm";
import { ReportMenuType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
@Entity({
name: "report_menus",
+2 -2
View File
@@ -18,9 +18,9 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { RoleColors } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { Guild } from "./Guild";
@Entity({
name: "roles",
+1 -1
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import type { User } from "./User";
@Entity({
name: "security_keys",
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import crypto from "crypto";
import { User } from "./User";
import { BaseClassWithoutId } from "./BaseClass";
import { Column, CreateDateColumn, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm";
import { Activity, ClientStatus, GatewaySession, GatewaySessionClientInfo, Status } from "../interfaces";
import { randomUpperString } from "@spacebar/api";
import { DateBuilder, IpDataClient, TimeSpan } from "../util";
import { BaseClassWithoutId } from "./BaseClass";
import type { User } from "./User";
@Entity({
name: "sessions",
+5 -4
View File
@@ -17,10 +17,11 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
import { StickerFormatType, StickerType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { Guild } from "./Guild";
import type { User } from "./User";
import type { StickerPack } from "./StickerPack";
@Entity({
name: "stickers",
@@ -47,7 +48,7 @@ export class Sticker extends BaseClass {
onDelete: "CASCADE",
nullable: true,
})
pack: import("./StickerPack").StickerPack;
pack: StickerPack;
@Column({ nullable: true })
guild_id?: string;
+1 -1
View File
@@ -17,8 +17,8 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { Sticker } from "./Sticker";
import { BaseClass } from "./BaseClass";
import type { Sticker } from "./Sticker";
@Entity({
name: "sticker_packs",
+2 -2
View File
@@ -1,7 +1,7 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { Channel } from "./Channel";
import type { User } from "./User";
import type { Channel } from "./Channel";
@Entity({
name: "streams",
+2 -2
View File
@@ -1,7 +1,7 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { Stream } from "./Stream";
import type { User } from "./User";
import type { Stream } from "./Stream";
@Entity({
name: "stream_sessions",
+1 -1
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import type { Channel } from "./Channel";
@Entity({
name: "tags",
+2 -2
View File
@@ -18,8 +18,8 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { TeamMember } from "./TeamMember";
import { User } from "./User";
import type { TeamMember } from "./TeamMember";
import type { User } from "./User";
@Entity({
name: "teams",
+5 -4
View File
@@ -17,9 +17,10 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import { TeamMemberRole, TeamMemberState } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { User } from "./User";
import type { Team } from "./Team";
@Entity({
name: "team_members",
@@ -39,10 +40,10 @@ export class TeamMember extends BaseClass {
team_id: string;
@JoinColumn({ name: "team_id" })
@ManyToOne(() => require("./Team").Team, (team: import("./Team").Team) => team.members, {
@ManyToOne(() => require("./Team").Team, (team: Team) => team.members, {
onDelete: "CASCADE",
})
team: import("./Team").Team;
team: Team;
@Column({ nullable: true })
@RelationId((member: TeamMember) => member.user)
+2 -2
View File
@@ -18,8 +18,8 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
import type { Guild } from "./Guild";
import type { User } from "./User";
@Entity({
name: "templates",
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn, RelationId } from "typeorm";
import { HTTPError } from "lambert-server";
import { ThreadMembersUpdateEvent } from "../interfaces";
import { emitEvent } from "../util";
import { BaseClassWithoutId } from "./BaseClass";
import { Channel } from "./Channel";
import { HTTPError } from "lambert-server";
import { Member } from "./Member";
import type { Member } from "./Member";
// TODO: move
interface ThreadMemberMuteConfig {
+9 -9
View File
@@ -20,14 +20,6 @@ import { Request } from "express";
import { Column, Entity, JoinColumn, OneToMany, OneToOne } from "typeorm";
import { Config, Email, FieldErrors, Snowflake, trimSpecial } from "..";
import { Random } from "../util";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { ConnectedAccount } from "./ConnectedAccount";
import { Member } from "./Member";
import { Relationship } from "./Relationship";
import { SecurityKey } from "./SecurityKey";
import { Session } from "./Session";
import { UserSettings } from "./UserSettings";
import {
AvatarDecorationData,
ChannelType,
@@ -40,6 +32,14 @@ import {
UserPrivate,
} from "@spacebar/schemas";
import { JsonNumber } from "../util/Decorators";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import type { ConnectedAccount } from "./ConnectedAccount";
import { Member } from "./Member";
import type { Relationship } from "./Relationship";
import type { SecurityKey } from "./SecurityKey";
import type { Session } from "./Session";
import { UserSettings } from "./UserSettings";
@Entity({
name: "users",
@@ -144,7 +144,7 @@ export class User extends BaseClass {
@JsonNumber
rights: string;
@OneToMany(() => Session, (session: Session) => session.user)
@OneToMany(() => require("./Session").Session, (session: Session) => session.user)
sessions: Session[];
@JoinColumn({ name: "relationship_ids" })
+1 -1
View File
@@ -17,8 +17,8 @@
*/
import { Column, Entity, PrimaryGeneratedColumn } from "typeorm";
import { BaseClassWithoutId } from "./BaseClass";
import { CustomStatus, FriendSourceFlags, GuildFolder } from "@spacebar/schemas";
import { BaseClassWithoutId } from "./BaseClass";
@Entity({
name: "user_settings",
+1 -1
View File
@@ -17,9 +17,9 @@
*/
import { Column, Entity, JoinColumn, OneToOne } from "typeorm";
import { FrecencyUserSettings, PreloadedUserSettings } from "discord-protos";
import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass";
import { User } from "./User";
import { FrecencyUserSettings, PreloadedUserSettings } from "discord-protos";
@Entity({
name: "user_settings_protos",
+5 -5
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { Member } from "./Member";
import { User } from "./User";
import { PublicVoiceState, PublicVoiceStateProjection } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { Channel } from "./Channel";
import type { Guild } from "./Guild";
import type { Member } from "./Member";
import type { User } from "./User";
//https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex
@Entity({
+5 -5
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { Application } from "./Application";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";
import { WebhookType } from "@spacebar/schemas";
import { BaseClass } from "./BaseClass";
import type { Application } from "./Application";
import type { Channel } from "./Channel";
import type { Guild } from "./Guild";
import type { User } from "./User";
@Entity({
name: "webhooks",