diff --git a/website/src/routes/api/(actions)/rawCheck/AddIssue/index.mdx b/website/src/routes/api/(actions)/rawCheck/AddIssue/index.mdx new file mode 100644 index 000000000..558ba9048 --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/AddIssue/index.mdx @@ -0,0 +1,21 @@ +--- +title: AddIssue +description: Add issue type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# AddIssue + +Add issue type. + +## Generics + +- `TInput` + +## Definition + +- `AddIssue` diff --git a/website/src/routes/api/(actions)/rawCheck/AddIssue/properties.ts b/website/src/routes/api/(actions)/rawCheck/AddIssue/properties.ts new file mode 100644 index 000000000..ee7c506b0 --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/AddIssue/properties.ts @@ -0,0 +1,31 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'any', + }, + AddIssue: { + type: { + type: 'function', + params: [ + { + name: 'info', + optional: true, + type: { + type: 'custom', + name: 'IssueInfo', + href: '../IssueInfo/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + }, + ], + return: 'void', + }, + }, +}; diff --git a/website/src/routes/api/(actions)/rawCheck/Context/index.mdx b/website/src/routes/api/(actions)/rawCheck/Context/index.mdx new file mode 100644 index 000000000..a7456cecc --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/Context/index.mdx @@ -0,0 +1,24 @@ +--- +title: Context +description: Context type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# Context + +Context type. + +## Generics + +- `TInput` + +## Definition + +- `Context` + - `dataset` + - `config` + - `addIssue` diff --git a/website/src/routes/api/(actions)/rawCheck/Context/properties.ts b/website/src/routes/api/(actions)/rawCheck/Context/properties.ts new file mode 100644 index 000000000..6eeeb0bec --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/Context/properties.ts @@ -0,0 +1,60 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'any', + }, + dataset: { + type: { + type: 'custom', + name: 'Dataset', + href: '../../Dataset/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'BaseIssue', + href: '../../BaseIssue/', + generics: ['unknown'], + }, + ], + }, + }, + config: { + type: { + type: 'custom', + name: 'Config', + href: '../../Config/', + generics: [ + { + type: 'custom', + name: 'RawCheckIssue', + href: '../../RawCheckIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + ], + }, + }, + addIssue: { + type: { + type: 'custom', + name: 'AddIssue', + href: '../AddIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(actions)/rawCheck/IssueInfo/index.mdx b/website/src/routes/api/(actions)/rawCheck/IssueInfo/index.mdx new file mode 100644 index 000000000..9e530a39b --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/IssueInfo/index.mdx @@ -0,0 +1,27 @@ +--- +title: IssueInfo +description: Issue info type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# IssueInfo + +Issue info type. + +## Generics + +- `TInput` + +## Definition + +- `IssueInfo` + - `label` + - `input` + - `expected` + - `received` + - `message` + - `path` diff --git a/website/src/routes/api/(actions)/rawCheck/IssueInfo/properties.ts b/website/src/routes/api/(actions)/rawCheck/IssueInfo/properties.ts new file mode 100644 index 000000000..ea255c581 --- /dev/null +++ b/website/src/routes/api/(actions)/rawCheck/IssueInfo/properties.ts @@ -0,0 +1,91 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'any', + }, + kind: { + type: { + type: 'string', + value: 'metadata', + }, + }, + label: { + type: { + type: 'union', + options: ['string', 'undefined'], + }, + }, + input: { + type: { + type: 'union', + options: ['unknown', 'undefined'], + }, + }, + expected: { + type: { + type: 'union', + options: ['string', 'undefined'], + }, + }, + received: { + type: { + type: 'union', + options: ['string', 'undefined'], + }, + }, + message: { + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'ErrorMessage', + href: '../../ErrorMessage/', + generics: [ + { + type: 'custom', + name: 'RawCheckIssue', + href: '../../RawCheckIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + ], + }, + 'undefined', + ], + }, + }, + path: { + type: { + type: 'union', + options: [ + { + type: 'tuple', + items: [ + { + type: 'custom', + name: 'IssuePathItem', + href: '../../IssuePathItem/', + }, + { + type: 'array', + item: { + type: 'custom', + name: 'IssuePathItem', + href: '../../IssuePathItem/', + }, + spread: true, + }, + ], + }, + 'undefined', + ], + }, + }, +}; diff --git a/website/src/routes/api/(actions)/rawCheck/properties.ts b/website/src/routes/api/(actions)/rawCheck/properties.ts index 55c6dd98e..3ba3188b5 100644 --- a/website/src/routes/api/(actions)/rawCheck/properties.ts +++ b/website/src/routes/api/(actions)/rawCheck/properties.ts @@ -12,129 +12,13 @@ export const properties: Record = { { name: 'context', type: { - type: 'object', - entries: [ + type: 'custom', + name: 'Context', + href: './Context/', + generics: [ { - key: 'dataset', - value: { - type: 'custom', - name: 'Dataset', - href: '../Dataset/', - generics: [ - { - type: 'custom', - name: 'TInput', - }, - { - type: 'custom', - name: 'BaseIssue', - generics: ['unknown'], - }, - ], - }, - }, - { - key: 'config', - value: { - type: 'custom', - name: 'Config', - href: '../Config/', - generics: [ - { - type: 'custom', - name: 'RawCheckIssue', - href: '../RawCheckIssue/', - generics: [ - { - type: 'custom', - name: 'TInput', - }, - ], - }, - ], - }, - }, - { - key: 'addIssue', - value: { - type: 'function', - params: [ - { - name: 'info', - type: { - type: 'object', - entries: [ - { - key: 'label', - optional: true, - value: 'string', - }, - { - key: 'input', - optional: true, - value: 'unknown', - }, - { - key: 'expected', - optional: true, - value: 'string', - }, - { - key: 'received', - optional: true, - value: 'string', - }, - { - key: 'message', - optional: true, - value: { - type: 'custom', - name: 'ErrorMessage', - href: '../ErrorMessage/', - generics: [ - { - type: 'custom', - name: 'RawCheckIssue', - href: '../RawCheckIssue/', - generics: [ - { - type: 'custom', - name: 'TInput', - }, - ], - }, - ], - }, - }, - { - key: 'path', - optional: true, - value: { - type: 'tuple', - items: [ - { - type: 'custom', - name: 'IssuePathItem', - href: '../IssuePathItem/', - }, - { - type: 'array', - spread: true, - item: { - type: 'custom', - name: 'IssuePathItem', - href: '../IssuePathItem/', - }, - }, - ], - }, - }, - ], - }, - }, - ], - return: 'void', - }, + type: 'custom', + name: 'TInput', }, ], }, diff --git a/website/src/routes/api/(async)/rawCheckAsync/index.mdx b/website/src/routes/api/(async)/rawCheckAsync/index.mdx index 6dc75cc1f..e78c293cf 100644 --- a/website/src/routes/api/(async)/rawCheckAsync/index.mdx +++ b/website/src/routes/api/(async)/rawCheckAsync/index.mdx @@ -1,11 +1,179 @@ --- title: rawCheckAsync +description: Creates a raw check validation action. source: /actions/rawCheck/rawCheckAsync.ts contributors: - EltonLobo07 - fabian-hiller --- +import { ApiList, Property } from '~/components'; +import { properties } from './properties'; + # rawCheckAsync -> 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/rawCheck/rawCheckAsync.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 raw check validation action. + +```ts +const Action = v.rawCheckAsync(action); +``` + +## Generics + +- `TInput` + +## Parameters + +- `action` + +### Explanation + +With `rawCheckAsync` you can freely validate the input with a custom `action` and add issues if necessary. + +## Returns + +- `Action` + +## Examples + +The following examples show how `rawCheckAsync` can be used. + +### Add users schema + +Object schema that ensures that only users not already in the group are included. + +> This `rawCheckAsync` validation action adds an issue for any invalid username and forwards it via `path` to the appropriate nested field. + +```ts +import { isAlreadyInGroup } from '~/api'; + +const AddUsersSchema = v.pipeAsync( + v.object({ + groupId: v.pipe(v.string(), v.uuid()), + usernames: v.array(v.pipe(v.string(), v.nonEmpty())), + }), + v.rawCheckAsync(async ({ dataset, addIssue }) => { + if (dataset.typed) { + await Promise.all( + dataset.value.usernames.map(async (username, index) => { + if (await isAlreadyInGroup(username, dataset.value.groupId)) { + addIssue({ + received: username, + message: 'The user is already in the group.', + path: [ + { + type: 'object', + origin: 'value', + input: dataset.value, + key: 'usernames', + value: dataset.value.usernames, + }, + { + type: 'array', + origin: 'value', + input: dataset.value.usernames, + key: index, + value: username, + }, + ], + }); + } + }) + ); + } + }) +); +``` + +## Related + +The following APIs can be combined with `rawCheckAsync`. + +### Schemas + + + +### Utils + + + +### Async + + diff --git a/website/src/routes/api/(async)/rawCheckAsync/properties.ts b/website/src/routes/api/(async)/rawCheckAsync/properties.ts new file mode 100644 index 000000000..470965212 --- /dev/null +++ b/website/src/routes/api/(async)/rawCheckAsync/properties.ts @@ -0,0 +1,48 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'any', + }, + action: { + type: { + type: 'function', + params: [ + { + name: 'context', + type: { + type: 'custom', + name: 'Context', + href: '../rawCheck/Context/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + }, + ], + return: { + type: 'custom', + name: 'MaybePromise', + href: '../MaybePromise/', + generics: ['void'], + }, + }, + }, + Action: { + type: { + type: 'custom', + name: 'RawCheckActionAsync', + href: '../RawCheckActionAsync/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/RawCheckActionAsync/index.mdx b/website/src/routes/api/(types)/RawCheckActionAsync/index.mdx new file mode 100644 index 000000000..c1f48ba92 --- /dev/null +++ b/website/src/routes/api/(types)/RawCheckActionAsync/index.mdx @@ -0,0 +1,24 @@ +--- +title: RawCheckActionAsync +description: Raw check action async type. +contributors: + - EltonLobo07 +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# RawCheckActionAsync + +Raw check action async type. + +## Generics + +- `TInput` + +## Definition + +- `RawCheckActionAsync` + - `type` + - `reference` + - `expects` diff --git a/website/src/routes/api/(types)/RawCheckActionAsync/properties.ts b/website/src/routes/api/(types)/RawCheckActionAsync/properties.ts new file mode 100644 index 000000000..55bdce616 --- /dev/null +++ b/website/src/routes/api/(types)/RawCheckActionAsync/properties.ts @@ -0,0 +1,54 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TInput: { + modifier: 'extends', + type: 'any', + }, + BaseValidationAsync: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseValidationAsync', + href: '../BaseValidationAsync/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'TInput', + }, + { + type: 'custom', + name: 'RawCheckIssue', + href: '../RawCheckIssue/', + generics: [ + { + type: 'custom', + name: 'TInput', + }, + ], + }, + ], + }, + }, + type: { + type: { + type: 'string', + value: 'raw_check', + }, + }, + reference: { + type: { + type: 'custom', + modifier: 'typeof', + name: 'rawCheckAsync', + href: '../rawCheckAsync/', + }, + }, + expects: { + type: 'null', + }, +}; diff --git a/website/src/routes/api/menu.md b/website/src/routes/api/menu.md index 520def226..7967cad6d 100644 --- a/website/src/routes/api/menu.md +++ b/website/src/routes/api/menu.md @@ -512,6 +512,7 @@ - [PromiseIssue](/api/PromiseIssue/) - [PromiseSchema](/api/PromiseSchema/) - [RawCheckAction](/api/RawCheckAction/) +- [RawCheckActionAsync](/api/RawCheckActionAsync/) - [RawCheckIssue](/api/RawCheckIssue/) - [RawTransformAction](/api/RawTransformAction/) - [RawTransformIssue](/api/RawTransformIssue/)