From 0b47fdfe449f42de89e0e88b61ae5140f629e5c4 Mon Sep 17 00:00:00 2001 From: Giulio Canti Date: Mon, 24 Jun 2024 14:52:54 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20the=200.67.22=20patch=20as=20it=20is?= =?UTF-8?q?=20causing=20issues=20with=20other=20array=20fil=E2=80=A6=20(#3?= =?UTF-8?q?074)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/stale-hairs-cheer.md | 5 +++++ packages/schema/dtslint/Schema.ts | 16 +++++++++++----- packages/schema/src/Schema.ts | 12 +++++------- 3 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 .changeset/stale-hairs-cheer.md diff --git a/.changeset/stale-hairs-cheer.md b/.changeset/stale-hairs-cheer.md new file mode 100644 index 0000000000..4d1adc87a1 --- /dev/null +++ b/.changeset/stale-hairs-cheer.md @@ -0,0 +1,5 @@ +--- +"@effect/schema": patch +--- + +Revert the 0.67.22 patch as it is causing issues with other array filters, closes #3073 diff --git a/packages/schema/dtslint/Schema.ts b/packages/schema/dtslint/Schema.ts index b0f6ecb096..9c1873151f 100644 --- a/packages/schema/dtslint/Schema.ts +++ b/packages/schema/dtslint/Schema.ts @@ -2473,11 +2473,17 @@ S.Struct({ a: S.requiredToOptional(aContext, S.String, { decode: Option.some, en // minItems // --------------------------------------------- -// $ExpectType Schema -S.asSchema(S.Array(S.String).pipe(S.minItems(1))) +// $ExpectType Schema +S.asSchema(S.Array(S.String).pipe(S.minItems(2))) + +// $ExpectType filter> +S.Array(S.String).pipe(S.minItems(2)) -// $ExpectType refine> -S.Array(S.String).pipe(S.minItems(1)) +// $ExpectType Schema +S.Array(S.String).pipe(S.minItems(2)).from // $ExpectType Schema -S.Array(S.String).pipe(S.minItems(1)).from +S.asSchema(S.Array(S.String).pipe(S.minItems(2), S.maxItems(3))) + +// $ExpectType filter> +S.Array(S.String).pipe(S.minItems(1), S.maxItems(2)) diff --git a/packages/schema/src/Schema.ts b/packages/schema/src/Schema.ts index 7ab22bc6d8..d379246f82 100644 --- a/packages/schema/src/Schema.ts +++ b/packages/schema/src/Schema.ts @@ -5426,11 +5426,9 @@ export type MinItemsTypeId = typeof MinItemsTypeId */ export const minItems = ( n: number, - annotations?: Annotations.Filter, ReadonlyArray> + annotations?: Annotations.Filter> ) => -( - self: Schema, I, R> -): refine, Schema, I, R>> => { +(self: Schema, I, R>): filter, I, R>> => { const minItems = Math.floor(n) if (minItems < 1) { throw new Error( @@ -5439,7 +5437,7 @@ export const minItems = ( } return self.pipe( filter( - (a): a is array_.NonEmptyReadonlyArray => a.length >= minItems, + (a) => a.length >= minItems, { typeId: MinItemsTypeId, description: `an array of at least ${minItems} items`, @@ -5473,7 +5471,7 @@ export const maxItems = ( ) => (self: Schema, I, R>): filter, I, R>> => self.pipe( - filter((a): a is ReadonlyArray => a.length <= n, { + filter((a) => a.length <= n, { typeId: MaxItemsTypeId, description: `an array of at most ${n} items`, jsonSchema: { maxItems: n }, @@ -5504,7 +5502,7 @@ export const itemsCount = ( ) => (self: Schema, I, R>): filter, I, R>> => self.pipe( - filter((a): a is ReadonlyArray => a.length === n, { + filter((a) => a.length === n, { typeId: ItemsCountTypeId, description: `an array of exactly ${n} item(s)`, jsonSchema: { minItems: n, maxItems: n },