refactor(server): drop dead Fence.wait + redundant casts (#28710)
This commit is contained in:
@@ -4,7 +4,6 @@ import { EventSequenceTable } from "@/sync/event.sql"
|
|||||||
import { Workspace } from "@/control-plane/workspace"
|
import { Workspace } from "@/control-plane/workspace"
|
||||||
import type { WorkspaceID } from "@/control-plane/schema"
|
import type { WorkspaceID } from "@/control-plane/schema"
|
||||||
import * as Log from "@opencode-ai/core/util/log"
|
import * as Log from "@opencode-ai/core/util/log"
|
||||||
import { AppRuntime } from "@/effect/app-runtime"
|
|
||||||
import { Effect } from "effect"
|
import { Effect } from "effect"
|
||||||
|
|
||||||
export const HEADER = "x-opencode-sync"
|
export const HEADER = "x-opencode-sync"
|
||||||
@@ -20,7 +19,7 @@ export function load(ids?: string[]) {
|
|||||||
return db.select().from(EventSequenceTable).where(inArray(EventSequenceTable.aggregate_id, ids)).all()
|
return db.select().from(EventSequenceTable).where(inArray(EventSequenceTable.aggregate_id, ids)).all()
|
||||||
})
|
})
|
||||||
|
|
||||||
return Object.fromEntries(rows.map((row) => [row.aggregate_id, row.seq])) as State
|
return Object.fromEntries(rows.map((row) => [row.aggregate_id, row.seq]))
|
||||||
}
|
}
|
||||||
|
|
||||||
export function diff(prev: State, next: State) {
|
export function diff(prev: State, next: State) {
|
||||||
@@ -31,15 +30,14 @@ export function diff(prev: State, next: State) {
|
|||||||
.filter(([id, seq]) => {
|
.filter(([id, seq]) => {
|
||||||
return (prev[id] ?? -1) !== seq
|
return (prev[id] ?? -1) !== seq
|
||||||
}),
|
}),
|
||||||
) as State
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function parse(headers: Headers) {
|
export function parse(headers: Headers): State | undefined {
|
||||||
const raw = headers.get(HEADER)
|
const raw = headers.get(HEADER)
|
||||||
if (!raw) return
|
if (!raw) return
|
||||||
|
|
||||||
let data
|
let data
|
||||||
|
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(raw)
|
data = JSON.parse(raw)
|
||||||
} catch {
|
} catch {
|
||||||
@@ -49,10 +47,10 @@ export function parse(headers: Headers) {
|
|||||||
if (!data || typeof data !== "object") return
|
if (!data || typeof data !== "object") return
|
||||||
|
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(data).filter(([id, seq]) => {
|
Object.entries(data).filter((entry): entry is [string, number] => {
|
||||||
return typeof id === "string" && Number.isInteger(seq)
|
return typeof entry[0] === "string" && Number.isInteger(entry[1])
|
||||||
}),
|
}),
|
||||||
) as State
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function waitEffect(workspaceID: WorkspaceID, state: State, signal?: AbortSignal) {
|
export function waitEffect(workspaceID: WorkspaceID, state: State, signal?: AbortSignal) {
|
||||||
@@ -68,7 +66,3 @@ export function waitEffect(workspaceID: WorkspaceID, state: State, signal?: Abor
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function wait(workspaceID: WorkspaceID, state: State, signal?: AbortSignal) {
|
|
||||||
await AppRuntime.runPromise(waitEffect(workspaceID, state, signal))
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user