import * as S from "@effect/schema/Schema";
import { Equal, Hash } from "effect";
import { uuidv7 } from "uuidv7";
export abstract class Entity
extends S.Class<Entity>("@core/domain/Entity")({
id: S.UUID.pipe(
S.propertySignature,
S.withConstructorDefault(() => S.UUID.make(uuidv7())),
),
})
implements Equal.Equal
{
[Hash.symbol](): number {
return Hash.hash(this.id);
}
[Equal.symbol](that: unknown): boolean {
if (that instanceof Entity) {
return (
Equal.equals(that.constructor.name, this.constructor.name) && Equal.equals(that.id, this.id)
);
}
return false;
}
}
import * as S from "@effect/schema/Schema";
import { Equal, Hash } from "effect";
import { uuidv7 } from "uuidv7";
export abstract class Entity
extends S.Class<Entity>("@core/domain/Entity")({
id: S.UUID.pipe(
S.propertySignature,
S.withConstructorDefault(() => S.UUID.make(uuidv7())),
),
})
implements Equal.Equal
{
[Hash.symbol](): number {
return Hash.hash(this.id);
}
[Equal.symbol](that: unknown): boolean {
if (that instanceof Entity) {
return (
Equal.equals(that.constructor.name, this.constructor.name) && Equal.equals(that.id, this.id)
);
}
return false;
}
}