Skip to content

Apply Shape

Validates a value against an expected shape.

@lainstack/data/apply-shape · Data

Apply Shape checks that one existing value matches an expected shape, then passes the same value on unchanged. It does not build, convert or clean data. Its output type comes from expectedShape, so downstream references see typed paths under value.

Choose it to give a typed contract to data you did not author in this automation, for example the output of @lainstack/data/parse-json (which is untyped Data) or an external payload. Choose @lainstack/flow/set-value to build a new typed value from literals and references. Choose @lainstack/js/transform to reshape or compute values.

Traps:

  • The check is strict. It does not coerce: the text “2” fails a number field.
  • A missing required field and a null value are different failures. Null passes only when the shape marks the field nullable.
  • Extra record fields pass through by default and stay in the value. Set rejectUndeclaredFields to true to fail on them.
  • A mismatch fails the step with error value_shape_invalid and lists the issues, up to 16. There is no second output port to route on.
  • value is required. An unset value is invalid config.
Setting Key Type Details
Value (required) value Value
Expected shape (required) expectedShape Value
Reject extra fields rejectUndeclaredFields Yes or no Default false.