Skip to content

Commit

Permalink
Revert the 0.67.22 patch as it is causing issues with other array fil… (
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jun 24, 2024
1 parent a70705c commit 0b47fdf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-hairs-cheer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@effect/schema": patch
---

Revert the 0.67.22 patch as it is causing issues with other array filters, closes #3073
16 changes: 11 additions & 5 deletions packages/schema/dtslint/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2473,11 +2473,17 @@ S.Struct({ a: S.requiredToOptional(aContext, S.String, { decode: Option.some, en
// minItems
// ---------------------------------------------

// $ExpectType Schema<readonly [string, ...string[]], readonly string[], never>
S.asSchema(S.Array(S.String).pipe(S.minItems(1)))
// $ExpectType Schema<readonly string[], readonly string[], never>
S.asSchema(S.Array(S.String).pipe(S.minItems(2)))

// $ExpectType filter<Schema<readonly string[], readonly string[], never>>
S.Array(S.String).pipe(S.minItems(2))

// $ExpectType refine<readonly [string, ...string[]], Schema<readonly string[], readonly string[], never>>
S.Array(S.String).pipe(S.minItems(1))
// $ExpectType Schema<readonly string[], readonly string[], never>
S.Array(S.String).pipe(S.minItems(2)).from

// $ExpectType Schema<readonly string[], readonly string[], never>
S.Array(S.String).pipe(S.minItems(1)).from
S.asSchema(S.Array(S.String).pipe(S.minItems(2), S.maxItems(3)))

// $ExpectType filter<Schema<readonly string[], readonly string[], never>>
S.Array(S.String).pipe(S.minItems(1), S.maxItems(2))
12 changes: 5 additions & 7 deletions packages/schema/src/Schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5426,11 +5426,9 @@ export type MinItemsTypeId = typeof MinItemsTypeId
*/
export const minItems = <A>(
n: number,
annotations?: Annotations.Filter<array_.NonEmptyReadonlyArray<A>, ReadonlyArray<A>>
annotations?: Annotations.Filter<ReadonlyArray<A>>
) =>
<I, R>(
self: Schema<ReadonlyArray<A>, I, R>
): refine<array_.NonEmptyReadonlyArray<A>, Schema<ReadonlyArray<A>, I, R>> => {
<I, R>(self: Schema<ReadonlyArray<A>, I, R>): filter<Schema<ReadonlyArray<A>, I, R>> => {
const minItems = Math.floor(n)
if (minItems < 1) {
throw new Error(
Expand All @@ -5439,7 +5437,7 @@ export const minItems = <A>(
}
return self.pipe(
filter(
(a): a is array_.NonEmptyReadonlyArray<A> => a.length >= minItems,
(a) => a.length >= minItems,
{
typeId: MinItemsTypeId,
description: `an array of at least ${minItems} items`,
Expand Down Expand Up @@ -5473,7 +5471,7 @@ export const maxItems = <A>(
) =>
<I, R>(self: Schema<ReadonlyArray<A>, I, R>): filter<Schema<ReadonlyArray<A>, I, R>> =>
self.pipe(
filter((a): a is ReadonlyArray<A> => a.length <= n, {
filter((a) => a.length <= n, {
typeId: MaxItemsTypeId,
description: `an array of at most ${n} items`,
jsonSchema: { maxItems: n },
Expand Down Expand Up @@ -5504,7 +5502,7 @@ export const itemsCount = <A>(
) =>
<I, R>(self: Schema<ReadonlyArray<A>, I, R>): filter<Schema<ReadonlyArray<A>, I, R>> =>
self.pipe(
filter((a): a is ReadonlyArray<A> => a.length === n, {
filter((a) => a.length === n, {
typeId: ItemsCountTypeId,
description: `an array of exactly ${n} item(s)`,
jsonSchema: { minItems: n, maxItems: n },
Expand Down

0 comments on commit 0b47fdf

Please sign in to comment.