-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(package): small refactoring + tests coverage improvement
- Loading branch information
Showing
14 changed files
with
227 additions
and
105 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import type { Parser } from "../types/parser.js"; | ||
import type { Validator } from "../types/validator.js"; | ||
import { validate } from "../util/validation.js"; | ||
|
||
export async function fromObject<$Parser extends Parser>({ | ||
export async function fromObject<$Validator extends Validator>({ | ||
data, | ||
schema, | ||
}: { | ||
data: unknown; | ||
schema: $Parser; | ||
schema: $Validator; | ||
}) { | ||
return validate(data, schema); | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from "../index.js"; | ||
export * from "./parser.js"; | ||
export * from "./validator.js"; |
This file was deleted.
Oops, something went wrong.
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,52 @@ | ||
// KUDOS to trpc for the inspiration | ||
|
||
export type ValidatorZod<TI, TPI> = { | ||
_input: TI; | ||
_output: TPI; | ||
}; | ||
|
||
export type ValidatorValibot<TI, TPI> = { | ||
types?: { | ||
input: TI; | ||
output: TPI; | ||
}; | ||
}; | ||
|
||
export type ValidatorMyZod<TI> = { | ||
parse: (input: any) => TI; | ||
}; | ||
|
||
export type ValidatorSuperstruct<TI> = { | ||
create: (input: unknown) => TI; | ||
}; | ||
|
||
export type ValidatorCustomValidator<TI> = (input: unknown) => Promise<TI> | TI; | ||
|
||
export type ValidatorYup<TI> = { | ||
validateSync: (input: unknown) => TI; | ||
}; | ||
|
||
export type ValidatorWithoutInput<TI> = | ||
| ValidatorCustomValidator<TI> | ||
| ValidatorMyZod<TI> | ||
| ValidatorSuperstruct<TI> | ||
| ValidatorYup<TI>; | ||
|
||
export type ValidatorWithInputOutput<TI, TPI> = ValidatorZod<TI, TPI> | ValidatorValibot<TI, TPI>; | ||
|
||
export type Validator = ValidatorWithInputOutput<any, any> | ValidatorWithoutInput<any>; | ||
|
||
export type inferValidator<$Validator extends Validator> = $Validator extends ValidatorWithInputOutput< | ||
infer $TIn, | ||
infer $TOut | ||
> | ||
? { | ||
in: $TIn; | ||
out: $TOut; | ||
} | ||
: $Validator extends ValidatorWithoutInput<infer $InOut> | ||
? { | ||
in: $InOut; | ||
out: $InOut; | ||
} | ||
: never; |
Oops, something went wrong.