(value: A)
| 8484 | * for constructive uniqueness using Effect equality. |
| 8485 | * |
| 8486 | * @category validation |
| 8487 | * @since 4.0.0 |
| 8488 | */ |
| 8489 | export function isUnique<T>(annotations?: Annotations.Filter) { |
| 8490 | return makeFilter<ReadonlyArray<T>>( |
| 8491 | (input) => Arr.dedupe(input).length === input.length, |
| 8492 | { |
| 8493 | expected: "an array with unique items", |
| 8494 | representation: { |
| 8495 | id: "effect/schema/isUnique", |
| 8496 | payload: null |
| 8497 | }, |
| 8498 | toJsonSchema: () => ({ uniqueItems: true }), |
| 8499 | toCode: () => ({ runtime: "Schema.isUnique()" }), |
| 8500 | arbitraryConstraint: { |
| 8501 | uniqueBy: identity |
| 8502 | }, |
| 8503 | ...annotations |
| 8504 | } |
| 8505 | ) |
| 8506 | } |
| 8507 | /** |
| 8508 | * Validates that all first elements in an array of key-value tuples are unique according to Effect equality. |
| 8509 | * |
| 8510 | * **Details** |
| 8511 | * |
| 8512 | * Arbitrary: |
| 8513 | * During arbitrary generation, this projects each entry to its key for constructive uniqueness. |
| 8514 | * |
| 8515 | * JSON Schema: |
| 8516 | * JSON Schema has no equivalent constraint, so this check is omitted from generated documents. |
| 8517 | * |
| 8518 | * @see {@link isUnique} for validating uniqueness of complete array elements |
| 8519 | * @category validation |
| 8520 | * @since 4.0.0 |
| 8521 | */ |
| 8522 | export function isUniqueKey<Key, Value>(annotations?: Annotations.Filter) { |
| 8523 | return makeFilter<ReadonlyArray<readonly [Key, Value]>>( |
| 8524 | (input) => Arr.dedupe(input.map(([key]) => key)).length === input.length, |
| 8525 | { |
| 8526 | expected: "an array with unique keys", |
| 8527 | representation: { |
| 8528 | id: "effect/schema/isUniqueKey", |
| 8529 | payload: null |
| 8530 | }, |
| 8531 | toCode: () => ({ runtime: "Schema.isUniqueKey()" }), |
| 8532 | arbitraryConstraint: { |
| 8533 | uniqueBy: (entry: readonly [Key, Value]) => entry[0] |
| 8534 | }, |
| 8535 | ...annotations |
| 8536 | } |
| 8537 | ) |
| 8538 | } |
| 8539 | /** |
| 8540 | * Type-level representation of {@link NonEmptyString}. |
| 8541 | * |
| 8542 | * @category models |
| 8543 | * @since 3.10.0 |
no test coverage detected
searching dependent graphs…