(value: unknown)
| 458 | } |
| 459 | |
| 460 | export function validateRuntimeScope(value: unknown): RuntimeValidationResult<RuntimeScope> { |
| 461 | if (!isRecord(value)) return validationError("$", "Runtime scope must be an object") |
| 462 | for (const key of Object.keys(value)) { |
| 463 | if (!RUNTIME_SCOPE_KEYS.has(key)) return validationError(`$.${key}`, `${key} is not allowed in runtime scope`) |
| 464 | } |
| 465 | |
| 466 | const output: RuntimeScope = {} |
| 467 | for (const key of ["workspaceId", "rootPath", "repoPath", "correlationId", "ownerType", "ownerId"] as const) { |
| 468 | const field = value[key] |
| 469 | if (field === undefined) continue |
| 470 | if (typeof field !== "string") return validationError(`$.${key}`, `${key} must be a string`) |
| 471 | output[key] = field |
| 472 | } |
| 473 | |
| 474 | if (value.labels !== undefined) { |
| 475 | if (!isRecord(value.labels)) return validationError("$.labels", "labels must be an object") |
| 476 | const labels: Record<string, string> = {} |
| 477 | for (const [labelKey, labelValue] of Object.entries(value.labels)) { |
| 478 | if (typeof labelValue !== "string") return validationError(`$.labels.${labelKey}`, "label values must be strings") |
| 479 | labels[labelKey] = labelValue |
| 480 | } |
| 481 | output.labels = labels |
| 482 | } |
| 483 | |
| 484 | return { ok: true, value: output } |
| 485 | } |
| 486 | |
| 487 | export function validateRuntimeRecord(value: unknown): RuntimeValidationResult<RuntimeRecord> { |
| 488 | if (!isRecord(value)) return validationError("$", "Runtime record must be an object") |
no test coverage detected