Skip to content

Commit

Permalink
Add new overload signature to pipe method #852
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian-hiller committed Nov 1, 2024
1 parent 1e8ddfd commit 2be7348
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ All notable changes to the library will be documented in this file.
- Add `graphemes`, `maxGraphemes`, `minGraphemes` and `notGraphemes` action (pull request #853)
- Add `words`, `maxWords`, `minWords` and `notWords` action
- Add `args` and `returns` action to transform functions (issue #243)
- Add new overload signature to `pipe` and `pipeAync` method to support unlimited pipe items of same input and output type (issue #852)
- Change types and implementation to support Standard Schema
- Change behaviour of `minValue` and `maxValue` for `NaN` (pull request #843)
- Change type and behaviour of `nullable`, `nullableAsync`, `nullish`, `nullishAsync`, `optional`, `optionalAsync`, `undefinedable` and `undefinedableAsync` for undefined default value (issue #878)
Expand Down
17 changes: 17 additions & 0 deletions library/src/methods/pipe/pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2639,6 +2639,23 @@ export function pipe<
]
>;

/**
* Adds a pipeline to a schema, that can validate and transform its input.
*
* @param schema The root schema.
* @param items The pipe items.
*
* @returns A schema with a pipeline.
*/
export function pipe<
const TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>,
const TItems extends PipeItem<
InferOutput<TSchema>,
InferOutput<TSchema>,
BaseIssue<unknown>
>[],
>(schema: TSchema, ...items: TItems): SchemaWithPipe<[TSchema, ...TItems]>;

export function pipe<
const TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>,
const TItems extends PipeItem<unknown, unknown, BaseIssue<unknown>>[],
Expand Down
22 changes: 22 additions & 0 deletions library/src/methods/pipe/pipeAsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3019,6 +3019,28 @@ export function pipeAsync<
]
>;

/**
* Adds a pipeline to a schema, that can validate and transform its input.
*
* @param schema The root schema.
* @param items The pipe items.
*
* @returns A schema with a pipeline.
*/
export function pipeAsync<
const TSchema extends
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
| BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>,
const TItems extends (
| PipeItem<InferOutput<TSchema>, InferOutput<TSchema>, BaseIssue<unknown>>
| PipeItemAsync<
InferOutput<TSchema>,
InferOutput<TSchema>,
BaseIssue<unknown>
>
)[],
>(schema: TSchema, ...items: TItems): SchemaWithPipeAsync<[TSchema, ...TItems]>;

export function pipeAsync<
const TSchema extends
| BaseSchema<unknown, unknown, BaseIssue<unknown>>
Expand Down

0 comments on commit 2be7348

Please sign in to comment.