-
-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for date filtering (after and before) to Schema.Date. #3606
Add support for date filtering (after and before) to Schema.Date. #3606
Conversation
🦋 Changeset detectedLatest commit: cd43238 The changes in this PR will be included in the next version bump. This PR includes changesets to release 25 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- changeset: you can replace minor with patch
- naming convention:
lessThan<entity>
solessThanDate
,lessThanOrEqualToDate
, etc... - no need for a
jsonSchema
annotation - no need to add the type ids to the internal
filter.ts
file
i.e. in practice you can take inspiration from the same filters defined for Duration
effect/packages/schema/src/Schema.ts
Lines 5519 to 5637 in 7fdf9d9
/** | |
* @category type id | |
* @since 0.67.0 | |
*/ | |
export const LessThanDurationTypeId: unique symbol = Symbol.for("@effect/schema/TypeId/LessThanDuration") | |
/** | |
* @category Duration filters | |
* @since 0.67.0 | |
*/ | |
export const lessThanDuration = <A extends duration_.Duration>( | |
max: duration_.DurationInput, | |
annotations?: Annotations.Filter<A> | |
) => | |
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => | |
self.pipe( | |
filter((a) => duration_.lessThan(a, max), { | |
typeId: { id: LessThanDurationTypeId, annotation: { max } }, | |
description: `a Duration less than ${duration_.decode(max)}`, | |
...annotations | |
}) | |
) | |
/** | |
* @category type id | |
* @since 0.67.0 | |
*/ | |
export const LessThanOrEqualToDurationTypeId: unique symbol = Symbol.for( | |
"@effect/schema/TypeId/LessThanOrEqualToDuration" | |
) | |
/** | |
* @category Duration filters | |
* @since 0.67.0 | |
*/ | |
export const lessThanOrEqualToDuration = <A extends duration_.Duration>( | |
max: duration_.DurationInput, | |
annotations?: Annotations.Filter<A> | |
) => | |
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => | |
self.pipe( | |
filter((a) => duration_.lessThanOrEqualTo(a, max), { | |
typeId: { id: LessThanDurationTypeId, annotation: { max } }, | |
description: `a Duration less than or equal to ${duration_.decode(max)}`, | |
...annotations | |
}) | |
) | |
/** | |
* @category type id | |
* @since 0.67.0 | |
*/ | |
export const GreaterThanDurationTypeId: unique symbol = Symbol.for("@effect/schema/TypeId/GreaterThanDuration") | |
/** | |
* @category Duration filters | |
* @since 0.67.0 | |
*/ | |
export const greaterThanDuration = <A extends duration_.Duration>( | |
min: duration_.DurationInput, | |
annotations?: Annotations.Filter<A> | |
) => | |
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => | |
self.pipe( | |
filter((a) => duration_.greaterThan(a, min), { | |
typeId: { id: GreaterThanDurationTypeId, annotation: { min } }, | |
description: `a Duration greater than ${duration_.decode(min)}`, | |
...annotations | |
}) | |
) | |
/** | |
* @category type id | |
* @since 0.67.0 | |
*/ | |
export const GreaterThanOrEqualToDurationTypeId: unique symbol = Symbol.for( | |
"@effect/schema/TypeId/GreaterThanOrEqualToDuration" | |
) | |
/** | |
* @category Duration filters | |
* @since 0.67.0 | |
*/ | |
export const greaterThanOrEqualToDuration = <A extends duration_.Duration>( | |
min: duration_.DurationInput, | |
annotations?: Annotations.Filter<A> | |
) => | |
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => | |
self.pipe( | |
filter((a) => duration_.greaterThanOrEqualTo(a, min), { | |
typeId: { id: GreaterThanOrEqualToDurationTypeId, annotation: { min } }, | |
description: `a Duration greater than or equal to ${duration_.decode(min)}`, | |
...annotations | |
}) | |
) | |
/** | |
* @category type id | |
* @since 0.67.0 | |
*/ | |
export const BetweenDurationTypeId: unique symbol = Symbol.for("@effect/schema/TypeId/BetweenDuration") | |
/** | |
* @category Duration filters | |
* @since 0.67.0 | |
*/ | |
export const betweenDuration = <A extends duration_.Duration>( | |
minimum: duration_.DurationInput, | |
maximum: duration_.DurationInput, | |
annotations?: Annotations.Filter<A> | |
) => | |
<I, R>(self: Schema<A, I, R>): filter<Schema<A, I, R>> => | |
self.pipe( | |
filter((a) => duration_.between(a, { minimum, maximum }), { | |
typeId: { id: BetweenDurationTypeId, annotation: { maximum, minimum } }, | |
description: `a Duration between ${duration_.decode(minimum)} and ${duration_.decode(maximum)}`, | |
...annotations | |
}) | |
) |
4c69ae2
to
6a128f6
Compare
Add support for date filtering (after and before) to
Schema.Date
.New APIs include:
Schema.after
Schema.afterOrEqualTo
Schema.before
Schema.beforeOrEqualTo
Important note:
The "decoding" tests not working because I din't know how to fix them. They are commented out.