| 9281 | * @since 4.0.0 |
| 9282 | */ |
| 9283 | export function isMaxProperties(maxProperties: number, annotations?: Annotations.Filter) { |
| 9284 | maxProperties = Math.max(0, Math.floor(maxProperties)) |
| 9285 | return makeFilter<object>( |
| 9286 | (input) => Reflect.ownKeys(input).length <= maxProperties, |
| 9287 | { |
| 9288 | expected: `a value with at most ${maxProperties === 1 ? "1 entry" : `${maxProperties} entries`}`, |
| 9289 | representation: { |
| 9290 | id: "effect/schema/isMaxProperties", |
| 9291 | payload: { maxProperties } |
| 9292 | }, |
| 9293 | toJsonSchema: () => ({ maxProperties }), |
| 9294 | toCode: () => ({ runtime: `Schema.isMaxProperties(${maxProperties})` }), |
| 9295 | [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true, |
| 9296 | arbitrary: { |
| 9297 | constraint: { |
| 9298 | maxLength: maxProperties |
| 9299 | } |
| 9300 | }, |
| 9301 | ...annotations |
| 9302 | } |
| 9303 | ) |
| 9304 | } |
| 9305 | |
| 9306 | /** |
| 9307 | * Reviver for persisted `isMaxProperties` checks. |