feat: sync implementation for the user entity (#16234)

* ci: print out typeorm generation changes

* feat: sync implementation for the user entity

wip

---------

Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
Zack Pollard 2025-02-21 04:37:57 +00:00 committed by GitHub
parent 02cd8da871
commit ac36effb45
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
38 changed files with 1774 additions and 10 deletions

30
server/src/utils/sync.ts Normal file
View file

@ -0,0 +1,30 @@
import { SyncItem } from 'src/dtos/sync.dto';
import { SyncEntityType } from 'src/enum';
import { SyncAck } from 'src/types';
type Impossible<K extends keyof any> = {
[P in K]: never;
};
type Exact<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
export const fromAck = (ack: string): SyncAck => {
const [type, timestamp, ...ids] = ack.split('|');
return { type: type as SyncEntityType, ackEpoch: timestamp, ids };
};
export const toAck = ({ type, ackEpoch, ids }: SyncAck) => [type, ackEpoch, ...ids].join('|');
export const mapJsonLine = (object: unknown) => JSON.stringify(object) + '\n';
export const serialize = <T extends keyof SyncItem, D extends SyncItem[T]>({
type,
ackEpoch,
ids,
data,
}: {
type: T;
ackEpoch: string;
ids: string[];
data: Exact<SyncItem[T], D>;
}) => mapJsonLine({ type, data, ack: toAck({ type, ackEpoch, ids }) });