Hyperlinkv0.8.0-beta.28

Schema

Schema.isMaxSizefunctioneffect/Schema.ts:8178
(maxSize: number, annotations?: Annotations.Filter): SchemaAST.Filter<{
  readonly size: number
}>

Validates that a value has at most the specified size. Works with values that have a size property, such as Set or Map.

Details

JSON Schema:

This check does not have a direct JSON Schema equivalent, as it applies to values with a size property rather than standard JSON Schema types.

Arbitrary:

When generating test data with fast-check, this applies a node-local maxLength constraint. Generators for values with a final .size, such as sets and maps, interpret it as final cardinality.

Size checks
Source effect/Schema.ts:817820 lines
export function isMaxSize(maxSize: number, annotations?: Annotations.Filter) {
  maxSize = Math.max(0, Math.floor(maxSize))
  return makeFilter<{ readonly size: number }>(
    (input) => input.size <= maxSize,
    {
      expected: `a value with a size of at most ${maxSize}`,
      meta: {
        _tag: "isMaxSize",
        maxSize
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      arbitrary: {
        constraint: {
          maxLength: maxSize
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols