Revert "Merge pull request #1008 from spacebarchat/dev/samuel"

This reverts commit 69ea71aa9e, reversing
changes made to 8b2faf0b18.
This commit is contained in:
Madeline
2023-03-31 15:26:15 +11:00
parent c8f65ca4c7
commit 698ad90d3e
51 changed files with 2600 additions and 3583 deletions
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Team } from "./Team";
import { User } from "./User";
@Entity("applications")
export class Application extends EntityCache {
export class Application extends BaseClass {
@Column()
name: string;
+2 -2
View File
@@ -25,11 +25,11 @@ import {
RelationId,
} from "typeorm";
import { URL } from "url";
import { EntityCache } from "../cache";
import { deleteFile } from "../util/cdn";
import { BaseClass } from "./BaseClass";
@Entity("attachments")
export class Attachment extends EntityCache {
export class Attachment extends BaseClass {
@Column()
filename: string; // name of file attached
+2 -2
View File
@@ -17,7 +17,7 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { ChannelPermissionOverwrite } from "./Channel";
import { User } from "./User";
@@ -112,7 +112,7 @@ export enum AuditLogEvents {
}
@Entity("audit_logs")
export class AuditLog extends EntityCache {
export class AuditLog extends BaseClass {
@JoinColumn({ name: "target_id" })
@ManyToOne(() => User)
target?: User;
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
import crypto from "crypto";
@Entity("backup_codes")
export class BackupCode extends EntityCache {
export class BackupCode extends BaseClass {
@JoinColumn({ name: "user_id" })
@ManyToOne(() => User, { onDelete: "CASCADE" })
user: User;
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
@Entity("bans")
export class Ban extends EntityCache {
export class Ban extends BaseClass {
@Column({ nullable: true })
@RelationId((ban: Ban) => ban.user)
user_id: string;
+24 -20
View File
@@ -25,12 +25,16 @@ import {
PrimaryColumn,
} from "typeorm";
import { Snowflake } from "../util/Snowflake";
import { getDatabase } from "../util/Database";
import { OrmUtils } from "../imports/OrmUtils";
import { getDatabase } from "../util";
export class BaseClassWithoutId extends BaseEntity {
public get metadata() {
return getDatabase()?.getMetadata(this.constructor);
private get construct() {
return this.constructor;
}
private get metadata() {
return getDatabase()?.getMetadata(this.construct);
}
assign(props: object) {
@@ -57,23 +61,8 @@ export class BaseClassWithoutId extends BaseEntity {
),
);
}
}
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb")
? ObjectIdColumn
: PrimaryColumn;
export class BaseClassWithId extends BaseClassWithoutId {
@PrimaryIdColumn()
id: string = Snowflake.generate();
@BeforeUpdate()
@BeforeInsert()
_do_validate() {
if (!this.id) this.id = Snowflake.generate();
}
static increment<T extends BaseClassWithId>(
static increment<T extends BaseClass>(
conditions: FindOptionsWhere<T>,
propertyPath: string,
value: number | string,
@@ -82,7 +71,7 @@ export class BaseClassWithId extends BaseClassWithoutId {
return repository.increment(conditions, propertyPath, value);
}
static decrement<T extends BaseClassWithId>(
static decrement<T extends BaseClass>(
conditions: FindOptionsWhere<T>,
propertyPath: string,
value: number | string,
@@ -91,3 +80,18 @@ export class BaseClassWithId extends BaseClassWithoutId {
return repository.decrement(conditions, propertyPath, value);
}
}
export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb")
? ObjectIdColumn
: PrimaryColumn;
export class BaseClass extends BaseClassWithoutId {
@PrimaryIdColumn()
id: string = Snowflake.generate();
@BeforeUpdate()
@BeforeInsert()
_do_validate() {
if (!this.id) this.id = Snowflake.generate();
}
}
+2 -2
View File
@@ -24,7 +24,7 @@ import {
OneToMany,
RelationId,
} from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { PublicUserProjection, User } from "./User";
import { HTTPError } from "lambert-server";
@@ -70,7 +70,7 @@ export enum ChannelType {
}
@Entity("channels")
export class Channel extends EntityCache {
export class Channel extends BaseClass {
@Column()
created_at: Date;
+2 -2
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
@Entity("client_release")
export class Release extends EntityCache {
export class Release extends BaseClass {
@Column()
name: string;
+2 -2
View File
@@ -17,7 +17,7 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
export type PublicConnectedAccount = Pick<
@@ -26,7 +26,7 @@ export type PublicConnectedAccount = Pick<
>;
@Entity("connected_accounts")
export class ConnectedAccount extends EntityCache {
export class ConnectedAccount extends BaseClass {
@Column({ nullable: true })
@RelationId((account: ConnectedAccount) => account.user)
user_id: string;
+2 -2
View File
@@ -16,12 +16,12 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Entity, Column } from "typeorm";
import { Embed } from "./Message";
@Entity("embed_cache")
export class EmbedCache extends EntityCache {
export class EmbedCache extends BaseClass {
@Column()
url: string;
+2 -2
View File
@@ -18,11 +18,11 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from ".";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
@Entity("emojis")
export class Emoji extends EntityCache {
export class Emoji extends BaseClass {
@Column()
animated: boolean;
+2 -2
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
@Entity("security_settings")
export class SecuritySettings extends EntityCache {
export class SecuritySettings extends BaseClass {
@Column({ nullable: true })
guild_id: string;
+2 -2
View File
@@ -26,7 +26,7 @@ import {
} from "typeorm";
import { Config, handleFile, Snowflake } from "..";
import { Ban } from "./Ban";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Emoji } from "./Emoji";
import { Invite } from "./Invite";
@@ -67,7 +67,7 @@ export const PublicGuildRelations = [
];
@Entity("guilds")
export class Guild extends EntityCache {
export class Guild extends BaseClass {
@Column({ nullable: true })
@RelationId((guild: Guild) => guild.afk_channel)
afk_channel_id?: string;
+2 -2
View File
@@ -34,7 +34,7 @@ import {
OneToMany,
RelationId,
} from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { Webhook } from "./Webhook";
import { Sticker } from "./Sticker";
@@ -70,7 +70,7 @@ export enum MessageType {
@Entity("messages")
@Index(["channel_id", "id"], { unique: true })
export class Message extends EntityCache {
export class Message extends BaseClass {
@Column({ nullable: true })
@RelationId((message: Message) => message.channel)
@Index()
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, Unique } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
@Entity("notes")
@Unique(["owner", "target"])
export class Note extends EntityCache {
export class Note extends BaseClass {
@JoinColumn({ name: "owner_id" })
@ManyToOne(() => User, { onDelete: "CASCADE" })
owner: User;
+2 -2
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
@Entity("rate_limits")
export class RateLimit extends EntityCache {
export class RateLimit extends BaseClass {
@Column() // no relation as it also
executor_id: string;
+2 -2
View File
@@ -24,7 +24,7 @@ import {
ManyToOne,
RelationId,
} from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { User } from "./User";
@@ -34,7 +34,7 @@ import { User } from "./User";
@Entity("read_states")
@Index(["channel_id", "user_id"], { unique: true })
export class ReadState extends EntityCache {
export class ReadState extends BaseClass {
@Column()
@RelationId((read_state: ReadState) => read_state.channel)
channel_id: string;
+2 -2
View File
@@ -17,10 +17,10 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
@Entity("recipients")
export class Recipient extends EntityCache {
export class Recipient extends BaseClass {
@Column()
@RelationId((recipient: Recipient) => recipient.channel)
channel_id: string;
+2 -2
View File
@@ -24,7 +24,7 @@ import {
ManyToOne,
RelationId,
} from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
export enum RelationshipType {
@@ -36,7 +36,7 @@ export enum RelationshipType {
@Entity("relationships")
@Index(["from_id", "to_id"], { unique: true })
export class Relationship extends EntityCache {
export class Relationship extends BaseClass {
@Column({})
@RelationId((relationship: Relationship) => relationship.from)
from_id: string;
+2 -2
View File
@@ -18,11 +18,11 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
@Entity("roles")
export class Role extends EntityCache {
export class Role extends BaseClass {
@Column({ nullable: true })
@RelationId((role: Role) => role.guild)
guild_id: string;
+2 -2
View File
@@ -17,11 +17,11 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
@Entity("security_keys")
export class SecurityKey extends EntityCache {
export class SecurityKey extends BaseClass {
@Column({ nullable: true })
@RelationId((key: SecurityKey) => key.user)
user_id: string;
+2 -2
View File
@@ -17,7 +17,7 @@
*/
import { User } from "./User";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { Status } from "../interfaces/Status";
import { Activity } from "../interfaces/Activity";
@@ -25,7 +25,7 @@ import { Activity } from "../interfaces/Activity";
//TODO we need to remove all sessions on server start because if the server crashes without closing websockets it won't delete them
@Entity("sessions")
export class Session extends EntityCache {
export class Session extends BaseClass {
@Column({ nullable: true })
@RelationId((session: Session) => session.user)
user_id: string;
+2 -2
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { User } from "./User";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
export enum StickerType {
@@ -34,7 +34,7 @@ export enum StickerFormatType {
}
@Entity("stickers")
export class Sticker extends EntityCache {
export class Sticker extends BaseClass {
@Column()
name: string;
+2 -2
View File
@@ -25,10 +25,10 @@ import {
RelationId,
} from "typeorm";
import { Sticker } from ".";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
@Entity("sticker_packs")
export class StickerPack extends EntityCache {
export class StickerPack extends BaseClass {
@Column()
name: string;
+2 -2
View File
@@ -24,12 +24,12 @@ import {
OneToMany,
RelationId,
} from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { TeamMember } from "./TeamMember";
import { User } from "./User";
@Entity("teams")
export class Team extends EntityCache {
export class Team extends BaseClass {
@Column({ nullable: true })
icon?: string;
+2 -2
View File
@@ -17,7 +17,7 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { User } from "./User";
export enum TeamMemberState {
@@ -26,7 +26,7 @@ export enum TeamMemberState {
}
@Entity("team_members")
export class TeamMember extends EntityCache {
export class TeamMember extends BaseClass {
@Column({ type: "int" })
membership_state: TeamMemberState;
+2 -2
View File
@@ -17,12 +17,12 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Guild } from "./Guild";
import { User } from "./User";
@Entity("templates")
export class Template extends EntityCache {
export class Template extends BaseClass {
@Column({ unique: true })
code: string;
+2 -2
View File
@@ -34,7 +34,7 @@ import {
trimSpecial,
} from "..";
import { BitField } from "../util/BitField";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { ConnectedAccount } from "./ConnectedAccount";
import { Member } from "./Member";
import { Relationship } from "./Relationship";
@@ -94,7 +94,7 @@ export interface UserPrivate extends Pick<User, PrivateUserKeys> {
}
@Entity("users")
export class User extends EntityCache {
export class User extends BaseClass {
@Column()
username: string; // username max length 32, min 2 (should be configurable)
+2 -2
View File
@@ -17,7 +17,7 @@
*/
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";
@@ -25,7 +25,7 @@ import { Member } from "./Member";
//https://gist.github.com/vassjozsef/e482c65df6ee1facaace8b3c9ff66145#file-voice_state-ex
@Entity("voice_states")
export class VoiceState extends EntityCache {
export class VoiceState extends BaseClass {
@Column({ nullable: true })
@RelationId((voice_state: VoiceState) => voice_state.guild)
guild_id: string;
+2 -2
View File
@@ -18,7 +18,7 @@
import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
import { Application } from "./Application";
import { EntityCache } from "../cache";
import { BaseClass } from "./BaseClass";
import { Channel } from "./Channel";
import { Guild } from "./Guild";
import { User } from "./User";
@@ -30,7 +30,7 @@ export enum WebhookType {
}
@Entity("webhooks")
export class Webhook extends EntityCache {
export class Webhook extends BaseClass {
@Column({ type: "int" })
type: WebhookType;