콘텐츠로 이동

reconcileSyncPage — @gj-kit/expo-workouts

@gj-kit/expo-workouts/core에서 공개하는 function입니다. package version 0.1.1의 release declaration을 그대로 표시합니다.

import { reconcileSyncPage } from '@gj-kit/expo-workouts/core';
/**
* Split one sync page into the three operations a local store actually performs.
*
* - `rekeys` come from `removed[].replaced === true` matched against the same page's `added` —
* iOS replaces a workout's native id when the same sync identifier is re-saved. Apply them as an
* UPDATE of the primary key, NEVER as DELETE + INSERT, or you lose your local join data (server
* ids, upload state, notes).
* - `deletes` are the genuinely-gone ids. Applying one for an id you never held must be a no-op.
*
* ⚠ Matching heuristic, stated out loud: `RemovedWorkout` deliberately does not carry a
* `replacedById` field, so a replaced removal is paired, in order, with the same page's own
* writes (`isOwn && clientId != null`). A batch that carries several replacements at once pairs
* them positionally, which is what the platform emits. A replaced removal that finds no partner
* is NEVER turned into a delete — `replaced: true` means the workout still exists, and deleting
* it would destroy the caller's join data.
*/
declare function reconcileSyncPage(page: Pick<SyncPage, 'added' | 'removed'>): {
readonly upserts: readonly Workout[];
readonly deletes: readonly string[];
readonly rekeys: readonly {
readonly fromId: string;
readonly toId: string;
}[];
};

이 선언은 매개변수, optionality, 제네릭, 반환값, 공개 union/type 계약의 정본입니다. 호출 전 필요한 환경·권한·오류 경계는 패키지 Golden path와 이 subpath의 import 조건을 함께 확인하세요.

  • 패키지: @gj-kit/expo-workouts
  • 버전: 0.1.1
  • 공개 entry: ./core
  • 소스: GitHub

Split one sync page into the three operations a local store actually performs.

  • rekeys come from removed[].replaced === true matched against the same page’s added — iOS replaces a workout’s native id when the same sync identifier is re-saved. Apply them as an UPDATE of the primary key, NEVER as DELETE + INSERT, or you lose your local join data (server ids, upload state, notes).
  • deletes are the genuinely-gone ids. Applying one for an id you never held must be a no-op.

⚠ Matching heuristic, stated out loud: RemovedWorkout deliberately does not carry a replacedById field, so a replaced removal is paired, in order, with the same page’s own writes (isOwn && clientId != null). A batch that carries several replacements at once pairs them positionally, which is what the platform emits. A replaced removal that finds no partner is NEVER turned into a delete — replaced: true means the workout still exists, and deleting it would destroy the caller’s join data.