refactor: sync service (#19225)

This commit is contained in:
Jason Rasmussen 2025-06-17 12:06:40 -04:00 committed by GitHub
parent 4c69511225
commit 35280b94cc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 235 additions and 234 deletions

View file

@ -18,14 +18,17 @@ export const toAck = ({ type, updateId, extraId }: SyncAck) =>
export const mapJsonLine = (object: unknown) => JSON.stringify(object) + '\n';
export type SerializeOptions<T extends keyof SyncItem, D extends SyncItem[T]> = {
type: T;
data: Exact<SyncItem[T], D>;
ids: [string] | [string, string];
ackType?: SyncEntityType;
};
export const serialize = <T extends keyof SyncItem, D extends SyncItem[T]>({
type,
data,
ids,
ackType,
}: {
type: T;
data: Exact<SyncItem[T], D>;
ids: [string] | [string, string];
ackType?: SyncEntityType;
}) => mapJsonLine({ type, data, ack: toAck({ type: ackType ?? type, updateId: ids[0], extraId: ids[1] }) });
}: SerializeOptions<T, D>) =>
mapJsonLine({ type, data, ack: toAck({ type: ackType ?? type, updateId: ids[0], extraId: ids[1] }) });