| 9344 | * @since 4.0.0 |
| 9345 | */ |
| 9346 | export function isPropertiesLengthBetween(minimum: number, maximum: number, annotations?: Annotations.Filter) { |
| 9347 | minimum = Math.max(0, Math.floor(minimum)) |
| 9348 | maximum = Math.max(0, Math.floor(maximum)) |
| 9349 | return makeFilter<object>( |
| 9350 | (input) => Reflect.ownKeys(input).length >= minimum && Reflect.ownKeys(input).length <= maximum, |
| 9351 | { |
| 9352 | expected: minimum === maximum |
| 9353 | ? `a value with exactly ${minimum === 1 ? "1 entry" : `${minimum} entries`}` |
| 9354 | : `a value with between ${minimum} and ${maximum} entries`, |
| 9355 | |
| 9356 | representation: { |
| 9357 | id: "effect/schema/isPropertiesLengthBetween", |
| 9358 | payload: { minimum, maximum } |
| 9359 | }, |
| 9360 | toJsonSchema: () => ({ minProperties: minimum, maxProperties: maximum }), |
| 9361 | toCode: () => ({ runtime: `Schema.isPropertiesLengthBetween(${minimum}, ${maximum})` }), |
| 9362 | [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true, |
| 9363 | arbitrary: { |
| 9364 | constraint: { |
| 9365 | minLength: minimum, |
| 9366 | maxLength: maximum |
| 9367 | } |
| 9368 | }, |
| 9369 | ...annotations |
| 9370 | } |
| 9371 | ) |
| 9372 | } |
| 9373 | |
| 9374 | /** |
| 9375 | * Reviver for persisted `isPropertiesLengthBetween` checks. |