validateAgainstShape
validateAgainstShape(
data,shapeFields):ShapeValidatorResult
Validate a data payload against shape field definitions.
Shape field types:
- “number”, “string”, “boolean”: primitive types
- “wref”: string (reference to another thing)
- Typed field objects: { type: primitive, description?: string }
- Nested objects: { fieldName: type, … }
- Arrays: [elementType]
- Optional fields: field name ending with ”?” (e.g. “terminal_reason?”: “string”) OR type string ending with ”?” (e.g. “terminal_reason”: “string?”) OR typed object type ending with ”?” (e.g. { type: “string?” })
For v1 this is permissive: validates top-level field existence and basic types.
Returns a ShapeValidatorResult discriminated union — read result.valid
to branch, then result.errors (only present when invalid) for the list of
messages. result.warnings may be present in either branch and carries
undeclared top-level field names.
Parameters
Section titled “Parameters”Record<string, unknown>
shapeFields
Section titled “shapeFields”Record<string, unknown>
Returns
Section titled “Returns”Example
Section titled “Example”import { validateAgainstShape } from "@warmhub/sdk-ts";
const shapeFields = { x: "number", y: "number", label: "string?" };
const ok = validateAgainstShape({ x: 1, y: 2 }, shapeFields);// ok.valid === true
const bad = validateAgainstShape({ x: "not-a-number" }, shapeFields);if (!bad.valid) { for (const message of bad.errors) console.error(message); // ['Field "x" must be a number', 'Missing required field: "y"']}Hit a problem or have a question? Get in touch.