Skip to content

Commit

Permalink
Merge b2455c7 into sapling-pr-archive-decs
Browse files Browse the repository at this point in the history
  • Loading branch information
decs authored Apr 6, 2024
2 parents 83093be + b2455c7 commit 382d82d
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 70 deletions.
9 changes: 9 additions & 0 deletions packages/all/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# @typeschema/all

## 0.13.8

### Patch Changes

- a7c09b6: feat: add support to fastest-validator
- Updated dependencies [a7c09b6]
- @typeschema/fastest-validator@0.1.0
- @typeschema/main@0.13.8

## 0.13.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/all/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"//": "This file is partially generated. Only some fields can be modified manually!",
"name": "@typeschema/all",
"//version": "This field is manually maintained.",
"version": "0.13.7",
"version": "0.13.8",
"//description": "This field is manually maintained.",
"description": "Universal adapter for schema validation",
"keywords": [
Expand Down
7 changes: 7 additions & 0 deletions packages/fastest-validator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# @typeschema/fastest-validator

## 0.1.0

### Minor Changes

- a7c09b6: feat: add support to fastest-validator
2 changes: 1 addition & 1 deletion packages/fastest-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"//": "This file is partially generated. Only some fields can be modified manually!",
"name": "@typeschema/fastest-validator",
"//version": "This field is manually maintained.",
"version": "0.0.0",
"version": "0.1.0",
"//description": "This field is manually maintained.",
"description": "Reusable adapter for fastest-validator schemas",
"keywords": [
Expand Down
8 changes: 8 additions & 0 deletions packages/main/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @typeschema/main

## 0.13.8

### Patch Changes

- a7c09b6: feat: add support to fastest-validator
- Updated dependencies [a7c09b6]
- @typeschema/fastest-validator@0.1.0

## 0.13.7

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/main/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"//": "This file is partially generated. Only some fields can be modified manually!",
"name": "@typeschema/main",
"//version": "This field is manually maintained.",
"version": "0.13.7",
"version": "0.13.8",
"//description": "This field is manually maintained.",
"description": "Universal adapter for schema validation",
"keywords": [
Expand Down
112 changes: 45 additions & 67 deletions packages/main/src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,31 @@ import type {Kind} from '@sinclair/typebox';
import type {IfDefined, SchemaFrom} from '@typeschema/core';
import type {CoreValidator} from 'suretype';

type IsTypeboxSchema<TSchema> = [IfDefined<typeof Kind>] extends [never]
? false
: TSchema extends {[Kind]: unknown}
? true
: false;
// prettier-ignore
type IsTypeboxSchema<TSchema> =
[IfDefined<typeof Kind>] extends [never] ? false
: TSchema extends {[Kind]: unknown} ? true
: false;
function isTypeboxSchema(
schema: SchemaFrom<AdapterResolver>,
): schema is SchemaFrom<AdapterResolvers['typebox']> {
return typeof schema === 'object' && Symbol.for('TypeBox.Kind') in schema;
}

type IsSuretypeSchema<TSchema> = [IfDefined<CoreValidator<unknown>>] extends [
never,
]
? false
: TSchema extends CoreValidator<unknown>
? true
: false;
// prettier-ignore
type IsSuretypeSchema<TSchema> =
[IfDefined<CoreValidator<unknown>>] extends [never] ? false
: TSchema extends CoreValidator<unknown> ? true
: false;
function isSuretypeSchema(
schema: SchemaFrom<AdapterResolver>,
): schema is SchemaFrom<AdapterResolvers['suretype']> {
return typeof schema === 'object' && '_annotations' in schema;
}

type IsClassValidatorSchema<TSchema> = TSchema extends new (
...args: unknown[]
) => object
? true
// prettier-ignore
type IsClassValidatorSchema<TSchema> =
TSchema extends new (...args: unknown[]) => object ? true
: false;
function isClassValidatorSchema(
schema: SchemaFrom<AdapterResolver>,
Expand All @@ -41,23 +38,17 @@ function isClassValidatorSchema(
);
}

type IsJSONSchema<TSchema> = TSchema extends {type: unknown}
? true
: TSchema extends {const: unknown}
? true
: TSchema extends {enum: unknown}
? true
: TSchema extends {anyOf: unknown}
? true
: TSchema extends {oneOf: unknown}
? true
: TSchema extends {allOf: unknown}
? true
: TSchema extends {not: unknown}
? true
: TSchema extends {if: unknown}
? true
: false;
// prettier-ignore
type IsJSONSchema<TSchema> =
TSchema extends {type: unknown} ? true
: TSchema extends {const: unknown} ? true
: TSchema extends {enum: unknown} ? true
: TSchema extends {anyOf: unknown} ? true
: TSchema extends {oneOf: unknown} ? true
: TSchema extends {allOf: unknown} ? true
: TSchema extends {not: unknown} ? true
: TSchema extends {if: unknown} ? true
: false;
function isJSONSchema(
schema: SchemaFrom<AdapterResolver>,
): schema is SchemaFrom<AdapterResolvers['json']> {
Expand All @@ -80,43 +71,30 @@ function notJSON<TSchema>(
return schema as any;
}

// prettier-ignore
export type Select<TSchema> =
// eslint-disable-next-line @typescript-eslint/ban-types
TSchema extends Function
? TSchema extends {assert: unknown}
? 'arktype'
: IsClassValidatorSchema<TSchema> extends true
? 'classValidator'
: 'function'
: IsTypeboxSchema<TSchema> extends true
? 'typebox'
: IsSuretypeSchema<TSchema> extends true
? 'suretype'
: TSchema extends {__isYupSchema__: unknown}
? 'yup'
: TSchema extends {_def: unknown}
? 'zod'
: TSchema extends {async: unknown}
? 'valibot'
: TSchema extends {refiner: unknown}
? 'superstruct'
: TSchema extends {_flags: unknown}
? 'joi'
: TSchema extends {encode: unknown}
? 'ioTs'
: TSchema extends {reflect: unknown}
? 'runtypes'
: TSchema extends {ast: unknown}
? 'effect'
: TSchema extends {kind: unknown}
? 'deepkit'
: TSchema extends {addValidator: unknown}
? 'ow'
: TSchema extends {toTerminals: unknown}
? 'valita'
: IsJSONSchema<TSchema> extends true
? 'json'
: 'fastestValidator';
? TSchema extends {assert: unknown} ? 'arktype'
: IsClassValidatorSchema<TSchema> extends true ? 'classValidator'
: 'function'
: TSchema extends object
? IsTypeboxSchema<TSchema> extends true ? 'typebox'
: IsSuretypeSchema<TSchema> extends true ? 'suretype'
: TSchema extends {__isYupSchema__: unknown} ? 'yup'
: TSchema extends {_def: unknown} ? 'zod'
: TSchema extends {async: unknown} ? 'valibot'
: TSchema extends {refiner: unknown} ? 'superstruct'
: TSchema extends {_flags: unknown} ? 'joi'
: TSchema extends {encode: unknown} ? 'ioTs'
: TSchema extends {reflect: unknown} ? 'runtypes'
: TSchema extends {ast: unknown} ? 'effect'
: TSchema extends {kind: unknown} ? 'deepkit'
: TSchema extends {addValidator: unknown} ? 'ow'
: TSchema extends {toTerminals: unknown} ? 'valita'
: IsJSONSchema<TSchema> extends true ? 'json'
: 'fastestValidator'
: never;

export const select: <
TMap extends {
Expand Down

0 comments on commit 382d82d

Please sign in to comment.