Skip to content
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

Conversation

achaconm2001
Copy link

@achaconm2001 achaconm2001 commented Sep 13, 2024

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.

Copy link

changeset-bot bot commented Sep 13, 2024

🦋 Changeset detected

Latest commit: cd43238

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 25 packages
Name Type
@effect/schema Minor
@effect/cli Major
@effect/cluster-browser Major
@effect/cluster-node Major
@effect/cluster-workflow Major
@effect/cluster Major
@effect/experimental Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/rpc-http Major
@effect/rpc Major
@effect/sql Major
@effect/sql-d1 Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-node Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major

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

@achaconm2001 achaconm2001 marked this pull request as draft September 13, 2024 11:57
Copy link
Contributor

@gcanti gcanti left a 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> so lessThanDate, 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

/**
* @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
})
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants