Hyperlinkv0.8.0-beta.28

Schema

Schema.isMaxPropertiesfunctioneffect/Schema.ts:8305
(
  maxProperties: number,
  annotations?: Annotations.Filter
): SchemaAST.Filter<object>

Validates that an object contains at most the specified number of properties. This includes both string and symbol keys when counting properties.

Details

JSON Schema:

This check corresponds to the maxProperties constraint in JSON Schema.

Arbitrary:

When generating test data with fast-check, this applies a node-local maxLength constraint. Object generators interpret it as the final number of own properties.

Object checks
Source effect/Schema.ts:830520 lines
export function isMaxProperties(maxProperties: number, annotations?: Annotations.Filter) {
  maxProperties = Math.max(0, Math.floor(maxProperties))
  return makeFilter<object>(
    (input) => Reflect.ownKeys(input).length <= maxProperties,
    {
      expected: `a value with at most ${maxProperties === 1 ? "1 entry" : `${maxProperties} entries`}`,
      meta: {
        _tag: "isMaxProperties",
        maxProperties
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      arbitrary: {
        constraint: {
          maxLength: maxProperties
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols