2024-03-22 10:23:28 +01:00
|
|
|
import { z } from "zod"
|
|
|
|
|
|
|
|
export const EntitySchema = z.object({
|
|
|
|
id: z.string(),
|
|
|
|
})
|
|
|
|
|
|
|
|
export type EntityData = z.infer<typeof EntitySchema>
|
2024-03-15 22:48:28 +01:00
|
|
|
|
2024-03-22 10:23:28 +01:00
|
|
|
export abstract class Entity implements EntityData {
|
2024-03-15 22:48:28 +01:00
|
|
|
public readonly id: string
|
|
|
|
|
2024-03-22 10:23:28 +01:00
|
|
|
public constructor(options: EntityData) {
|
2024-03-15 22:48:28 +01:00
|
|
|
const { id } = options
|
|
|
|
this.id = id
|
|
|
|
}
|
|
|
|
|
2024-03-22 10:23:28 +01:00
|
|
|
public equals(entity: Entity): boolean {
|
|
|
|
return entity.id === this.id
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract toJSON(): EntityData
|
2024-03-15 22:48:28 +01:00
|
|
|
}
|