-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(required): create required and description param on string,numbe…
…r and required
- Loading branch information
1 parent
3be0cc0
commit e8275c5
Showing
13 changed files
with
98 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@brainylab/resolver-validators": minor | ||
--- | ||
|
||
create required and add param description on required,string,number |
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 |
---|---|---|
|
@@ -3,7 +3,7 @@ dist | |
coverage | ||
|
||
.DS_Store | ||
typebox/* | ||
./typebox/* | ||
index.cjs | ||
index.d.ts | ||
index.d.cts | ||
|
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,14 @@ | ||
import type { RVRequired, RVRequiredParams } from '@/types/required'; | ||
import type { RVSchema } from '@/types/schema'; | ||
|
||
export function required<T extends RVSchema>( | ||
schema: T, | ||
params?: RVRequiredParams, | ||
): RVRequired<T> { | ||
return { | ||
type: 'required', | ||
schema, | ||
params, | ||
required: true, | ||
} as never; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Type } from '@sinclair/typebox'; | ||
|
||
import type { RVRequiredParams } from '@/types/required'; | ||
import type { SchemaOptions, TSchema } from '@sinclair/typebox'; | ||
|
||
export function TBRequired( | ||
schema: TSchema, | ||
params?: RVRequiredParams, | ||
): TSchema { | ||
const typeBoxParams: SchemaOptions = {}; | ||
|
||
const keys: { [key in keyof RVRequiredParams]: string } = { | ||
description: 'description', | ||
}; | ||
|
||
if (params) { | ||
for (const key in keys) { | ||
const mappedKey = keys[ | ||
key as keyof typeof keys | ||
] as keyof RVRequiredParams; | ||
if (params[key as keyof RVRequiredParams] !== undefined) { | ||
typeBoxParams[mappedKey] = params[key as keyof RVRequiredParams]; | ||
} | ||
} | ||
} | ||
|
||
return Type.Required(schema as unknown as TSchema, typeBoxParams); | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ export type RVTypes = | |
| 'number' | ||
| 'object' | ||
| 'optional' | ||
| 'required' | ||
| 'string' | ||
| 'tuple'; |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export type RVParams = { | ||
min?: number; | ||
max?: number; | ||
description?: string; | ||
}; |
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,7 @@ | ||
import type { RVObject } from './object'; | ||
import type { RVSchema } from './schema'; | ||
|
||
export type RVRequiredParams = { description?: string }; | ||
|
||
export type RVRequired<T extends RVSchema> = | ||
T extends RVObject<infer U> ? RVObject<RVRequired<U>> : T; |
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