From 0aa77fc2b36fef8f93d35b142a2501eba86f6a16 Mon Sep 17 00:00:00 2001 From: Pasi Eronen Date: Fri, 28 Apr 2017 20:56:46 +0300 Subject: [PATCH] joi: add support for array.unique(comparator) (#16200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an optional extended description… --- types/joi/index.d.ts | 3 ++- types/joi/joi-tests.ts | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/types/joi/index.d.ts b/types/joi/index.d.ts index c11bcb9daf..b1696bb7ad 100644 --- a/types/joi/index.d.ts +++ b/types/joi/index.d.ts @@ -567,7 +567,8 @@ export interface ArraySchema extends AnySchema { * Be aware that a deep equality is performed on elements of the array having a type of object, * a performance penalty is to be expected for this kind of operation. */ - unique(): ArraySchema; + unique(comparator?: (a: any, b: any) => boolean): ArraySchema; + unique(comparator?: string): ArraySchema; } export interface ObjectSchema extends AnySchema { diff --git a/types/joi/joi-tests.ts b/types/joi/joi-tests.ts index f35a124183..a58623ea06 100644 --- a/types/joi/joi-tests.ts +++ b/types/joi/joi-tests.ts @@ -261,6 +261,8 @@ arrSchema = arrSchema.min(num); arrSchema = arrSchema.max(num); arrSchema = arrSchema.length(num); arrSchema = arrSchema.unique(); +arrSchema = arrSchema.unique((a, b) => a.test === b.test); +arrSchema = arrSchema.unique('customer.id'); arrSchema = arrSchema.items(numSchema);