From 5a2cc308cb6cb8083f2da98df6f8596083fd88b2 Mon Sep 17 00:00:00 2001 From: Elton Lobo Date: Thu, 12 Dec 2024 01:07:26 +0530 Subject: [PATCH] add `transformAsync` & `TransformActionAsync` references --- .../api/(async)/transformAsync/index.mdx | 139 +++++++++++++++++- .../api/(async)/transformAsync/properties.ts | 53 +++++++ .../(types)/TransformActionAsync/index.mdx | 25 ++++ .../TransformActionAsync/properties.ts | 69 +++++++++ website/src/routes/api/menu.md | 1 + 5 files changed, 285 insertions(+), 2 deletions(-) create mode 100644 website/src/routes/api/(async)/transformAsync/properties.ts create mode 100644 website/src/routes/api/(types)/TransformActionAsync/index.mdx create mode 100644 website/src/routes/api/(types)/TransformActionAsync/properties.ts diff --git a/website/src/routes/api/(async)/transformAsync/index.mdx b/website/src/routes/api/(async)/transformAsync/index.mdx index a622a27d6..cc8efdc49 100644 --- a/website/src/routes/api/(async)/transformAsync/index.mdx +++ b/website/src/routes/api/(async)/transformAsync/index.mdx @@ -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(operation); +``` + +## Generics + +- `TInput` +- `TOutput` + +## Parameters + +- `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` + +## 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 + + + +### Utils + + + +### Async + + diff --git a/website/src/routes/api/(async)/transformAsync/properties.ts b/website/src/routes/api/(async)/transformAsync/properties.ts new file mode 100644 index 000000000..e8db8b95d --- /dev/null +++ b/website/src/routes/api/(async)/transformAsync/properties.ts @@ -0,0 +1,53 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + 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', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/TransformActionAsync/index.mdx b/website/src/routes/api/(types)/TransformActionAsync/index.mdx new file mode 100644 index 000000000..dc22a30b2 --- /dev/null +++ b/website/src/routes/api/(types)/TransformActionAsync/index.mdx @@ -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` +- `TOutput` + +## Definition + +- `TransformActionAsync` + - `type` + - `reference` + - `operation` diff --git a/website/src/routes/api/(types)/TransformActionAsync/properties.ts b/website/src/routes/api/(types)/TransformActionAsync/properties.ts new file mode 100644 index 000000000..050de07cc --- /dev/null +++ b/website/src/routes/api/(types)/TransformActionAsync/properties.ts @@ -0,0 +1,69 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + 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', + }, + ], + }, + }, + }, +}; diff --git a/website/src/routes/api/menu.md b/website/src/routes/api/menu.md index c2de16d74..05ce9620e 100644 --- a/website/src/routes/api/menu.md +++ b/website/src/routes/api/menu.md @@ -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/)