24 lines
1.3 KiB
TypeScript
24 lines
1.3 KiB
TypeScript
import { pollProblem, validateServerPollContext, type ServerPollContext } from "./server-poll-execution-model.js"
|
|
|
|
/** Candidate projection for waiting on a human. Not an authority, signature,
|
|
* catalog attestation or replacement for the exact in-flight context proof.
|
|
* The fixed production reader authenticates the DB epoch guard in the same
|
|
* protected snapshot before its private callback can use this projection. */
|
|
export function projectServerPollApprovalContext(context: ServerPollContext, serverId: number) {
|
|
validateServerPollContext(context, serverId)
|
|
const projection = structuredClone(context)
|
|
for (const row of Object.values(projection.settings)) {
|
|
if (!row || typeof row.pollConfigurationEpoch !== "string"
|
|
|| !/^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$/.test(row.pollConfigurationEpoch)) {
|
|
pollProblem("STATE_UNAVAILABLE", "Отсутствует версия конфигурации настроек опроса")
|
|
}
|
|
delete row.lastCollectedAt
|
|
delete row.lastDurationMs
|
|
delete row.lastError
|
|
delete row.updatedAt
|
|
}
|
|
// Separate from the whole execution-context domain even when no runtime
|
|
// fields happened to be present. Preserve every unknown top-level field.
|
|
return { domain: "server-poll-approval-context-v1" as const, context: projection }
|
|
}
|