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 transformAsync & TransformActionAsync references #974

Merged
Merged
Show file tree
Hide file tree
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
139 changes: 137 additions & 2 deletions website/src/routes/api/(async)/transformAsync/index.mdx
Original file line number Diff line number Diff line change
@@ -1,10 +1,145 @@
---
title: transformAsync
source: /methods/transform/transformAsync.ts
description: Creates a custom transformation action.
source: /actions/transform/transformAsync.ts
contributors:
- fabian-hiller
- santoshyadavdev
- EltonLobo07
---

import { Link } from '@builder.io/qwik-city';
import { ApiList, Property } from '~/components';
import { properties } from './properties';

# transformAsync

> 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/methods/transform/transformAsync.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 custom transformation action.

```ts
const Action = v.transformAsync<TInput, TOutput>(operation);
```

## Generics

- `TInput` <Property {...properties.TInput} />
- `TOutput` <Property {...properties.TOutput} />

## Parameters

- `operation` <Property {...properties.operation} />

### Explanation

`transformAsync` can be used to freely transform the input. The `operation` parameter is a function that takes the input and returns the transformed output.

## Returns

- `Action` <Property {...properties.Action} />

## Examples

The following examples show how `transformAsync` can be used.

### Blob to string

Schema that transforms a blob to its string value.

```ts
const StringSchema = v.pipeAsync(
v.blob(),
v.transformAsync((value) => value.text())
);
```

## Related

The following APIs can be combined with `transformAsync`.

### Schemas

<ApiList
items={[
'any',
'array',
'bigint',
'blob',
'boolean',
'custom',
'date',
'enum',
'file',
'function',
'instance',
'intersect',
'lazy',
'literal',
'looseObject',
'looseTuple',
'map',
'nan',
'never',
'nonNullable',
'nonNullish',
'nonOptional',
'null',
'nullable',
'nullish',
'number',
'object',
'objectWithRest',
'optional',
'picklist',
'promise',
'record',
'set',
'strictObject',
'strictTuple',
'string',
'symbol',
'tuple',
'tupleWithRest',
'undefined',
'undefinedable',
'union',
'unknown',
'variant',
'void',
]}
/>

### Utils

<ApiList items={['isOfKind', 'isOfType']} />

### Async

<ApiList
items={[
'arrayAsync',
'customAsync',
'intersectAsync',
'lazyAsync',
'looseObjectAsync',
'looseTupleAsync',
'mapAsync',
'nonNullableAsync',
'nonNullishAsync',
'nonOptionalAsync',
'nullableAsync',
'nullishAsync',
'objectAsync',
'objectWithRestAsync',
'optionalAsync',
'pipeAsync',
'recordAsync',
'setAsync',
'strictObjectAsync',
'strictTupleAsync',
'tupleAsync',
'tupleWithRestAsync',
'undefinedableAsync',
'unionAsync',
'variantAsync',
]}
/>
53 changes: 53 additions & 0 deletions website/src/routes/api/(async)/transformAsync/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type { PropertyProps } from '~/components';

export const properties: Record<string, PropertyProps> = {
TInput: {
modifier: 'extends',
type: 'any',
},
TOutput: {
modifier: 'extends',
type: 'any',
},
operation: {
type: {
type: 'function',
params: [
{
name: 'input',
type: {
type: 'custom',
name: 'TInput',
},
},
],
return: {
type: 'custom',
name: 'Promise',
generics: [
{
type: 'custom',
name: 'TOutput',
},
],
},
},
},
Action: {
type: {
type: 'custom',
name: 'TransformActionAsync',
href: '../TransformActionAsync/',
generics: [
{
type: 'custom',
name: 'TInput',
},
{
type: 'custom',
name: 'TOutput',
},
],
},
},
};
25 changes: 25 additions & 0 deletions website/src/routes/api/(types)/TransformActionAsync/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: TransformActionAsync
description: Transform action async type.
contributors:
- EltonLobo07
---

import { Property } from '~/components';
import { properties } from './properties';

# TransformActionAsync

Transform action async type.

## Generics

- `TInput` <Property {...properties.TInput} />
- `TOutput` <Property {...properties.TOutput} />

## Definition

- `TransformActionAsync` <Property {...properties.BaseTransformationAsync} />
- `type` <Property {...properties.type} />
- `reference` <Property {...properties.reference} />
- `operation` <Property {...properties.operation} />
69 changes: 69 additions & 0 deletions website/src/routes/api/(types)/TransformActionAsync/properties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import type { PropertyProps } from '~/components';

export const properties: Record<string, PropertyProps> = {
TInput: {
modifier: 'extends',
type: 'any',
},
TOutput: {
modifier: 'extends',
type: 'any',
},
BaseTransformationAsync: {
modifier: 'extends',
type: {
type: 'custom',
name: 'BaseTransformationAsync',
href: '../BaseTransformationAsync/',
generics: [
{
type: 'custom',
name: 'TInput',
},
{
type: 'custom',
name: 'TOutput',
},
'never',
],
},
},
type: {
type: {
type: 'string',
value: 'transform',
},
},
reference: {
type: {
type: 'custom',
modifier: 'typeof',
name: 'transformAsync',
href: '../transformAsync/',
},
},
operation: {
type: {
type: 'function',
params: [
{
name: 'input',
type: {
type: 'custom',
name: 'TInput',
},
},
],
return: {
type: 'custom',
name: 'Promise',
generics: [
{
type: 'custom',
name: 'TOutput',
},
],
},
},
},
};
1 change: 1 addition & 0 deletions website/src/routes/api/menu.md
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@
- [ToMinValueAction](/api/ToMinValueAction/)
- [ToUpperCaseAction](/api/ToUpperCaseAction/)
- [TransformAction](/api/TransformAction/)
- [TransformActionAsync](/api/TransformActionAsync/)
- [TrimAction](/api/TrimAction/)
- [TrimEndAction](/api/TrimEndAction/)
- [TrimStartAction](/api/TrimStartAction/)
Expand Down
Loading