refactor: use new updateId column for user CUD sync (#16384)

This commit is contained in:
Zack Pollard 2025-02-27 14:22:02 +00:00 committed by GitHub
parent 7d6cfd09e6
commit fb907d707d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 50 additions and 47 deletions

View file

@ -9,22 +9,20 @@ type Impossible<K extends keyof any> = {
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 };
const [type, updateId] = ack.split('|');
return { type: type as SyncEntityType, updateId };
};
export const toAck = ({ type, ackEpoch, ids }: SyncAck) => [type, ackEpoch, ...ids].join('|');
export const toAck = ({ type, updateId }: SyncAck) => [type, updateId].join('|');
export const mapJsonLine = (object: unknown) => JSON.stringify(object) + '\n';
export const serialize = <T extends keyof SyncItem, D extends SyncItem[T]>({
type,
ackEpoch,
ids,
updateId,
data,
}: {
type: T;
ackEpoch: string;
ids: string[];
updateId: string;
data: Exact<SyncItem[T], D>;
}) => mapJsonLine({ type, data, ack: toAck({ type, ackEpoch, ids }) });
}) => mapJsonLine({ type, data, ack: toAck({ type, updateId }) });