import type { EngineStore } from '../../store' import type { WriteContext } from '../../types' export async function writeStage( ctx: WriteContext, store: EngineStore, merge?: (existing: unknown | null, incoming: unknown) => unknown, lastParamsKey?: string, ): Promise { const data = merge ? merge(store.getState().slices[ctx.key]?.data ?? null, ctx.data) : ctx.data store.getState().actions.setSlice(ctx.key, { data, status: ctx.status, isLoading: false, isFetching: false, isError: false, error: null, warnings: ctx.warnings, lastUpdated: Date.now(), ...(lastParamsKey !== undefined ? { lastParamsKey } : {}), }) }