MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / sdkTimingPersist

Function sdkTimingPersist

packages/studio/src/utils/sdkCutover.ts:158–197  ·  view source on GitHub ↗
(
  hfId: string,
  targetPath: string,
  timingUpdate: { start?: number; duration?: number; trackIndex?: number },
  sdkSession: Composition | null | undefined,
  deps: CutoverDeps,
  options?: CutoverOptions,
)

Source from the content-addressed store, hash-verified

156}
157
158export async function sdkTimingPersist(
159 hfId: string,
160 targetPath: string,
161 timingUpdate: { start?: number; duration?: number; trackIndex?: number },
162 sdkSession: Composition | null | undefined,
163 deps: CutoverDeps,
164 options?: CutoverOptions,
165): Promise<boolean> {
166 // Resolver tripwire — runs BEFORE the cutover gate (decoupled): records when
167 // the SDK can't resolve a target the server timing path is addressing.
168 const timingSrc = deps.readProjectFile;
169 void recordResolverParity(
170 sdkSession,
171 hfId,
172 "setTiming",
173 timingSrc ? () => timingSrc(targetPath) : undefined,
174 );
175 // Dark-launch gate: without this, timing cutover runs whenever an SDK session
176 // exists (it always does, for shadow/selection) — flipping the flag OFF would
177 // NOT disable it. Gate here so flag-off routes back to the legacy server path.
178 if (!STUDIO_SDK_CUTOVER_ENABLED) return false;
179 if (!sdkSession || !sdkSession.getElement(hfId)) return false;
180 if (wrongCompositionFile(deps, targetPath)) return false;
181 try {
182 const serializedBefore = sdkSession.serialize();
183 sdkSession.batch(() => sdkSession.setTiming(hfId, timingUpdate));
184 const after = sdkSession.serialize();
185 if (after === serializedBefore) return false;
186 // Undo baseline = exact on-disk bytes (matching the style/delete paths), so
187 // undoing a timing edit restores the file verbatim instead of a normalized
188 // full-DOM re-emit. Falls back to serializedBefore when no reader is wired.
189 const undoBefore = await captureOnDiskBefore(deps, targetPath, serializedBefore);
190 await persistSdkSerialize(after, targetPath, undoBefore, deps, options);
191 trackStudioEvent("sdk_cutover_success", { hfId, opCount: 1 });
192 return true;
193 } catch (err) {
194 trackStudioEvent("sdk_cutover_fallback", { hfId, error: String(err) });
195 return false;
196 }
197}
198
199type SdkGsapTweenOp =
200 | { kind: "add"; target: string; spec: GsapTweenSpec }

Callers 3

sdkCutover.test.tsFile · 0.90
useTimelineEditingFunction · 0.90

Calls 9

recordResolverParityFunction · 0.90
trackStudioEventFunction · 0.90
wrongCompositionFileFunction · 0.85
captureOnDiskBeforeFunction · 0.85
persistSdkSerializeFunction · 0.85
getElementMethod · 0.65
serializeMethod · 0.65
batchMethod · 0.65
setTimingMethod · 0.65

Tested by

no test coverage detected