fix(connection): share fixture goal revision lookup
This commit is contained in:
@@ -1598,12 +1598,9 @@ function createFixtureWorld(options: FixtureOptions): FixtureWorld {
|
|||||||
))
|
))
|
||||||
},
|
},
|
||||||
clear(id: SessionId, ref: FxGoalRef): RpcResult<FxGoalRef> {
|
clear(id: SessionId, ref: FxGoalRef): RpcResult<FxGoalRef> {
|
||||||
const missing = requireGoalSession(id)
|
const resolved = resolveGoal(id, ref)
|
||||||
if (missing !== undefined) return missing
|
if (!resolved.ok) return resolved
|
||||||
const current = backscanGoal(logOf(id))
|
const current = resolved.value
|
||||||
if (current === null || current.goal.id !== ref.id || current.goal.revision !== ref.revision) {
|
|
||||||
return goalFailure('stale or missing goal revision')
|
|
||||||
}
|
|
||||||
const tombstone = { id: current.goal.id, revision: current.goal.revision + 1 }
|
const tombstone = { id: current.goal.id, revision: current.goal.revision + 1 }
|
||||||
appendGoalChange(id, {
|
appendGoalChange(id, {
|
||||||
kind: 'goal/change', version: 1, operation: 'clear', cleared: tombstone, clearedAt: Date.now(),
|
kind: 'goal/change', version: 1, operation: 'clear', cleared: tombstone, clearedAt: Date.now(),
|
||||||
@@ -1612,18 +1609,26 @@ function createFixtureWorld(options: FixtureOptions): FixtureWorld {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Shared CAS mutation path behind the canonical Remote verbs. */
|
/** Resolve one current goal revision for a canonical Remote mutation. */
|
||||||
function mutateGoal(
|
function resolveGoal(id: SessionId, ref: FxGoalRef): RpcResult<FxGoalProjection> {
|
||||||
id: SessionId,
|
|
||||||
ref: FxGoalRef,
|
|
||||||
next: (current: FxGoalProjection) => FxGoalProjection['goal'] | undefined,
|
|
||||||
): RpcResult<FxGoalView> {
|
|
||||||
const missing = requireGoalSession(id)
|
const missing = requireGoalSession(id)
|
||||||
if (missing !== undefined) return missing
|
if (missing !== undefined) return missing
|
||||||
const current = backscanGoal(logOf(id))
|
const current = backscanGoal(logOf(id))
|
||||||
if (current === null || current.goal.id !== ref.id || current.goal.revision !== ref.revision) {
|
if (current === null || current.goal.id !== ref.id || current.goal.revision !== ref.revision) {
|
||||||
return goalFailure('stale or missing goal revision')
|
return goalFailure('stale or missing goal revision')
|
||||||
}
|
}
|
||||||
|
return { ok: true, value: current }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shared CAS mutation path behind the canonical Remote verbs. */
|
||||||
|
function mutateGoal(
|
||||||
|
id: SessionId,
|
||||||
|
ref: FxGoalRef,
|
||||||
|
next: (current: FxGoalProjection) => FxGoalProjection['goal'] | undefined,
|
||||||
|
): RpcResult<FxGoalView> {
|
||||||
|
const resolved = resolveGoal(id, ref)
|
||||||
|
if (!resolved.ok) return resolved
|
||||||
|
const current = resolved.value
|
||||||
const goal = next(current)
|
const goal = next(current)
|
||||||
if (goal === undefined) {
|
if (goal === undefined) {
|
||||||
return goalFailure(`invalid goal transition from "${current.goal.phase}"`)
|
return goalFailure(`invalid goal transition from "${current.goal.phase}"`)
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user