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

Updated zod to schema comparison: added mention of Schema.URL #4346

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schema/comparisons.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ S.String.pipe(S.maxLength(5))
S.String.pipe(S.minLength(5))
S.String.pipe(S.length(5))
// S.string().email() // No equivalent
// S.string().url() // No equivalent
S.URL
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK S.URL is not equivalent, z.string().url() just validates a string:

import z from "zod"

console.log(typeof z.string().url().parse("https://example.com"))
// string

Copy link
Contributor Author

@nikelborm nikelborm Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schema.Date is also not an exact equivalent, but this fact didn't prevent it from being mentioned as an equivalent a few lines later:

schema/comparisons.md L286-L307
### Dates

Zod

```ts
const date = z.string().date()

date.parse("2020-01-01") // pass
date.parse("2020-1-1") // fail
date.parse("2020-01-32") // fail
```

Schema

```ts
import { Schema as S } from "effect"

S.decodeUnknownSync(S.Date)("2020-01-01") // pass
S.decodeUnknownSync(S.Date)("2020-1-1") // pass
S.decodeUnknownSync(S.Date)("2020-01-32") // fail
```
import z from 'zod';

console.log(typeof z.string().date().parse('2020-01-01'));
// string

console.log(typeof Schema.decodeUnknownSync(Schema.Date)('2020-01-01'));
// object (Date)

And I think that's fine that they're not exactly equivalent and still mentioned because there's a value in it. When I first saw that there's no equivalent of URL validation, I was really confused, spent time reimplementing Schema.URL, and only after I was done, I noticed it actually existed and I created absolutely the same thing.

I don't want this to happen to anybody else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it doesn't claim that they are equivalent, it shows what can be used in Schema when the input is a string. However, without proper description, that section is confusing and should be reorganized. Furthermore, since these docs were written, some things have changed (e.g., Schema.URL didn’t exist at the time). IMO, the entire document needs to be refactored

Copy link
Contributor Author

@nikelborm nikelborm Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed it claimed they were equivalent because it didn't claim otherwise. In cases where Effect had no equivalent, it was stated as:

### Times

No equivalent.

### IP addresses

No equivalent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's not your fault, the document needs to be restructured, it's currently confusing

// S.string().emoji() // No equivalent
S.UUID
// S.string().nanoid() // No equivalent
Expand Down
Loading