Refactor base types for entities and tombstones
Rename the base Entity type to ApiEntity, and the base EntityToombstone to ApiTombstone to better reflect the reality that its only used in the API interface and that the client and server types uses its own base if any. Remove EntityLiving and pull EntityTombstone out of of the base entity type so that the types based on ApiEntity are always living entities and if it's possible for it to contain tombstone this will be explicitly told with the type including a union with ApiTombstone. Refactor the types of the ClientEntity and ClientMap to better reflect the types of the entities it stores and converts to/from.
This commit is contained in:
parent
e3ff872b5c
commit
985b8e0950
13 changed files with 107 additions and 102 deletions
|
@ -1,7 +1,8 @@
|
|||
import type { Entity, EntityLiving, Id } from "~/shared/types/common";
|
||||
import type { ApiEntity, ApiTombstone } from "~/shared/types/api";
|
||||
import type { Id } from "~/shared/types/common";
|
||||
import { DateTime, Zone } from "~/shared/utils/luxon";
|
||||
|
||||
export abstract class ClientEntity {
|
||||
export abstract class ClientEntity<Api extends ApiEntity> {
|
||||
/**
|
||||
Millisecond offset used to indicate this is a new entitity.
|
||||
*/
|
||||
|
@ -73,10 +74,10 @@ export abstract class ClientEntity {
|
|||
/**
|
||||
Apply an update delivered from the API to this entity.
|
||||
*/
|
||||
abstract apiUpdate(api: EntityLiving, opts: { zone: Zone, locale: string }): void
|
||||
abstract apiUpdate(api: Api, opts: { zone: Zone, locale: string }): void
|
||||
|
||||
/**
|
||||
Serialise this entity to the API format. Not allowed if {@link deleted} is true.
|
||||
*/
|
||||
abstract toApi(): Entity
|
||||
abstract toApi(): Api | ApiTombstone
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue