-
-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add content to missing API references on website
- Loading branch information
1 parent
f4d2544
commit e72f2e4
Showing
11 changed files
with
1,262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,105 @@ | ||
--- | ||
title: argsAsync | ||
description: Creates a function arguments transformation action. | ||
source: /actions/args/argsAsync.ts | ||
contributors: | ||
- fabian-hiller | ||
--- | ||
|
||
import { ApiList, Property } from '~/components'; | ||
import { properties } from './properties'; | ||
|
||
# argsAsync | ||
|
||
> The content of this page is not yet ready. Until then, please use the [source code](https://github.com/fabian-hiller/valibot/blob/main/library/src/actions/args/argsAsync.ts) or take a look at [issue #287](https://github.com/fabian-hiller/valibot/issues/287) to help us extend the API reference. | ||
Creates a function arguments transformation action. | ||
|
||
```ts | ||
const Action = v.argsAsync<TInput, TSchema>(schema); | ||
``` | ||
|
||
## Generics | ||
|
||
- `TInput` <Property {...properties.TInput} /> | ||
- `TSchema` <Property {...properties.TSchema} /> | ||
|
||
## Parameters | ||
|
||
- `schema` <Property {...properties.schema} /> | ||
|
||
### Explanation | ||
|
||
With `argsAsync` you can force the arguments of a function to match the given `schema`. | ||
|
||
## Returns | ||
|
||
- `Action` <Property {...properties.Action} /> | ||
|
||
## Examples | ||
|
||
The following examples show how `argsAsync` can be used. | ||
|
||
### Product function schema | ||
|
||
Schema of a function that returns a product by its ID. | ||
|
||
```ts | ||
import { isValidProductId } from '~/api'; | ||
|
||
const ProductFunctionSchema = v.pipeAsync( | ||
v.function(), | ||
v.argsAsync( | ||
v.tupleAsync([v.pipeAsync(v.string(), v.checkAsync(isValidProductId))]) | ||
), | ||
v.returnsAsync( | ||
v.pipeAsync( | ||
v.promise(), | ||
v.awaitAsync(), | ||
v.object({ | ||
id: v.string(), | ||
name: v.string(), | ||
price: v.number(), | ||
}) | ||
) | ||
) | ||
); | ||
``` | ||
|
||
## Related | ||
|
||
The following APIs can be combined with `argsAsync`. | ||
|
||
### Schemas | ||
|
||
<ApiList | ||
items={[ | ||
'any', | ||
'custom', | ||
'looseTuple', | ||
'function', | ||
'strictTuple', | ||
'tuple', | ||
'tupleWithRest', | ||
]} | ||
/> | ||
|
||
### Methods | ||
|
||
<ApiList items={['pipe']} /> | ||
|
||
### Utils | ||
|
||
<ApiList items={['isOfKind', 'isOfType']} /> | ||
|
||
### Async | ||
|
||
<ApiList | ||
items={[ | ||
'customAsync', | ||
'looseTupleAsync', | ||
'pipeAsync', | ||
'returnsAsync', | ||
'strictTupleAsync', | ||
'tupleAsync', | ||
'tupleWithRestAsync', | ||
]} | ||
/> |
Oops, something went wrong.