MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / validateRuntimeScope

Function validateRuntimeScope

projects/runtime-protocol/src/protocol.ts:460–485  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

458}
459
460export 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
487export function validateRuntimeRecord(value: unknown): RuntimeValidationResult<RuntimeRecord> {
488 if (!isRecord(value)) return validationError("$", "Runtime record must be an object")

Callers 1

validateRuntimeRecordFunction · 0.85

Calls 4

validationErrorFunction · 0.85
hasMethod · 0.80
entriesMethod · 0.80
isRecordFunction · 0.70

Tested by

no test coverage detected