Skip to content

Commit

Permalink
wow
Browse files Browse the repository at this point in the history
  • Loading branch information
morgante committed May 23, 2024
1 parent cc10133 commit 6920c4b
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions .grit/patterns/valibot_v03.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pattern vb_renames() {
}
}
pattern vb_pipe_schema_args($new_schema_args, $piped_args) {
pattern vb_pipe_schema_args($schema, $new_schema_args, $piped_args) {
or {
[$maybe_pipe] where $other_args = [],
[$one_arg, $maybe_pipe] where $other_args = [$one_arg],
Expand All @@ -52,11 +52,11 @@ pattern vb_pipe($v) {
or {
`$v.$schema($schema_args)` where {
$schema <: vb_schema(),
$schema_args <: vb_pipe_schema_args($new_schema_args, $piped_args)
$schema_args <: vb_pipe_schema_args($schema, $new_schema_args, $piped_args)
} => `$v.pipe($v.$schema($new_schema_args), $piped_args)`,
`$schema($schema_args)` where {
$schema <: vb_schema(),
$schema_args <: vb_pipe_schema_args($new_schema_args, $piped_args),
$schema_args <: vb_pipe_schema_args($schema, $new_schema_args, $piped_args),
add_import(`pipe`, `'valibot'`)
} => `pipe($schema($new_schema_args), $piped_args)`
}
Expand Down Expand Up @@ -126,6 +126,25 @@ After:
const Schema = v.pipe(v.map(v.number(),v.pipe(v.string(), v.url(), v.endsWith('@example.com'))), v.maxSize(10));
```

## Union without pipe

```js
const Schema = v.object({
email: v.string([v.email(), v.endsWith('@gmail.com')]),
password: v.string([v.minLength(8)]),
other: v.union([v.string([v.decimal()]), v.number()]),
});
```

```js
const Schema = v.object({
email: v.pipe(v.string(), v.email(), v.endsWith('@gmail.com')),
password: v.pipe(v.string(), v.minLength(8)),
other: v.union([v.pipe(v.string(), v.decimal()), v.number()]),
});
```


## Nested pipe with union

Union arguments are not a pipe.
Expand Down

0 comments on commit 6920c4b

Please sign in to comment.