-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(annotatee+raw): added annotate() and the raw validator
- Loading branch information
Showing
23 changed files
with
385 additions
and
92 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
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { BaseValidator } from "./validators/base/validator" | ||
|
||
export interface Annotations | ||
{ | ||
name?: string; | ||
title?: string; | ||
description?: string; | ||
examples?: Array< string >; | ||
} | ||
|
||
export type TopLevelAnnotations = | ||
Omit< Annotations, 'name' > & | ||
Required< Pick< Annotations, 'name' > >; | ||
|
||
export class AnnotationsHolder | ||
{ | ||
constructor( public options: Annotations ) | ||
{ } | ||
} | ||
|
||
type AnnotatedValidator< T extends BaseValidator< unknown, any > > = | ||
T & { _annotations: AnnotationsHolder }; | ||
|
||
export function annotateValidator< T extends BaseValidator< unknown > >( | ||
validator: T, | ||
annotations: AnnotationsHolder | ||
): T | ||
{ | ||
( validator as AnnotatedValidator< T > )._annotations = annotations; | ||
return validator; | ||
} | ||
|
||
export function getAnnotations< T extends BaseValidator< unknown > >( | ||
validator: T | ||
): Annotations | undefined | ||
{ | ||
return ( validator as AnnotatedValidator< T > )._annotations?.options; | ||
} |
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
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
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
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
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
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
Oops, something went wrong.