Write the logic of keeping track of location modifications and applying updates from the server into the ClientSchedule class. This should serve as the foundation for replacing the prototype in-component update logic which have turned into an unmaintainable spagetti.
28 lines
965 B
TypeScript
28 lines
965 B
TypeScript
import { z } from "zod/v4-mini";
|
|
|
|
export const idSchema = z.number();
|
|
export type Id = z.infer<typeof idSchema>;
|
|
|
|
export const entityLivingSchema = z.object({
|
|
id: idSchema,
|
|
updatedAt: z.string(),
|
|
deleted: z.optional(z.literal(false)),
|
|
});
|
|
export type EntityLiving = z.infer<typeof entityLivingSchema>;
|
|
|
|
export const entityToombstoneSchema = z.object({
|
|
id: idSchema,
|
|
updatedAt: z.string(),
|
|
deleted: z.literal(true),
|
|
});
|
|
export type EntityToombstone = z.infer<typeof entityToombstoneSchema>;
|
|
|
|
export const entitySchema = z.discriminatedUnion("deleted", [entityLivingSchema, entityToombstoneSchema]);
|
|
export type Entity = z.infer<typeof entitySchema>;
|
|
|
|
export type Living<T extends Entity> = Extract<T, { deleted?: false }>;
|
|
export type Tombstone<T extends Entity> = Extract<T, { deleted: true }>;
|
|
|
|
export function defineEntity<T extends {}>(fields: T) {
|
|
return z.discriminatedUnion("deleted", [z.extend(entityLivingSchema, fields), entityToombstoneSchema]);
|
|
}
|