MCPcopy Create free account
hub / github.com/cloudflare/computer / assertValue

Function assertValue

packages/computer/src/runtime/capability.ts:260–279  ·  view source on GitHub ↗
(value: unknown, seen: WeakSet<object>)

Source from the content-addressed store, hash-verified

258}
259
260function assertValue(value: unknown, seen: WeakSet<object>): void {
261 if (value === null || typeof value === "boolean" || typeof value === "string") return;
262 if (typeof value === "number" && Number.isFinite(value)) return;
263 if (typeof value !== "object") {
264 throw new Error("Workspace code inputs and results must be JSON-compatible values.");
265 }
266 if (seen.has(value)) throw new Error("Workspace code inputs and results cannot contain cycles.");
267 seen.add(value);
268 if (Array.isArray(value)) {
269 for (const item of value) assertValue(item, seen);
270 seen.delete(value);
271 return;
272 }
273 const prototype = Object.getPrototypeOf(value);
274 if (prototype !== Object.prototype && prototype !== null) {
275 throw new Error("Workspace code inputs and results must use plain objects.");
276 }
277 for (const item of Object.values(value)) assertValue(item, seen);
278 seen.delete(value);
279}

Callers 1

assertRuntimeValueFunction · 0.85

Calls 4

hasMethod · 0.80
addMethod · 0.65
deleteMethod · 0.65
valuesMethod · 0.65

Tested by

no test coverage detected