diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index 8b9a7aeb4..4ef5bbda8 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -4,8 +4,15 @@ All notable changes to the library will be documented in this file. ## vX.X.X (Month DD, YYYY) +- Add `Default` and `DefaultAsync` type and refactor codebase +- Add `Fallback` and `FallbackAsync` type and refactor codebase +- Add `isOfType` type guard util to check the type of an object +- Refactor `getDefaults` and `getDefaultsAsync` method (pull request #259) +- Refactor `getFallbacks` and `getFallbacksAsync` method (pull request #259) +- Change type definitions from `type` to `interface` (pull request #259) - Remove deprecated properties of `safeParse` and `safeParseAsync` method - Fix `NestedPath` type of `flatten` for async schemas (issue #456) +- Fix implementation of `DefaultValue` type for transformed values ## v0.29.0 (February 19, 2024) diff --git a/library/src/methods/fallback/fallback.ts b/library/src/methods/fallback/fallback.ts index 6b1572ef7..e875a665b 100644 --- a/library/src/methods/fallback/fallback.ts +++ b/library/src/methods/fallback/fallback.ts @@ -3,16 +3,19 @@ import { schemaResult } from '../../utils/index.ts'; import { getFallback } from '../getFallback/index.ts'; import type { FallbackInfo } from './types.ts'; -// TODO: Should we create a Fallback and Default type to simplify the generics? +/** + * Fallback type. + */ +export type Fallback = + | Output + | ((info?: FallbackInfo) => Output); /** * Schema with fallback type. */ export type SchemaWithFallback< TSchema extends BaseSchema = BaseSchema, - TFallback extends - | Output - | ((info?: FallbackInfo) => Output) = Output, + TFallback extends Fallback = Fallback, > = TSchema & { /** * The fallback value. @@ -30,8 +33,7 @@ export type SchemaWithFallback< */ export function fallback< TSchema extends BaseSchema, - const TFallback extends // TODO: Should we also allow `undefined` - Output | ((info?: FallbackInfo) => Output), + const TFallback extends Fallback, // TODO: Should we also allow `undefined` >( schema: TSchema, fallback: TFallback diff --git a/library/src/methods/fallback/fallbackAsync.ts b/library/src/methods/fallback/fallbackAsync.ts index 51e68b5e7..2ef288258 100644 --- a/library/src/methods/fallback/fallbackAsync.ts +++ b/library/src/methods/fallback/fallbackAsync.ts @@ -3,16 +3,19 @@ import { schemaResult } from '../../utils/index.ts'; import { getFallbackAsync } from '../getFallback/index.ts'; import type { FallbackInfo } from './types.ts'; +/** + * Fallback async type. + */ +export type FallbackAsync = + | Output + | ((info?: FallbackInfo) => Output | Promise>); + /** * Schema with fallback async type. */ export type SchemaWithFallbackAsync< TSchema extends BaseSchemaAsync = BaseSchemaAsync, - TFallback extends - | Output - | (( - info?: FallbackInfo - ) => Output | Promise>) = Output, + TFallback extends FallbackAsync = FallbackAsync, > = TSchema & { /** * The fallback value. @@ -30,9 +33,7 @@ export type SchemaWithFallbackAsync< */ export function fallbackAsync< TSchema extends BaseSchemaAsync, - const TFallback extends - | Output - | ((info?: FallbackInfo) => Output | Promise>), + const TFallback extends FallbackAsync, >( schema: TSchema, fallback: TFallback diff --git a/library/src/methods/getDefault/getDefault.ts b/library/src/methods/getDefault/getDefault.ts index 2713acf47..14ccf4fee 100644 --- a/library/src/methods/getDefault/getDefault.ts +++ b/library/src/methods/getDefault/getDefault.ts @@ -1,16 +1,18 @@ -import type { BaseSchema, Output } from '../../types/index.ts'; +import type { BaseSchema, Default } from '../../types/index.ts'; import type { DefaultValue } from './types.ts'; /** * Schema with maybe default type. */ -export type SchemaWithMaybeDefault = - TSchema & { - /** - * The optional default value. - */ - default?: Output | (() => Output | undefined); - }; +export type SchemaWithMaybeDefault< + TSchema extends BaseSchema = BaseSchema, + TDefault extends Default = Default, +> = TSchema & { + /** + * The optional default value. + */ + default?: TDefault; +}; /** * Returns the default value of the schema. diff --git a/library/src/methods/getDefault/getDefaultAsync.ts b/library/src/methods/getDefault/getDefaultAsync.ts index 8e2235871..19ba6d2d8 100644 --- a/library/src/methods/getDefault/getDefaultAsync.ts +++ b/library/src/methods/getDefault/getDefaultAsync.ts @@ -1,4 +1,4 @@ -import type { BaseSchemaAsync, Output } from '../../types/index.ts'; +import type { BaseSchemaAsync, DefaultAsync } from '../../types/index.ts'; import type { SchemaWithMaybeDefault } from './getDefault.ts'; import type { DefaultValue } from './types.ts'; @@ -7,16 +7,12 @@ import type { DefaultValue } from './types.ts'; */ export type SchemaWithMaybeDefaultAsync< TSchema extends BaseSchemaAsync = BaseSchemaAsync, + TDefault extends DefaultAsync = DefaultAsync, > = TSchema & { /** * The optional default value. */ - default?: - | Output - | (() => - | Output - | Promise | undefined> - | undefined); + default?: TDefault; }; /** diff --git a/library/src/methods/getDefault/types.ts b/library/src/methods/getDefault/types.ts index 996b55bf6..c92e828f9 100644 --- a/library/src/methods/getDefault/types.ts +++ b/library/src/methods/getDefault/types.ts @@ -1,4 +1,4 @@ -import type { Output } from '../../types/index.ts'; +import type { Input } from '../../types/index.ts'; import type { SchemaWithMaybeDefault } from './getDefault.ts'; import type { SchemaWithMaybeDefaultAsync } from './getDefaultAsync.ts'; @@ -7,10 +7,10 @@ import type { SchemaWithMaybeDefaultAsync } from './getDefaultAsync.ts'; */ export type DefaultValue< TSchema extends SchemaWithMaybeDefault | SchemaWithMaybeDefaultAsync, -> = TSchema['default'] extends Output | undefined +> = TSchema['default'] extends Input | undefined ? TSchema['default'] - : TSchema['default'] extends () => Output | undefined + : TSchema['default'] extends () => Input | undefined ? ReturnType - : TSchema['default'] extends () => Promise | undefined> + : TSchema['default'] extends () => Promise | undefined> ? Awaited> : undefined; diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index 0fd262f16..e4adb95ce 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -4,7 +4,8 @@ import type { TupleItems, TupleSchema, } from '../../schemas/index.ts'; -import type { BaseSchema } from '../../types/index.ts'; +import type { BaseSchema } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefault, type SchemaWithMaybeDefault, @@ -26,32 +27,27 @@ export function getDefaults< TSchema extends SchemaWithMaybeDefault< BaseSchema | ObjectSchema | TupleSchema >, ->(schema: TSchema): DefaultValues { - // Create defaults variable - let defaults: any; - - // If schema contains a default function, set its default value +>(schema: TSchema): DefaultValues | undefined { + // If schema has default, return its value if (schema.default !== undefined) { - defaults = getDefault(schema); + return getDefault(schema); + } - // Otherwise, check if schema is of kind object or tuple - } else if ('type' in schema) { - // If it is an object schema, set object with default value of each entry - if (schema.type === 'object') { - defaults = {}; - for (const key in schema.entries) { - defaults[key] = getDefaults(schema.entries[key]); - } + // If it is an object schema, return default of each entry + if (isOfType('object', schema)) { + return Object.fromEntries( + Object.entries(schema.entries).map(([key, value]) => [ + key, + getDefaults(value), + ]) + ) as DefaultValues; + } - // If it is a tuple schema, set array with default value of each item - } else if (schema.type === 'tuple') { - defaults = []; - for (let key = 0; key < schema.items.length; key++) { - defaults.push(getDefaults(schema.items[key])); - } - } + // If it is a tuple schema, return default of each item + if (isOfType('tuple', schema)) { + return schema.items.map(getDefaults) as DefaultValues; } - // Return default values - return defaults; + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index 9f4deb4b4..057ae6eb3 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -8,7 +8,8 @@ import type { TupleSchema, TupleSchemaAsync, } from '../../schemas/index.ts'; -import type { BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; +import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefaultAsync, type SchemaWithMaybeDefault, @@ -39,32 +40,31 @@ export async function getDefaultsAsync< | ObjectSchemaAsync | TupleSchemaAsync >, ->(schema: TSchema): Promise> { - // Create defaults variable - let defaults: any; - - // If schema contains a default function, set its default value +>(schema: TSchema): Promise | undefined> { + // If schema contains default, return its value if (schema.default !== undefined) { - defaults = await getDefaultAsync(schema); + return getDefaultAsync(schema); + } - // Otherwise, check if schema is of kind object or tuple - } else if ('type' in schema) { - // If it is an object schema, set object with default value of each entry - if (schema.type === 'object') { - defaults = {}; - for (const key in schema.entries) { - defaults[key] = await getDefaultsAsync(schema.entries[key]); - } + // If it is an object schema, return default of each entry + if (isOfType('object', schema)) { + return Object.fromEntries( + await Promise.all( + Object.entries(schema.entries).map(async ([key, value]) => [ + key, + await getDefaultsAsync(value), + ]) + ) + ) as DefaultValues; + } - // If it is a tuple schema, set array with default value of each item - } else if (schema.type === 'tuple') { - defaults = []; - for (let key = 0; key < schema.items.length; key++) { - defaults.push(await getDefaultsAsync(schema.items[key])); - } - } + // If it is a tuple schema, return default of each item + if (isOfType('tuple', schema)) { + return Promise.all( + schema.items.map(getDefaultsAsync) + ) as DefaultValues; } - // Return default values - return defaults; + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getFallback/getFallback.ts b/library/src/methods/getFallback/getFallback.ts index 5106258c6..d81fa894d 100644 --- a/library/src/methods/getFallback/getFallback.ts +++ b/library/src/methods/getFallback/getFallback.ts @@ -1,17 +1,20 @@ -import type { BaseSchema, Output } from '../../types/index.ts'; +import type { BaseSchema } from '../../types/index.ts'; +import type { Fallback } from '../fallback/index.ts'; import type { FallbackInfo } from '../fallback/types.ts'; import type { FallbackValue } from './types.ts'; /** * Schema with maybe fallback type. */ -export type SchemaWithMaybeFallback = - TSchema & { - /** - * The optional fallback value. - */ - fallback?: Output | ((info?: FallbackInfo) => Output); - }; +export type SchemaWithMaybeFallback< + TSchema extends BaseSchema = BaseSchema, + TFallback extends Fallback = Fallback, +> = TSchema & { + /** + * The optional fallback value. + */ + fallback?: TFallback; +}; /** * Returns the fallback value of the schema. diff --git a/library/src/methods/getFallback/getFallbackAsync.ts b/library/src/methods/getFallback/getFallbackAsync.ts index 278d9f3a0..832a696da 100644 --- a/library/src/methods/getFallback/getFallbackAsync.ts +++ b/library/src/methods/getFallback/getFallbackAsync.ts @@ -1,4 +1,5 @@ -import type { BaseSchemaAsync, Output } from '../../types/index.ts'; +import type { BaseSchemaAsync } from '../../types/index.ts'; +import type { FallbackAsync } from '../fallback/index.ts'; import type { FallbackInfo } from '../fallback/types.ts'; import type { SchemaWithMaybeFallback } from './getFallback.ts'; import type { FallbackValue } from './types.ts'; @@ -8,13 +9,12 @@ import type { FallbackValue } from './types.ts'; */ export type SchemaWithMaybeFallbackAsync< TSchema extends BaseSchemaAsync = BaseSchemaAsync, + TFallback extends FallbackAsync = FallbackAsync, > = TSchema & { /** * The optional fallback value. */ - fallback?: - | Output - | ((info?: FallbackInfo) => Output | Promise>); + fallback?: TFallback; }; /** diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index dde2ed6ed..e36133ba0 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -4,7 +4,8 @@ import type { TupleItems, TupleSchema, } from '../../schemas/index.ts'; -import type { BaseSchema } from '../../types/index.ts'; +import type { BaseSchema } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallback, type SchemaWithMaybeFallback, @@ -26,32 +27,27 @@ export function getFallbacks< TSchema extends SchemaWithMaybeFallback< BaseSchema | ObjectSchema | TupleSchema >, ->(schema: TSchema): FallbackValues { - // Create fallbacks variable - let fallbacks: any; - - // If schema has a fallback, set its value +>(schema: TSchema): FallbackValues | undefined { + // If schema has fallback, return its value if (schema.fallback !== undefined) { - fallbacks = getFallback(schema); + return getFallback(schema); + } - // Otherwise, check if schema is of kind object or tuple - } else if ('type' in schema) { - // If it is an object schema, set object with fallback value of each entry - if (schema.type === 'object') { - fallbacks = {}; - for (const key in schema.entries) { - fallbacks[key] = getFallbacks(schema.entries[key]); - } + // If it is an object schema, return fallback of each entry + if (isOfType('object', schema)) { + return Object.fromEntries( + Object.entries(schema.entries).map(([key, value]) => [ + key, + getFallbacks(value), + ]) + ) as FallbackValues; + } - // If it is a tuple schema, set array with fallback value of each item - } else if (schema.type === 'tuple') { - fallbacks = []; - for (let key = 0; key < schema.items.length; key++) { - fallbacks.push(getFallbacks(schema.items[key])); - } - } + // If it is a tuple schema, return fallback of each item + if (isOfType('tuple', schema)) { + return schema.items.map(getFallbacks) as FallbackValues; } - // Return fallback values - return fallbacks; + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 47619c840..de70ee79b 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -8,7 +8,8 @@ import type { TupleSchema, TupleSchemaAsync, } from '../../schemas/index.ts'; -import type { BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; +import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallbackAsync, type SchemaWithMaybeFallback, @@ -39,32 +40,31 @@ export async function getFallbacksAsync< | ObjectSchemaAsync | TupleSchemaAsync >, ->(schema: TSchema): Promise> { - // Create fallbacks variable - let fallbacks: any; - - // If schema has a fallback, set its value +>(schema: TSchema): Promise | undefined> { + // If schema has fallback, return its value if (schema.fallback !== undefined) { - fallbacks = await getFallbackAsync(schema); + return getFallbackAsync(schema); + } - // Otherwise, check if schema is of kind object or tuple - } else if ('type' in schema) { - if (schema.type === 'object') { - fallbacks = {}; + // If it is an object schema, return fallback of each entry + if (isOfType('object', schema)) { + return Object.fromEntries( await Promise.all( - Object.entries(schema.entries).map(async ([key, schema]) => { - fallbacks[key] = await getFallbacksAsync(schema); - }) - ); + Object.entries(schema.entries).map(async ([key, value]) => [ + key, + await getFallbacksAsync(value), + ]) + ) + ) as FallbackValues; + } - // If it is a tuple schema, set array with fallback value of each item - } else if (schema.type === 'tuple') { - fallbacks = await Promise.all( - schema.items.map((schema) => getFallbacksAsync(schema)) - ); - } + // If it is a tuple schema, return fallback of each item + if (isOfType('tuple', schema)) { + return Promise.all( + schema.items.map(getFallbacksAsync) + ) as FallbackValues; } - // Return fallback values - return fallbacks; + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/safeParse/safeParse.test.ts b/library/src/methods/safeParse/safeParse.test.ts index 4806a863e..720bacfe4 100644 --- a/library/src/methods/safeParse/safeParse.test.ts +++ b/library/src/methods/safeParse/safeParse.test.ts @@ -1,5 +1,4 @@ import { describe, expect, test } from 'vitest'; -import { ValiError } from '../../error/index.ts'; import { object, string } from '../../schemas/index.ts'; import type { SchemaIssues } from '../../types/index.ts'; import { minLength } from '../../validations/index.ts'; diff --git a/library/src/methods/safeParse/safeParseAsync.test.ts b/library/src/methods/safeParse/safeParseAsync.test.ts index 33cd0c2c2..722e8f40f 100644 --- a/library/src/methods/safeParse/safeParseAsync.test.ts +++ b/library/src/methods/safeParse/safeParseAsync.test.ts @@ -1,5 +1,4 @@ import { describe, expect, test } from 'vitest'; -import { ValiError } from '../../error/index.ts'; import { object, string } from '../../schemas/index.ts'; import type { SchemaIssues } from '../../types/index.ts'; import { minLength } from '../../validations/index.ts'; diff --git a/library/src/schemas/any/any.ts b/library/src/schemas/any/any.ts index 40083f9f3..0e6b3f6a9 100644 --- a/library/src/schemas/any/any.ts +++ b/library/src/schemas/any/any.ts @@ -4,7 +4,7 @@ import { pipeResult } from '../../utils/index.ts'; /** * Any schema type. */ -export type AnySchema = BaseSchema & { +export interface AnySchema extends BaseSchema { /** * The schema type. */ @@ -13,7 +13,7 @@ export type AnySchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates an any schema. diff --git a/library/src/schemas/any/anyAsync.ts b/library/src/schemas/any/anyAsync.ts index b3defed28..757c090e6 100644 --- a/library/src/schemas/any/anyAsync.ts +++ b/library/src/schemas/any/anyAsync.ts @@ -4,7 +4,8 @@ import { pipeResultAsync } from '../../utils/index.ts'; /** * Any schema type. */ -export type AnySchemaAsync = BaseSchemaAsync & { +export interface AnySchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -13,7 +14,7 @@ export type AnySchemaAsync = BaseSchemaAsync & { * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async any schema. diff --git a/library/src/schemas/array/array.ts b/library/src/schemas/array/array.ts index d58aa6c2a..709ef0e47 100644 --- a/library/src/schemas/array/array.ts +++ b/library/src/schemas/array/array.ts @@ -17,10 +17,10 @@ import type { ArrayPathItem } from './types.ts'; /** * Array schema type. */ -export type ArraySchema< +export interface ArraySchema< TItem extends BaseSchema, TOutput = Output[], -> = BaseSchema[], TOutput> & { +> extends BaseSchema[], TOutput> { /** * The schema type. */ @@ -37,7 +37,7 @@ export type ArraySchema< * The validation and transformation pipeline. */ pipe: Pipe[]> | undefined; -}; +} /** * Creates a array schema. diff --git a/library/src/schemas/array/arrayAsync.ts b/library/src/schemas/array/arrayAsync.ts index 026593ef7..19b57f87a 100644 --- a/library/src/schemas/array/arrayAsync.ts +++ b/library/src/schemas/array/arrayAsync.ts @@ -18,10 +18,10 @@ import type { ArrayPathItem } from './types.ts'; /** * Array schema async type. */ -export type ArraySchemaAsync< +export interface ArraySchemaAsync< TItem extends BaseSchema | BaseSchemaAsync, TOutput = Output[], -> = BaseSchemaAsync[], TOutput> & { +> extends BaseSchemaAsync[], TOutput> { /** * The schema type. */ @@ -38,7 +38,7 @@ export type ArraySchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync[]> | undefined; -}; +} /** * Creates an async array schema. diff --git a/library/src/schemas/bigint/bigint.ts b/library/src/schemas/bigint/bigint.ts index f1ace3102..e8d4f026e 100644 --- a/library/src/schemas/bigint/bigint.ts +++ b/library/src/schemas/bigint/bigint.ts @@ -4,7 +4,8 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Bigint schema type. */ -export type BigintSchema = BaseSchema & { +export interface BigintSchema + extends BaseSchema { /** * The schema type. */ @@ -17,7 +18,7 @@ export type BigintSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a bigint schema. diff --git a/library/src/schemas/bigint/bigintAsync.ts b/library/src/schemas/bigint/bigintAsync.ts index 0bae4c2a5..f0f7f5c06 100644 --- a/library/src/schemas/bigint/bigintAsync.ts +++ b/library/src/schemas/bigint/bigintAsync.ts @@ -12,10 +12,8 @@ import { /** * Bigint schema async type. */ -export type BigintSchemaAsync = BaseSchemaAsync< - bigint, - TOutput -> & { +export interface BigintSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -28,7 +26,7 @@ export type BigintSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async bigint schema. diff --git a/library/src/schemas/blob/blob.ts b/library/src/schemas/blob/blob.ts index 27c5d2e74..b1e53f58d 100644 --- a/library/src/schemas/blob/blob.ts +++ b/library/src/schemas/blob/blob.ts @@ -4,7 +4,7 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Blob schema type. */ -export type BlobSchema = BaseSchema & { +export interface BlobSchema extends BaseSchema { /** * The schema type. */ @@ -17,7 +17,7 @@ export type BlobSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a blob schema. diff --git a/library/src/schemas/blob/blobAsync.ts b/library/src/schemas/blob/blobAsync.ts index 869b7e1b9..d29a81e9f 100644 --- a/library/src/schemas/blob/blobAsync.ts +++ b/library/src/schemas/blob/blobAsync.ts @@ -12,7 +12,8 @@ import { /** * Blob schema async type. */ -export type BlobSchemaAsync = BaseSchemaAsync & { +export interface BlobSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -25,7 +26,7 @@ export type BlobSchemaAsync = BaseSchemaAsync & { * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async blob schema. diff --git a/library/src/schemas/boolean/boolean.ts b/library/src/schemas/boolean/boolean.ts index 260b6a13b..2409c8219 100644 --- a/library/src/schemas/boolean/boolean.ts +++ b/library/src/schemas/boolean/boolean.ts @@ -4,7 +4,8 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Boolean schema type. */ -export type BooleanSchema = BaseSchema & { +export interface BooleanSchema + extends BaseSchema { /** * The schema type. */ @@ -17,7 +18,7 @@ export type BooleanSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a boolean schema. diff --git a/library/src/schemas/boolean/booleanAsync.ts b/library/src/schemas/boolean/booleanAsync.ts index bd8c2a6b4..9756c22b1 100644 --- a/library/src/schemas/boolean/booleanAsync.ts +++ b/library/src/schemas/boolean/booleanAsync.ts @@ -12,10 +12,8 @@ import { /** * Boolean schema async type. */ -export type BooleanSchemaAsync = BaseSchemaAsync< - boolean, - TOutput -> & { +export interface BooleanSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -28,7 +26,7 @@ export type BooleanSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async boolean schema. diff --git a/library/src/schemas/date/date.ts b/library/src/schemas/date/date.ts index 79a754347..483519475 100644 --- a/library/src/schemas/date/date.ts +++ b/library/src/schemas/date/date.ts @@ -4,7 +4,7 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Date schema type. */ -export type DateSchema = BaseSchema & { +export interface DateSchema extends BaseSchema { /** * The schema type. */ @@ -17,7 +17,7 @@ export type DateSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a date schema. diff --git a/library/src/schemas/date/dateAsync.ts b/library/src/schemas/date/dateAsync.ts index 878015e67..e8ae587dc 100644 --- a/library/src/schemas/date/dateAsync.ts +++ b/library/src/schemas/date/dateAsync.ts @@ -12,7 +12,8 @@ import { /** * Date schema async type. */ -export type DateSchemaAsync = BaseSchemaAsync & { +export interface DateSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -25,7 +26,7 @@ export type DateSchemaAsync = BaseSchemaAsync & { * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async date schema. diff --git a/library/src/schemas/enum/enum.ts b/library/src/schemas/enum/enum.ts index 34a83ff6a..74f9db47d 100644 --- a/library/src/schemas/enum/enum.ts +++ b/library/src/schemas/enum/enum.ts @@ -12,10 +12,8 @@ export type Enum = { /** * Native enum schema type. */ -export type EnumSchema< - TEnum extends Enum, - TOutput = TEnum[keyof TEnum], -> = BaseSchema & { +export interface EnumSchema + extends BaseSchema { /** * The schema type. */ @@ -28,7 +26,7 @@ export type EnumSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an enum schema. diff --git a/library/src/schemas/enum/enumAsync.ts b/library/src/schemas/enum/enumAsync.ts index 03c8ae4d3..f2dc8accd 100644 --- a/library/src/schemas/enum/enumAsync.ts +++ b/library/src/schemas/enum/enumAsync.ts @@ -5,10 +5,10 @@ import type { Enum } from './enum.ts'; /** * Native enum schema async type. */ -export type EnumSchemaAsync< +export interface EnumSchemaAsync< TEnum extends Enum, TOutput = TEnum[keyof TEnum], -> = BaseSchemaAsync & { +> extends BaseSchemaAsync { /** * The schema type. */ @@ -21,7 +21,7 @@ export type EnumSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async enum schema. diff --git a/library/src/schemas/instance/instance.ts b/library/src/schemas/instance/instance.ts index 99677ff6e..56ff50717 100644 --- a/library/src/schemas/instance/instance.ts +++ b/library/src/schemas/instance/instance.ts @@ -5,10 +5,10 @@ import type { Class } from './types.ts'; /** * Instance schema type. */ -export type InstanceSchema< +export interface InstanceSchema< TClass extends Class, TOutput = InstanceType, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -25,7 +25,7 @@ export type InstanceSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates an instance schema. diff --git a/library/src/schemas/instance/instanceAsync.ts b/library/src/schemas/instance/instanceAsync.ts index 16abbd596..1f201ddba 100644 --- a/library/src/schemas/instance/instanceAsync.ts +++ b/library/src/schemas/instance/instanceAsync.ts @@ -13,10 +13,10 @@ import type { Class } from './types.ts'; /** * Instance schema type. */ -export type InstanceSchemaAsync< +export interface InstanceSchemaAsync< TClass extends Class, TOutput = InstanceType, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -33,7 +33,7 @@ export type InstanceSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async instance schema. diff --git a/library/src/schemas/intersect/index.ts b/library/src/schemas/intersect/index.ts index 367ce66ab..bce493c98 100644 --- a/library/src/schemas/intersect/index.ts +++ b/library/src/schemas/intersect/index.ts @@ -1,2 +1,2 @@ export * from './intersect.ts'; -export * from './intersect.ts'; +export * from './intersectAsync.ts'; diff --git a/library/src/schemas/intersect/intersect.ts b/library/src/schemas/intersect/intersect.ts index b7401a984..6271b4179 100644 --- a/library/src/schemas/intersect/intersect.ts +++ b/library/src/schemas/intersect/intersect.ts @@ -24,10 +24,10 @@ export type IntersectOptions = MaybeReadonly< /** * Intersect schema type. */ -export type IntersectSchema< +export interface IntersectSchema< TOptions extends IntersectOptions, TOutput = IntersectOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -44,7 +44,7 @@ export type IntersectSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates an intersect schema. diff --git a/library/src/schemas/intersect/intersectAsync.ts b/library/src/schemas/intersect/intersectAsync.ts index 7399176e0..8f13c04ce 100644 --- a/library/src/schemas/intersect/intersectAsync.ts +++ b/library/src/schemas/intersect/intersectAsync.ts @@ -29,10 +29,10 @@ export type IntersectOptionsAsync = MaybeReadonly< /** * Intersect schema async type. */ -export type IntersectSchemaAsync< +export interface IntersectSchemaAsync< TOptions extends IntersectOptionsAsync, TOutput = IntersectOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -49,7 +49,7 @@ export type IntersectSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async intersect schema. diff --git a/library/src/schemas/lazy/lazy.ts b/library/src/schemas/lazy/lazy.ts index bc5472358..b212a084b 100644 --- a/library/src/schemas/lazy/lazy.ts +++ b/library/src/schemas/lazy/lazy.ts @@ -3,10 +3,10 @@ import type { BaseSchema, Input, Output } from '../../types/index.ts'; /** * Lazy schema type. */ -export type LazySchema< +export interface LazySchema< TGetter extends (input: unknown) => BaseSchema, TOutput = Output>, -> = BaseSchema>, TOutput> & { +> extends BaseSchema>, TOutput> { /** * The schema type. */ @@ -15,7 +15,7 @@ export type LazySchema< * The schema getter. */ getter: TGetter; -}; +} /** * Creates a lazy schema. diff --git a/library/src/schemas/lazy/lazyAsync.ts b/library/src/schemas/lazy/lazyAsync.ts index 876a9dfc9..77d4231c5 100644 --- a/library/src/schemas/lazy/lazyAsync.ts +++ b/library/src/schemas/lazy/lazyAsync.ts @@ -9,12 +9,12 @@ import type { /** * Lazy schema async type. */ -export type LazySchemaAsync< +export interface LazySchemaAsync< TGetter extends ( input: unknown ) => MaybePromise, TOutput = Output>>, -> = BaseSchemaAsync>>, TOutput> & { +> extends BaseSchemaAsync>>, TOutput> { /** * The schema type. */ @@ -23,7 +23,7 @@ export type LazySchemaAsync< * The schema getter. */ getter: TGetter; -}; +} /** * Creates an async lazy schema. diff --git a/library/src/schemas/literal/literal.ts b/library/src/schemas/literal/literal.ts index 1e4cebfd4..ef2721d9b 100644 --- a/library/src/schemas/literal/literal.ts +++ b/library/src/schemas/literal/literal.ts @@ -5,10 +5,8 @@ import type { Literal } from './types.ts'; /** * Literal schema type. */ -export type LiteralSchema< - TLiteral extends Literal, - TOutput = TLiteral, -> = BaseSchema & { +export interface LiteralSchema + extends BaseSchema { /** * The schema type. */ @@ -21,7 +19,7 @@ export type LiteralSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a literal schema. diff --git a/library/src/schemas/literal/literalAsync.ts b/library/src/schemas/literal/literalAsync.ts index d5c53231c..5daa5b6b9 100644 --- a/library/src/schemas/literal/literalAsync.ts +++ b/library/src/schemas/literal/literalAsync.ts @@ -5,10 +5,10 @@ import type { Literal } from './types.ts'; /** * Literal schema async type. */ -export type LiteralSchemaAsync< +export interface LiteralSchemaAsync< TLiteral extends Literal, TOutput = TLiteral, -> = BaseSchemaAsync & { +> extends BaseSchemaAsync { /** * The schema type. */ @@ -21,7 +21,7 @@ export type LiteralSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async literal schema. diff --git a/library/src/schemas/map/map.ts b/library/src/schemas/map/map.ts index 1566a8928..3b32bfb0a 100644 --- a/library/src/schemas/map/map.ts +++ b/library/src/schemas/map/map.ts @@ -16,11 +16,11 @@ import type { MapInput, MapOutput, MapPathItem } from './types.ts'; /** * Map schema type. */ -export type MapSchema< +export interface MapSchema< TKey extends BaseSchema, TValue extends BaseSchema, TOutput = MapOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -41,7 +41,7 @@ export type MapSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a map schema. diff --git a/library/src/schemas/map/mapAsync.ts b/library/src/schemas/map/mapAsync.ts index ba4510277..bc3ded5d0 100644 --- a/library/src/schemas/map/mapAsync.ts +++ b/library/src/schemas/map/mapAsync.ts @@ -17,11 +17,11 @@ import type { MapInput, MapOutput, MapPathItem } from './types.ts'; /** * Map schema async type. */ -export type MapSchemaAsync< +export interface MapSchemaAsync< TKey extends BaseSchema | BaseSchemaAsync, TValue extends BaseSchema | BaseSchemaAsync, TOutput = MapOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -42,7 +42,7 @@ export type MapSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async map schema. diff --git a/library/src/schemas/nan/nan.ts b/library/src/schemas/nan/nan.ts index ba4c26ae4..b81cfc442 100644 --- a/library/src/schemas/nan/nan.ts +++ b/library/src/schemas/nan/nan.ts @@ -4,7 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * NaN schema type. */ -export type NanSchema = BaseSchema & { +export interface NanSchema + extends BaseSchema { /** * The schema type. */ @@ -13,7 +14,7 @@ export type NanSchema = BaseSchema & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a NaN schema. diff --git a/library/src/schemas/nan/nanAsync.ts b/library/src/schemas/nan/nanAsync.ts index 3e6f72679..8932407de 100644 --- a/library/src/schemas/nan/nanAsync.ts +++ b/library/src/schemas/nan/nanAsync.ts @@ -4,10 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * NaN schema async type. */ -export type NanSchemaAsync = BaseSchemaAsync< - number, - TOutput -> & { +export interface NanSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -16,7 +14,7 @@ export type NanSchemaAsync = BaseSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async NaN schema. diff --git a/library/src/schemas/never/never.ts b/library/src/schemas/never/never.ts index bfcaf3af4..0cd27fbf8 100644 --- a/library/src/schemas/never/never.ts +++ b/library/src/schemas/never/never.ts @@ -4,7 +4,7 @@ import { schemaIssue } from '../../utils/index.ts'; /** * Never schema type. */ -export type NeverSchema = BaseSchema & { +export interface NeverSchema extends BaseSchema { /** * The schema type. */ @@ -13,7 +13,7 @@ export type NeverSchema = BaseSchema & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a never schema. diff --git a/library/src/schemas/never/neverAsync.ts b/library/src/schemas/never/neverAsync.ts index 09ccba905..33ddcda30 100644 --- a/library/src/schemas/never/neverAsync.ts +++ b/library/src/schemas/never/neverAsync.ts @@ -4,7 +4,7 @@ import { schemaIssue } from '../../utils/index.ts'; /** * Never schema async type. */ -export type NeverSchemaAsync = BaseSchemaAsync & { +export interface NeverSchemaAsync extends BaseSchemaAsync { /** * The schema type. */ @@ -13,7 +13,7 @@ export type NeverSchemaAsync = BaseSchemaAsync & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async never schema. diff --git a/library/src/schemas/nonNullable/nonNullable.ts b/library/src/schemas/nonNullable/nonNullable.ts index c1d0b224d..1e20d01cc 100644 --- a/library/src/schemas/nonNullable/nonNullable.ts +++ b/library/src/schemas/nonNullable/nonNullable.ts @@ -5,10 +5,10 @@ import type { NonNullableInput, NonNullableOutput } from './types.ts'; /** * Non nullable schema type. */ -export type NonNullableSchema< +export interface NonNullableSchema< TWrapped extends BaseSchema, TOutput = NonNullableOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -21,7 +21,7 @@ export type NonNullableSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a non nullable schema. diff --git a/library/src/schemas/nonNullable/nonNullableAsync.ts b/library/src/schemas/nonNullable/nonNullableAsync.ts index daa431401..be7f04853 100644 --- a/library/src/schemas/nonNullable/nonNullableAsync.ts +++ b/library/src/schemas/nonNullable/nonNullableAsync.ts @@ -9,10 +9,10 @@ import type { NonNullableInput, NonNullableOutput } from './types.ts'; /** * Non nullable schema async type. */ -export type NonNullableSchemaAsync< +export interface NonNullableSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonNullableOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -25,7 +25,7 @@ export type NonNullableSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async non nullable schema. diff --git a/library/src/schemas/nonNullish/nonNullish.ts b/library/src/schemas/nonNullish/nonNullish.ts index 653b3eccf..4005a5b2f 100644 --- a/library/src/schemas/nonNullish/nonNullish.ts +++ b/library/src/schemas/nonNullish/nonNullish.ts @@ -5,10 +5,10 @@ import type { NonNullishInput, NonNullishOutput } from './types.ts'; /** * Non nullish schema type. */ -export type NonNullishSchema< +export interface NonNullishSchema< TWrapped extends BaseSchema, TOutput = NonNullishOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -21,7 +21,7 @@ export type NonNullishSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a non nullish schema. diff --git a/library/src/schemas/nonNullish/nonNullishAsync.ts b/library/src/schemas/nonNullish/nonNullishAsync.ts index 866de857b..5b43078a9 100644 --- a/library/src/schemas/nonNullish/nonNullishAsync.ts +++ b/library/src/schemas/nonNullish/nonNullishAsync.ts @@ -9,10 +9,10 @@ import type { NonNullishInput, NonNullishOutput } from './types.ts'; /** * Non nullish schema async type. */ -export type NonNullishSchemaAsync< +export interface NonNullishSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonNullishOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -25,7 +25,7 @@ export type NonNullishSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async non nullish schema. diff --git a/library/src/schemas/nonOptional/nonOptional.ts b/library/src/schemas/nonOptional/nonOptional.ts index 051114c0e..dbf6cc854 100644 --- a/library/src/schemas/nonOptional/nonOptional.ts +++ b/library/src/schemas/nonOptional/nonOptional.ts @@ -5,10 +5,10 @@ import type { NonOptionalInput, NonOptionalOutput } from './types.ts'; /** * Non optional schema type. */ -export type NonOptionalSchema< +export interface NonOptionalSchema< TWrapped extends BaseSchema, TOutput = NonOptionalOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -21,7 +21,7 @@ export type NonOptionalSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a non optional schema. diff --git a/library/src/schemas/nonOptional/nonOptionalAsync.ts b/library/src/schemas/nonOptional/nonOptionalAsync.ts index 7e3189bd9..3990e856b 100644 --- a/library/src/schemas/nonOptional/nonOptionalAsync.ts +++ b/library/src/schemas/nonOptional/nonOptionalAsync.ts @@ -9,10 +9,10 @@ import type { NonOptionalInput, NonOptionalOutput } from './types.ts'; /** * Non optional schema async type. */ -export type NonOptionalSchemaAsync< +export interface NonOptionalSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonOptionalOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -25,7 +25,7 @@ export type NonOptionalSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async non optional schema. diff --git a/library/src/schemas/null/null.ts b/library/src/schemas/null/null.ts index f971c1007..d468afa19 100644 --- a/library/src/schemas/null/null.ts +++ b/library/src/schemas/null/null.ts @@ -4,7 +4,7 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Null schema type. */ -export type NullSchema = BaseSchema & { +export interface NullSchema extends BaseSchema { /** * The schema type. */ @@ -13,7 +13,7 @@ export type NullSchema = BaseSchema & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a null schema. diff --git a/library/src/schemas/null/nullAsync.ts b/library/src/schemas/null/nullAsync.ts index 5e3358bb0..9673aff07 100644 --- a/library/src/schemas/null/nullAsync.ts +++ b/library/src/schemas/null/nullAsync.ts @@ -4,7 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Null schema async type. */ -export type NullSchemaAsync = BaseSchemaAsync & { +export interface NullSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -13,7 +14,7 @@ export type NullSchemaAsync = BaseSchemaAsync & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async null schema. diff --git a/library/src/schemas/nullable/nullable.ts b/library/src/schemas/nullable/nullable.ts index e4c96fe26..da1977285 100644 --- a/library/src/schemas/nullable/nullable.ts +++ b/library/src/schemas/nullable/nullable.ts @@ -1,20 +1,17 @@ import { getDefault } from '../../methods/index.ts'; -import type { BaseSchema, Input, Output } from '../../types/index.ts'; +import type { BaseSchema, Default, Input, Output } from '../../types/index.ts'; import { schemaResult } from '../../utils/index.ts'; /** * Nullable schema type. */ -export type NullableSchema< +export interface NullableSchema< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, TOutput = TDefault extends Input | (() => Input) ? Output : Output | null, -> = BaseSchema | null, TOutput> & { +> extends BaseSchema | null, TOutput> { /** * The schema type. */ @@ -27,7 +24,7 @@ export type NullableSchema< * The default value. */ default: TDefault; -}; +} /** * Creates a nullable schema. @@ -50,18 +47,12 @@ export function nullable( */ export function nullable< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined, + TDefault extends Default, >(wrapped: TWrapped, default_: TDefault): NullableSchema; export function nullable< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, >(wrapped: TWrapped, default_?: TDefault): NullableSchema { return { type: 'nullable', diff --git a/library/src/schemas/nullable/nullableAsync.ts b/library/src/schemas/nullable/nullableAsync.ts index 4a8869ad8..8f7c9edd4 100644 --- a/library/src/schemas/nullable/nullableAsync.ts +++ b/library/src/schemas/nullable/nullableAsync.ts @@ -2,6 +2,7 @@ import { getDefaultAsync } from '../../methods/index.ts'; import type { BaseSchema, BaseSchemaAsync, + DefaultAsync, Input, Output, } from '../../types/index.ts'; @@ -10,18 +11,15 @@ import { schemaResult } from '../../utils/index.ts'; /** * Nullable schema async type. */ -export type NullableSchemaAsync< +export interface NullableSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, TOutput = TDefault extends | Input | (() => Input | Promise>) ? Output : Output | null, -> = BaseSchemaAsync | null, TOutput> & { +> extends BaseSchemaAsync | null, TOutput> { /** * The schema type. */ @@ -34,7 +32,7 @@ export type NullableSchemaAsync< * Returns the default value. */ default: TDefault; -}; +} /** * Creates an async nullable schema. @@ -57,10 +55,7 @@ export function nullableAsync( */ export function nullableAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined, + TDefault extends DefaultAsync, >( wrapped: TWrapped, default_: TDefault @@ -68,10 +63,7 @@ export function nullableAsync< export function nullableAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, >( wrapped: TWrapped, default_?: TDefault diff --git a/library/src/schemas/nullish/nullish.ts b/library/src/schemas/nullish/nullish.ts index 6cc53cbbb..31c162a65 100644 --- a/library/src/schemas/nullish/nullish.ts +++ b/library/src/schemas/nullish/nullish.ts @@ -1,20 +1,17 @@ import { getDefault } from '../../methods/index.ts'; -import type { BaseSchema, Input, Output } from '../../types/index.ts'; +import type { BaseSchema, Default, Input, Output } from '../../types/index.ts'; import { schemaResult } from '../../utils/index.ts'; /** * Nullish schema type. */ -export type NullishSchema< +export interface NullishSchema< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, TOutput = TDefault extends Input | (() => Input) ? Output : Output | null | undefined, -> = BaseSchema | null | undefined, TOutput> & { +> extends BaseSchema | null | undefined, TOutput> { /** * The schema type. */ @@ -27,7 +24,7 @@ export type NullishSchema< * Returns the default value. */ default: TDefault; -}; +} /** * Creates a nullish schema. @@ -50,18 +47,12 @@ export function nullish( */ export function nullish< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined, + TDefault extends Default, >(wrapped: TWrapped, default_: TDefault): NullishSchema; export function nullish< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, >(wrapped: TWrapped, default_?: TDefault): NullishSchema { return { type: 'nullish', diff --git a/library/src/schemas/nullish/nullishAsync.ts b/library/src/schemas/nullish/nullishAsync.ts index a891553c2..66c810bbd 100644 --- a/library/src/schemas/nullish/nullishAsync.ts +++ b/library/src/schemas/nullish/nullishAsync.ts @@ -2,6 +2,7 @@ import { getDefaultAsync } from '../../methods/index.ts'; import type { BaseSchema, BaseSchemaAsync, + DefaultAsync, Input, Output, } from '../../types/index.ts'; @@ -10,18 +11,15 @@ import { schemaResult } from '../../utils/index.ts'; /** * Nullish schema async type. */ -export type NullishSchemaAsync< +export interface NullishSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, TOutput = TDefault extends | Input | (() => Input | Promise>) ? Output : Output | null | undefined, -> = BaseSchemaAsync | null | undefined, TOutput> & { +> extends BaseSchemaAsync | null | undefined, TOutput> { /** * The schema type. */ @@ -34,7 +32,7 @@ export type NullishSchemaAsync< * Retutns the default value. */ default: TDefault; -}; +} /** * Creates an async nullish schema. @@ -57,10 +55,7 @@ export function nullishAsync( */ export function nullishAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined, + TDefault extends DefaultAsync, >( wrapped: TWrapped, default_: TDefault @@ -68,10 +63,7 @@ export function nullishAsync< export function nullishAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, >( wrapped: TWrapped, default_?: TDefault diff --git a/library/src/schemas/number/number.ts b/library/src/schemas/number/number.ts index 141ca8d6e..fa314d4b5 100644 --- a/library/src/schemas/number/number.ts +++ b/library/src/schemas/number/number.ts @@ -4,7 +4,8 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Number schema type. */ -export type NumberSchema = BaseSchema & { +export interface NumberSchema + extends BaseSchema { /** * The schema type. */ @@ -17,7 +18,7 @@ export type NumberSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a number schema. diff --git a/library/src/schemas/number/numberAsync.ts b/library/src/schemas/number/numberAsync.ts index 5290ec51b..08a44bda3 100644 --- a/library/src/schemas/number/numberAsync.ts +++ b/library/src/schemas/number/numberAsync.ts @@ -12,10 +12,8 @@ import { /** * Number schema async type. */ -export type NumberSchemaAsync = BaseSchemaAsync< - number, - TOutput -> & { +export interface NumberSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -28,7 +26,7 @@ export type NumberSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async number schema. diff --git a/library/src/schemas/object/object.ts b/library/src/schemas/object/object.ts index 0507b8614..9383c30c6 100644 --- a/library/src/schemas/object/object.ts +++ b/library/src/schemas/object/object.ts @@ -20,11 +20,11 @@ export type ObjectEntries = Record; /** * Object schema type. */ -export type ObjectSchema< +export interface ObjectSchema< TEntries extends ObjectEntries, TRest extends BaseSchema | undefined = undefined, TOutput = ObjectOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -45,7 +45,7 @@ export type ObjectSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates an object schema. diff --git a/library/src/schemas/object/objectAsync.ts b/library/src/schemas/object/objectAsync.ts index 23d3a0cc0..99b4c4756 100644 --- a/library/src/schemas/object/objectAsync.ts +++ b/library/src/schemas/object/objectAsync.ts @@ -21,11 +21,11 @@ export type ObjectEntriesAsync = Record; /** * Object schema async type. */ -export type ObjectSchemaAsync< +export interface ObjectSchemaAsync< TEntries extends ObjectEntriesAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, TOutput = ObjectOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -46,7 +46,7 @@ export type ObjectSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async object schema. diff --git a/library/src/schemas/optional/optional.ts b/library/src/schemas/optional/optional.ts index 7041ba500..ef59b3591 100644 --- a/library/src/schemas/optional/optional.ts +++ b/library/src/schemas/optional/optional.ts @@ -1,20 +1,17 @@ import { getDefault } from '../../methods/index.ts'; -import type { BaseSchema, Input, Output } from '../../types/index.ts'; +import type { BaseSchema, Default, Input, Output } from '../../types/index.ts'; import { schemaResult } from '../../utils/index.ts'; /** * Optional schema type. */ -export type OptionalSchema< +export interface OptionalSchema< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, TOutput = TDefault extends Input | (() => Input) ? Output : Output | undefined, -> = BaseSchema | undefined, TOutput> & { +> extends BaseSchema | undefined, TOutput> { /** * The schema type. */ @@ -27,7 +24,7 @@ export type OptionalSchema< * Returns the default value. */ default: TDefault; -}; +} /** * Creates a optional schema. @@ -50,18 +47,12 @@ export function optional( */ export function optional< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined, + TDefault extends Default, >(wrapped: TWrapped, default_: TDefault): OptionalSchema; export function optional< TWrapped extends BaseSchema, - TDefault extends - | Input - | (() => Input | undefined) - | undefined = undefined, + TDefault extends Default = undefined, >(wrapped: TWrapped, default_?: TDefault): OptionalSchema { return { type: 'optional', diff --git a/library/src/schemas/optional/optionalAsync.ts b/library/src/schemas/optional/optionalAsync.ts index a2e7b074c..9848e0581 100644 --- a/library/src/schemas/optional/optionalAsync.ts +++ b/library/src/schemas/optional/optionalAsync.ts @@ -2,6 +2,7 @@ import { getDefaultAsync } from '../../methods/index.ts'; import type { BaseSchema, BaseSchemaAsync, + DefaultAsync, Input, Output, } from '../../types/index.ts'; @@ -10,18 +11,15 @@ import { schemaResult } from '../../utils/index.ts'; /** * Optional schema async type. */ -export type OptionalSchemaAsync< +export interface OptionalSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, TOutput = TDefault extends | Input | (() => Input | Promise>) ? Output : Output | undefined, -> = BaseSchemaAsync | undefined, TOutput> & { +> extends BaseSchemaAsync | undefined, TOutput> { /** * The schema type. */ @@ -34,7 +32,7 @@ export type OptionalSchemaAsync< * Returns the default value. */ default: TDefault; -}; +} /** * Creates an async optional schema. @@ -57,10 +55,7 @@ export function optionalAsync( */ export function optionalAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined, + TDefault extends DefaultAsync, >( wrapped: TWrapped, default_: TDefault @@ -68,10 +63,7 @@ export function optionalAsync< export function optionalAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TDefault extends - | Input - | (() => Input | Promise | undefined> | undefined) - | undefined = undefined, + TDefault extends DefaultAsync = undefined, >( wrapped: TWrapped, default_?: TDefault diff --git a/library/src/schemas/picklist/picklist.ts b/library/src/schemas/picklist/picklist.ts index c39bbf01e..031368104 100644 --- a/library/src/schemas/picklist/picklist.ts +++ b/library/src/schemas/picklist/picklist.ts @@ -5,10 +5,10 @@ import type { PicklistOptions } from './types.ts'; /** * Picklist schema type. */ -export type PicklistSchema< +export interface PicklistSchema< TOptions extends PicklistOptions, TOutput = TOptions[number], -> = BaseSchema & { +> extends BaseSchema { /** * The schema type. */ @@ -21,7 +21,7 @@ export type PicklistSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a picklist schema. diff --git a/library/src/schemas/picklist/picklistAsync.ts b/library/src/schemas/picklist/picklistAsync.ts index 00e492d81..8ecf895b3 100644 --- a/library/src/schemas/picklist/picklistAsync.ts +++ b/library/src/schemas/picklist/picklistAsync.ts @@ -5,10 +5,10 @@ import type { PicklistOptions } from './types.ts'; /** * Picklist schema async type. */ -export type PicklistSchemaAsync< +export interface PicklistSchemaAsync< TOptions extends PicklistOptions, TOutput = TOptions[number], -> = BaseSchemaAsync & { +> extends BaseSchemaAsync { /** * The schema type. */ @@ -21,7 +21,7 @@ export type PicklistSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async picklist schema. diff --git a/library/src/schemas/record/record.ts b/library/src/schemas/record/record.ts index fd4c80d8a..2fbe89b68 100644 --- a/library/src/schemas/record/record.ts +++ b/library/src/schemas/record/record.ts @@ -27,11 +27,11 @@ export type RecordKey = /** * Record schema type. */ -export type RecordSchema< +export interface RecordSchema< TKey extends RecordKey, TValue extends BaseSchema, TOutput = RecordOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -52,7 +52,7 @@ export type RecordSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a record schema. diff --git a/library/src/schemas/record/recordAsync.ts b/library/src/schemas/record/recordAsync.ts index 1ccdb0a72..d40c83517 100644 --- a/library/src/schemas/record/recordAsync.ts +++ b/library/src/schemas/record/recordAsync.ts @@ -37,11 +37,11 @@ export type RecordKeyAsync = /** * Record schema async type. */ -export type RecordSchemaAsync< +export interface RecordSchemaAsync< TKey extends RecordKeyAsync, TValue extends BaseSchema | BaseSchemaAsync, TOutput = RecordOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -62,7 +62,7 @@ export type RecordSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async record schema. diff --git a/library/src/schemas/set/set.ts b/library/src/schemas/set/set.ts index c13c634bf..6397c99f0 100644 --- a/library/src/schemas/set/set.ts +++ b/library/src/schemas/set/set.ts @@ -15,10 +15,10 @@ import type { SetInput, SetOutput, SetPathItem } from './types.ts'; /** * Set schema type. */ -export type SetSchema< +export interface SetSchema< TValue extends BaseSchema, TOutput = SetOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -35,7 +35,7 @@ export type SetSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a set schema. diff --git a/library/src/schemas/set/setAsync.ts b/library/src/schemas/set/setAsync.ts index b5f8ce571..f74a28979 100644 --- a/library/src/schemas/set/setAsync.ts +++ b/library/src/schemas/set/setAsync.ts @@ -16,10 +16,10 @@ import type { SetInput, SetOutput, SetPathItem } from './types.ts'; /** * Set schema async type. */ -export type SetSchemaAsync< +export interface SetSchemaAsync< TValue extends BaseSchema | BaseSchemaAsync, TOutput = SetOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -36,7 +36,7 @@ export type SetSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async set schema. diff --git a/library/src/schemas/special/special.ts b/library/src/schemas/special/special.ts index b9ab2cd65..5e92bbdec 100644 --- a/library/src/schemas/special/special.ts +++ b/library/src/schemas/special/special.ts @@ -4,10 +4,8 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * Special schema type. */ -export type SpecialSchema = BaseSchema< - TInput, - TOutput -> & { +export interface SpecialSchema + extends BaseSchema { /** * The schema type. */ @@ -24,7 +22,7 @@ export type SpecialSchema = BaseSchema< * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a special schema. diff --git a/library/src/schemas/special/specialAsync.ts b/library/src/schemas/special/specialAsync.ts index 40bcc1d0f..af935b36f 100644 --- a/library/src/schemas/special/specialAsync.ts +++ b/library/src/schemas/special/specialAsync.ts @@ -12,10 +12,8 @@ import { /** * Special schema async type. */ -export type SpecialSchemaAsync = BaseSchemaAsync< - TInput, - TOutput -> & { +export interface SpecialSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -32,7 +30,7 @@ export type SpecialSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async special schema. diff --git a/library/src/schemas/string/string.ts b/library/src/schemas/string/string.ts index 46fe96a05..04dafbd94 100644 --- a/library/src/schemas/string/string.ts +++ b/library/src/schemas/string/string.ts @@ -4,7 +4,8 @@ import { defaultArgs, pipeResult, schemaIssue } from '../../utils/index.ts'; /** * String schema type. */ -export type StringSchema = BaseSchema & { +export interface StringSchema + extends BaseSchema { /** * The schema type. */ @@ -17,7 +18,7 @@ export type StringSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a string schema. diff --git a/library/src/schemas/string/stringAsync.ts b/library/src/schemas/string/stringAsync.ts index d043329e3..f3e3506e1 100644 --- a/library/src/schemas/string/stringAsync.ts +++ b/library/src/schemas/string/stringAsync.ts @@ -12,10 +12,8 @@ import { /** * String schema async type. */ -export type StringSchemaAsync = BaseSchemaAsync< - string, - TOutput -> & { +export interface StringSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -28,7 +26,7 @@ export type StringSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async string schema. diff --git a/library/src/schemas/symbol/symbol.ts b/library/src/schemas/symbol/symbol.ts index 4b2ebf2a2..227f62eea 100644 --- a/library/src/schemas/symbol/symbol.ts +++ b/library/src/schemas/symbol/symbol.ts @@ -4,7 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Symbol schema type. */ -export type SymbolSchema = BaseSchema & { +export interface SymbolSchema + extends BaseSchema { /** * The schema type. */ @@ -13,7 +14,7 @@ export type SymbolSchema = BaseSchema & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a symbol schema. diff --git a/library/src/schemas/symbol/symbolAsync.ts b/library/src/schemas/symbol/symbolAsync.ts index 07dacb536..4880875c5 100644 --- a/library/src/schemas/symbol/symbolAsync.ts +++ b/library/src/schemas/symbol/symbolAsync.ts @@ -4,10 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Symbol schema async type. */ -export type SymbolSchemaAsync = BaseSchemaAsync< - symbol, - TOutput -> & { +export interface SymbolSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -16,7 +14,7 @@ export type SymbolSchemaAsync = BaseSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async symbol schema. diff --git a/library/src/schemas/tuple/tuple.ts b/library/src/schemas/tuple/tuple.ts index 1188c4cac..04039cf68 100644 --- a/library/src/schemas/tuple/tuple.ts +++ b/library/src/schemas/tuple/tuple.ts @@ -20,11 +20,11 @@ export type TupleItems = [BaseSchema, ...BaseSchema[]]; /** * Tuple schema type. */ -export type TupleSchema< +export interface TupleSchema< TItems extends TupleItems, TRest extends BaseSchema | undefined = undefined, TOutput = TupleOutput, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -45,7 +45,7 @@ export type TupleSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a tuple schema. diff --git a/library/src/schemas/tuple/tupleAsync.ts b/library/src/schemas/tuple/tupleAsync.ts index f9f00fbca..76475e1ff 100644 --- a/library/src/schemas/tuple/tupleAsync.ts +++ b/library/src/schemas/tuple/tupleAsync.ts @@ -24,11 +24,11 @@ export type TupleItemsAsync = [ /** * Tuple schema async type. */ -export type TupleSchemaAsync< +export interface TupleSchemaAsync< TItems extends TupleItemsAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, TOutput = TupleOutput, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -49,7 +49,7 @@ export type TupleSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async tuple schema. diff --git a/library/src/schemas/undefined/undefined.ts b/library/src/schemas/undefined/undefined.ts index f764b5d70..72c2ec29b 100644 --- a/library/src/schemas/undefined/undefined.ts +++ b/library/src/schemas/undefined/undefined.ts @@ -4,10 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Undefined schema type. */ -export type UndefinedSchema = BaseSchema< - undefined, - TOutput -> & { +export interface UndefinedSchema + extends BaseSchema { /** * The schema type. */ @@ -16,7 +14,7 @@ export type UndefinedSchema = BaseSchema< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a undefined schema. diff --git a/library/src/schemas/undefined/undefinedAsync.ts b/library/src/schemas/undefined/undefinedAsync.ts index 807d838bb..3b6504da7 100644 --- a/library/src/schemas/undefined/undefinedAsync.ts +++ b/library/src/schemas/undefined/undefinedAsync.ts @@ -4,10 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Undefined schema async type. */ -export type UndefinedSchemaAsync = BaseSchemaAsync< - undefined, - TOutput -> & { +export interface UndefinedSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -16,7 +14,7 @@ export type UndefinedSchemaAsync = BaseSchemaAsync< * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async undefined schema. diff --git a/library/src/schemas/union/union.ts b/library/src/schemas/union/union.ts index ecb7761ce..78925896e 100644 --- a/library/src/schemas/union/union.ts +++ b/library/src/schemas/union/union.ts @@ -19,10 +19,10 @@ export type UnionOptions = MaybeReadonly; /** * Union schema type. */ -export type UnionSchema< +export interface UnionSchema< TOptions extends UnionOptions, TOutput = Output, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -39,7 +39,7 @@ export type UnionSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a union schema. diff --git a/library/src/schemas/union/unionAsync.ts b/library/src/schemas/union/unionAsync.ts index 287c75f8e..1e79f1393 100644 --- a/library/src/schemas/union/unionAsync.ts +++ b/library/src/schemas/union/unionAsync.ts @@ -24,10 +24,10 @@ export type UnionOptionsAsync = MaybeReadonly<(BaseSchema | BaseSchemaAsync)[]>; /** * Union schema async type. */ -export type UnionSchemaAsync< +export interface UnionSchemaAsync< TOptions extends UnionOptionsAsync, TOutput = Output, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -44,7 +44,7 @@ export type UnionSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async union schema. diff --git a/library/src/schemas/unknown/unknown.ts b/library/src/schemas/unknown/unknown.ts index 8d28a2bc0..dedfeb59e 100644 --- a/library/src/schemas/unknown/unknown.ts +++ b/library/src/schemas/unknown/unknown.ts @@ -4,7 +4,8 @@ import { pipeResult } from '../../utils/index.ts'; /** * Unknown schema type. */ -export type UnknownSchema = BaseSchema & { +export interface UnknownSchema + extends BaseSchema { /** * The schema type. */ @@ -13,7 +14,7 @@ export type UnknownSchema = BaseSchema & { * The validation and transformation pipeline. */ pipe: Pipe | undefined; -}; +} /** * Creates a unknown schema. diff --git a/library/src/schemas/unknown/unknownAsync.ts b/library/src/schemas/unknown/unknownAsync.ts index 95001227d..a023ed4e4 100644 --- a/library/src/schemas/unknown/unknownAsync.ts +++ b/library/src/schemas/unknown/unknownAsync.ts @@ -4,10 +4,8 @@ import { pipeResultAsync } from '../../utils/index.ts'; /** * Unknown schema async type. */ -export type UnknownSchemaAsync = BaseSchemaAsync< - unknown, - TOutput -> & { +export interface UnknownSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -16,7 +14,7 @@ export type UnknownSchemaAsync = BaseSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync | undefined; -}; +} /** * Creates an async unknown schema. diff --git a/library/src/schemas/variant/variant.ts b/library/src/schemas/variant/variant.ts index 57f662652..d1acad300 100644 --- a/library/src/schemas/variant/variant.ts +++ b/library/src/schemas/variant/variant.ts @@ -31,11 +31,11 @@ export type VariantOptions = [ /** * Variant schema type. */ -export type VariantSchema< +export interface VariantSchema< TKey extends string, TOptions extends VariantOptions, TOutput = Output, -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -56,7 +56,7 @@ export type VariantSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a variant (aka discriminated union) schema. diff --git a/library/src/schemas/variant/variantAsync.ts b/library/src/schemas/variant/variantAsync.ts index c39f4c636..dfd94febe 100644 --- a/library/src/schemas/variant/variantAsync.ts +++ b/library/src/schemas/variant/variantAsync.ts @@ -37,11 +37,11 @@ export type VariantOptionsAsync = [ /** * Variant schema async type. */ -export type VariantSchemaAsync< +export interface VariantSchemaAsync< TKey extends string, TOptions extends VariantOptionsAsync, TOutput = Output, -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -62,7 +62,7 @@ export type VariantSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async variant (aka discriminated union) schema. diff --git a/library/src/schemas/void/void.ts b/library/src/schemas/void/void.ts index bacb070a7..ad25eb9c0 100644 --- a/library/src/schemas/void/void.ts +++ b/library/src/schemas/void/void.ts @@ -4,7 +4,7 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Void schema type. */ -export type VoidSchema = BaseSchema & { +export interface VoidSchema extends BaseSchema { /** * The schema type. */ @@ -13,7 +13,7 @@ export type VoidSchema = BaseSchema & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates a void schema. diff --git a/library/src/schemas/void/voidAsync.ts b/library/src/schemas/void/voidAsync.ts index 1d6d7a00d..b83f190c2 100644 --- a/library/src/schemas/void/voidAsync.ts +++ b/library/src/schemas/void/voidAsync.ts @@ -4,7 +4,8 @@ import { schemaIssue, schemaResult } from '../../utils/index.ts'; /** * Void schema async type. */ -export type VoidSchemaAsync = BaseSchemaAsync & { +export interface VoidSchemaAsync + extends BaseSchemaAsync { /** * The schema type. */ @@ -13,7 +14,7 @@ export type VoidSchemaAsync = BaseSchemaAsync & { * The error message. */ message: ErrorMessage | undefined; -}; +} /** * Creates an async void schema. diff --git a/library/src/transformations/toCustom/toCustom.ts b/library/src/transformations/toCustom/toCustom.ts index bfc2523d2..f34e055e7 100644 --- a/library/src/transformations/toCustom/toCustom.ts +++ b/library/src/transformations/toCustom/toCustom.ts @@ -4,12 +4,13 @@ import { actionOutput } from '../../utils/index.ts'; /** * To custom transformation type. */ -export type ToCustomTransformation = BaseTransformation & { +export interface ToCustomTransformation + extends BaseTransformation { /** * The transformation type. */ type: 'to_custom'; -}; +} /** * Creates a custom pipeline transformation action. diff --git a/library/src/transformations/toCustom/toCustomAsync.ts b/library/src/transformations/toCustom/toCustomAsync.ts index 00b16d24d..963b14559 100644 --- a/library/src/transformations/toCustom/toCustomAsync.ts +++ b/library/src/transformations/toCustom/toCustomAsync.ts @@ -4,13 +4,13 @@ import { actionOutput } from '../../utils/index.ts'; /** * To custom transformation async type. */ -export type ToCustomTransformationAsync = - BaseTransformationAsync & { - /** - * The transformation type. - */ - type: 'to_custom'; - }; +export interface ToCustomTransformationAsync + extends BaseTransformationAsync { + /** + * The transformation type. + */ + type: 'to_custom'; +} /** * Creates a async custom transformation function. diff --git a/library/src/transformations/toLowerCase/toLowerCase.ts b/library/src/transformations/toLowerCase/toLowerCase.ts index 0cf9152df..524f276b7 100644 --- a/library/src/transformations/toLowerCase/toLowerCase.ts +++ b/library/src/transformations/toLowerCase/toLowerCase.ts @@ -4,12 +4,12 @@ import { actionOutput } from '../../utils/index.ts'; /** * To lower case transformation type. */ -export type ToLowerCaseTransformation = BaseTransformation & { +export interface ToLowerCaseTransformation extends BaseTransformation { /** * The transformation type. */ type: 'to_lower_case'; -}; +} /** * Creates a pipeline transformation action that converts all the alphabetic diff --git a/library/src/transformations/toMaxValue/toMaxValue.ts b/library/src/transformations/toMaxValue/toMaxValue.ts index 76c8554c5..671c764e4 100644 --- a/library/src/transformations/toMaxValue/toMaxValue.ts +++ b/library/src/transformations/toMaxValue/toMaxValue.ts @@ -4,10 +4,10 @@ import { actionOutput } from '../../utils/index.ts'; /** * To max value transformation type. */ -export type ToMaxValueTransformation< +export interface ToMaxValueTransformation< TInput extends string | number | bigint | Date, TRequirement extends TInput, -> = BaseTransformation & { +> extends BaseTransformation { /** * The transformation type. */ @@ -16,7 +16,7 @@ export type ToMaxValueTransformation< * The maximum value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline transformation action that sets a string, number or date diff --git a/library/src/transformations/toMinValue/toMinValue.ts b/library/src/transformations/toMinValue/toMinValue.ts index 78d366f9c..f3cca4192 100644 --- a/library/src/transformations/toMinValue/toMinValue.ts +++ b/library/src/transformations/toMinValue/toMinValue.ts @@ -4,10 +4,10 @@ import { actionOutput } from '../../utils/index.ts'; /** * To min value transformation type. */ -export type ToMinValueTransformation< +export interface ToMinValueTransformation< TInput extends string | number | bigint | Date, TRequirement extends TInput, -> = BaseTransformation & { +> extends BaseTransformation { /** * The transformation type. */ @@ -16,7 +16,7 @@ export type ToMinValueTransformation< * The minium value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline transformation action that sets a string, number or date diff --git a/library/src/transformations/toTrimmed/toTrimmed.ts b/library/src/transformations/toTrimmed/toTrimmed.ts index df58ccb73..450f0eb83 100644 --- a/library/src/transformations/toTrimmed/toTrimmed.ts +++ b/library/src/transformations/toTrimmed/toTrimmed.ts @@ -4,12 +4,12 @@ import { actionOutput } from '../../utils/index.ts'; /** * To trimmed transformation type. */ -export type ToTrimmedTransformation = BaseTransformation & { +export interface ToTrimmedTransformation extends BaseTransformation { /** * The transformation type. */ type: 'to_trimmed'; -}; +} /** * Creates a pipeline transformation action that removes the leading and diff --git a/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts b/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts index b8728c1c1..aa78e6c72 100644 --- a/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts +++ b/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts @@ -4,12 +4,12 @@ import { actionOutput } from '../../utils/index.ts'; /** * To trimmed end transformation type. */ -export type ToTrimmedEndTransformation = BaseTransformation & { +export interface ToTrimmedEndTransformation extends BaseTransformation { /** * The transformation type. */ type: 'to_trimmed_end'; -}; +} /** * Creates a pipeline transformation action that removes the trailing white diff --git a/library/src/transformations/toTrimmedStart/toTrimmedStart.ts b/library/src/transformations/toTrimmedStart/toTrimmedStart.ts index 01decf8b1..b1b918d12 100644 --- a/library/src/transformations/toTrimmedStart/toTrimmedStart.ts +++ b/library/src/transformations/toTrimmedStart/toTrimmedStart.ts @@ -4,12 +4,13 @@ import { actionOutput } from '../../utils/index.ts'; /** * To trimmed start transformation type. */ -export type ToTrimmedStartTransformation = BaseTransformation & { +export interface ToTrimmedStartTransformation + extends BaseTransformation { /** * The transformation type. */ type: 'to_trimmed_start'; -}; +} /** * Creates a pipeline transformation action that removes the leading white diff --git a/library/src/transformations/toUpperCase/toUpperCase.ts b/library/src/transformations/toUpperCase/toUpperCase.ts index 4e428f907..b6f3e4426 100644 --- a/library/src/transformations/toUpperCase/toUpperCase.ts +++ b/library/src/transformations/toUpperCase/toUpperCase.ts @@ -4,12 +4,12 @@ import { actionOutput } from '../../utils/index.ts'; /** * To upper case transformation type. */ -export type ToUpperCaseTransformation = BaseTransformation & { +export interface ToUpperCaseTransformation extends BaseTransformation { /** * The transformation type. */ type: 'to_upper_case'; -}; +} /** * Creates a pipeline transformation action that converts all the alphabetic diff --git a/library/src/types/other.ts b/library/src/types/other.ts index 453a12b12..710bc24c5 100644 --- a/library/src/types/other.ts +++ b/library/src/types/other.ts @@ -1,4 +1,21 @@ import type { ObjectSchema, ObjectSchemaAsync } from '../schemas/index.ts'; +import type { BaseSchema, BaseSchemaAsync, Input } from './schema.ts'; + +/** + * Default type. + */ +export type Default = + | Input + | (() => Input | undefined) + | undefined; + +/** + * Default async type. + */ +export type DefaultAsync = + | Input + | (() => Input | Promise | undefined> | undefined) + | undefined; /** * Object keys type. diff --git a/library/src/types/pipe.ts b/library/src/types/pipe.ts index f71186d54..dfe8a8916 100644 --- a/library/src/types/pipe.ts +++ b/library/src/types/pipe.ts @@ -49,7 +49,11 @@ export type PipeActionResult = /** * Base validation type. */ -export type BaseValidation = { +export interface BaseValidation { + /** + * The validation type. + */ + type: string; /** * The expected property. */ @@ -62,6 +66,10 @@ export type BaseValidation = { * Whether it's async. */ async: false; + /** + * The validation requirement. + */ + requirement: unknown; /** * Parses unknown input based on its requirement. * @@ -72,12 +80,16 @@ export type BaseValidation = { * @internal */ _parse(input: TInput): PipeActionResult; -}; +} /** * Base validation async type. */ -export type BaseValidationAsync = { +export interface BaseValidationAsync { + /** + * The validation type. + */ + type: string; /** * The expected property. */ @@ -90,6 +102,10 @@ export type BaseValidationAsync = { * Whether it's async. */ async: true; + /** + * The validation requirement. + */ + requirement: unknown; /** * Parses unknown input based on its requirement. * @@ -100,12 +116,16 @@ export type BaseValidationAsync = { * @internal */ _parse(input: TInput): Promise>; -}; +} /** * Base transformation type. */ -export type BaseTransformation = { +export interface BaseTransformation { + /** + * The transformation type. + */ + type: string; /** * Whether it's async. */ @@ -120,12 +140,16 @@ export type BaseTransformation = { * @internal */ _parse(input: TInput): PipeActionResult; -}; +} /** * Base transformation async type. */ -export type BaseTransformationAsync = { +export interface BaseTransformationAsync { + /** + * The transformation type. + */ + type: string; /** * Whether it's async. */ @@ -140,7 +164,7 @@ export type BaseTransformationAsync = { * @internal */ _parse(input: TInput): Promise>; -}; +} /** * Pipe type. diff --git a/library/src/types/schema.ts b/library/src/types/schema.ts index ecb669bf6..d191198a8 100644 --- a/library/src/types/schema.ts +++ b/library/src/types/schema.ts @@ -47,7 +47,11 @@ export type SchemaResult = /** * Base schema type. */ -export type BaseSchema = { +export interface BaseSchema { + /** + * The schema type. + */ + type: string; /** * The expected property. */ @@ -73,12 +77,16 @@ export type BaseSchema = { * @internal */ _types?: { input: TInput; output: TOutput }; -}; +} /** * Base schema async type. */ -export type BaseSchemaAsync = { +export interface BaseSchemaAsync { + /** + * The schema type. + */ + type: string; /** * The expected property. */ @@ -104,7 +112,7 @@ export type BaseSchemaAsync = { * @internal */ _types?: { input: TInput; output: TOutput }; -}; +} /** * Input inference type. diff --git a/library/src/utils/index.ts b/library/src/utils/index.ts index e6169a57d..3c7bdd49f 100644 --- a/library/src/utils/index.ts +++ b/library/src/utils/index.ts @@ -3,6 +3,7 @@ export * from './actionOutput/index.ts'; export * from './defaultArgs/index.ts'; export * from './i18n/index.ts'; export * from './isLuhnAlgo/index.ts'; +export * from './isOfType/index.ts'; export * from './pipeResult/index.ts'; export * from './restAndDefaultArgs/index.ts'; export * from './schemaIssue/index.ts'; diff --git a/library/src/utils/isOfType/index.ts b/library/src/utils/isOfType/index.ts new file mode 100644 index 000000000..547e93e2b --- /dev/null +++ b/library/src/utils/isOfType/index.ts @@ -0,0 +1 @@ +export * from './isOfType.ts'; diff --git a/library/src/utils/isOfType/isOfType.test.ts b/library/src/utils/isOfType/isOfType.test.ts new file mode 100644 index 000000000..ca204fd24 --- /dev/null +++ b/library/src/utils/isOfType/isOfType.test.ts @@ -0,0 +1,26 @@ +import { describe, expect, test } from 'vitest'; +import { number, object, string } from '../../schemas/index.ts'; +import { isOfType } from './isOfType.ts'; + +describe('isOfType', () => { + test('should check string schema', () => { + const schema = string(); + expect(isOfType('string', schema)).toBeTruthy(); + expect(isOfType('number', schema)).toBeFalsy(); + expect(isOfType('object', schema)).toBeFalsy(); + }); + + test('should check number schema', () => { + const schema = number(); + expect(isOfType('number', schema)).toBeTruthy(); + expect(isOfType('string', schema)).toBeFalsy(); + expect(isOfType('object', schema)).toBeFalsy(); + }); + + test('should check object schema', () => { + const schema = object({ key: string() }); + expect(isOfType('object', schema)).toBeTruthy(); + expect(isOfType('string', schema)).toBeFalsy(); + expect(isOfType('number', schema)).toBeFalsy(); + }); +}); diff --git a/library/src/utils/isOfType/isOfType.ts b/library/src/utils/isOfType/isOfType.ts new file mode 100644 index 000000000..2524b4abe --- /dev/null +++ b/library/src/utils/isOfType/isOfType.ts @@ -0,0 +1,14 @@ +/** + * A generic type guard to check the type of an object. + * + * @param type The type to check for. + * @param object The object to check. + * + * @returns Whether it matches. + */ +export function isOfType< + TType extends string, + TObject extends { type: string }, +>(type: TType, object: TObject): object is Extract { + return object.type === type; +} diff --git a/library/src/validations/bytes/bytes.ts b/library/src/validations/bytes/bytes.ts index aab7a84ca..bec499222 100644 --- a/library/src/validations/bytes/bytes.ts +++ b/library/src/validations/bytes/bytes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Bytes validation type. */ -export type BytesValidation< +export interface BytesValidation< TInput extends string, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type BytesValidation< * The byte length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the bytes of a string. diff --git a/library/src/validations/cuid2/cuid2.ts b/library/src/validations/cuid2/cuid2.ts index 09c8ded49..1e3e603ee 100644 --- a/library/src/validations/cuid2/cuid2.ts +++ b/library/src/validations/cuid2/cuid2.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Cuid2 validation type. */ -export type Cuid2Validation = BaseValidation & { +export interface Cuid2Validation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type Cuid2Validation = BaseValidation & { * The Cuid2 regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates a [Cuid2](https://github.com/paralleldrive/cuid2). diff --git a/library/src/validations/custom/custom.ts b/library/src/validations/custom/custom.ts index b0c139a6d..2a2569d46 100644 --- a/library/src/validations/custom/custom.ts +++ b/library/src/validations/custom/custom.ts @@ -4,7 +4,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Custom validation type. */ -export type CustomValidation = BaseValidation & { +export interface CustomValidation extends BaseValidation { /** * The validation type. */ @@ -13,7 +13,7 @@ export type CustomValidation = BaseValidation & { * The validation function. */ requirement: (input: TInput) => boolean; -}; +} /** * Creates a custom pipeline validation action. diff --git a/library/src/validations/custom/customAsync.ts b/library/src/validations/custom/customAsync.ts index 225e7ac6b..7a8925184 100644 --- a/library/src/validations/custom/customAsync.ts +++ b/library/src/validations/custom/customAsync.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Custom validation async type. */ -export type CustomValidationAsync = BaseValidationAsync & { +export interface CustomValidationAsync + extends BaseValidationAsync { /** * The validation type. */ @@ -13,7 +14,7 @@ export type CustomValidationAsync = BaseValidationAsync & { * The validation function. */ requirement: (input: TInput) => Promise; -}; +} /** * Creates a async custom validation function. diff --git a/library/src/validations/email/email.ts b/library/src/validations/email/email.ts index b729245cd..ed4425a4d 100644 --- a/library/src/validations/email/email.ts +++ b/library/src/validations/email/email.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Email validation type. */ -export type EmailValidation = BaseValidation & { +export interface EmailValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type EmailValidation = BaseValidation & { * The email regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates an email. diff --git a/library/src/validations/emoji/emoji.ts b/library/src/validations/emoji/emoji.ts index 4a3d808de..b05e768c7 100644 --- a/library/src/validations/emoji/emoji.ts +++ b/library/src/validations/emoji/emoji.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Emoji validation type. */ -export type EmojiValidation = BaseValidation & { +export interface EmojiValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type EmojiValidation = BaseValidation & { * The emoji regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates an emoji. diff --git a/library/src/validations/endsWith/endsWith.ts b/library/src/validations/endsWith/endsWith.ts index e2f80257f..d6fd6a626 100644 --- a/library/src/validations/endsWith/endsWith.ts +++ b/library/src/validations/endsWith/endsWith.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Ends with validation type. */ -export type EndsWithValidation< +export interface EndsWithValidation< TInput extends string, TRequirement extends string, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type EndsWithValidation< * The end string. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the end of a string. diff --git a/library/src/validations/equal/equal.ts b/library/src/validations/equal/equal.ts index b19a22be9..118fec28d 100644 --- a/library/src/validations/equal/equal.ts +++ b/library/src/validations/equal/equal.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Equal validation type. */ -export type EqualValidation< +export interface EqualValidation< TInput extends string | number | bigint | boolean, TRequirement extends TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type EqualValidation< * The required value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that checks the value for equality. diff --git a/library/src/validations/every/every.ts b/library/src/validations/every/every.ts index cf370fa7d..2ceb8aa2f 100644 --- a/library/src/validations/every/every.ts +++ b/library/src/validations/every/every.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Every validation type. */ -export type EveryValidation = BaseValidation & { +export interface EveryValidation + extends BaseValidation { /** * The validation type. */ @@ -17,7 +18,7 @@ export type EveryValidation = BaseValidation & { index: number, array: TInput[number][] ) => boolean; -}; +} /** * Creates a pipeline validation action that validates the items of an array. diff --git a/library/src/validations/excludes/excludes.ts b/library/src/validations/excludes/excludes.ts index ec72ae56c..53aa4f556 100644 --- a/library/src/validations/excludes/excludes.ts +++ b/library/src/validations/excludes/excludes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Excludes validation type. */ -export type ExcludesValidation< +export interface ExcludesValidation< TInput extends string | any[], TRequirement extends TInput extends any[] ? TInput[number] : TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type ExcludesValidation< * The required value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the content of a string diff --git a/library/src/validations/finite/finite.ts b/library/src/validations/finite/finite.ts index 4a86c5f51..6a0189881 100644 --- a/library/src/validations/finite/finite.ts +++ b/library/src/validations/finite/finite.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Finite validation type. */ -export type FiniteValidation = BaseValidation & { +export interface FiniteValidation + extends BaseValidation { /** * The validation type. */ @@ -13,7 +14,7 @@ export type FiniteValidation = BaseValidation & { * The validation function. */ requirement: (input: TInput) => boolean; -}; +} /** * Creates a pipeline validation action that validates whether a number is finite. diff --git a/library/src/validations/imei/imei.ts b/library/src/validations/imei/imei.ts index 7a47654b8..3349d83da 100644 --- a/library/src/validations/imei/imei.ts +++ b/library/src/validations/imei/imei.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput, isLuhnAlgo } from '../../utils/index.ts'; /** * IMEI validation type. */ -export type ImeiValidation = BaseValidation & { +export interface ImeiValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type ImeiValidation = BaseValidation & { * The IMEI regex and luhn algorithm. */ requirement: [RegExp, typeof isLuhnAlgo]; -}; +} /** * Creates a pipeline validation action that validates an [IMEI](https://en.wikipedia.org/wiki/International_Mobile_Equipment_Identity). diff --git a/library/src/validations/includes/includes.ts b/library/src/validations/includes/includes.ts index 29754ee89..49795d6bb 100644 --- a/library/src/validations/includes/includes.ts +++ b/library/src/validations/includes/includes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Includes validation type. */ -export type IncludesValidation< +export interface IncludesValidation< TInput extends string | any[], TRequirement extends TInput extends any[] ? TInput[number] : TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type IncludesValidation< * The required value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the content of a string diff --git a/library/src/validations/integer/integer.ts b/library/src/validations/integer/integer.ts index 436f93454..1d36aac68 100644 --- a/library/src/validations/integer/integer.ts +++ b/library/src/validations/integer/integer.ts @@ -4,17 +4,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Integer validation type. */ -export type IntegerValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'integer'; - /** - * The validation function. - */ - requirement: (input: TInput) => boolean; - }; +export interface IntegerValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'integer'; + /** + * The validation function. + */ + requirement: (input: TInput) => boolean; +} /** * Creates a pipeline validation action that validates whether a number is an diff --git a/library/src/validations/ip/ip.ts b/library/src/validations/ip/ip.ts index a4062a549..c064b3ac5 100644 --- a/library/src/validations/ip/ip.ts +++ b/library/src/validations/ip/ip.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * IP validation type. */ -export type IpValidation = BaseValidation & { +export interface IpValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type IpValidation = BaseValidation & { * The IPv4 and IPv6 regex. */ requirement: [RegExp, RegExp]; -}; +} /** * Creates a pipeline validation action that validates an [IPv4](https://en.wikipedia.org/wiki/IPv4) diff --git a/library/src/validations/ipv4/ipv4.ts b/library/src/validations/ipv4/ipv4.ts index d5d96cd9c..bfd29e9ca 100644 --- a/library/src/validations/ipv4/ipv4.ts +++ b/library/src/validations/ipv4/ipv4.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * IPv4 validation type. */ -export type Ipv4Validation = BaseValidation & { +export interface Ipv4Validation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type Ipv4Validation = BaseValidation & { * The IPv4 regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates an [IPv4](https://en.wikipedia.org/wiki/IPv4) address. diff --git a/library/src/validations/ipv6/ipv6.ts b/library/src/validations/ipv6/ipv6.ts index 38fbde8fd..d6ac121e2 100644 --- a/library/src/validations/ipv6/ipv6.ts +++ b/library/src/validations/ipv6/ipv6.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * IPv6 validation type. */ -export type Ipv6Validation = BaseValidation & { +export interface Ipv6Validation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type Ipv6Validation = BaseValidation & { * The IPv6 regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates an [IPv6](https://en.wikipedia.org/wiki/IPv6) address. diff --git a/library/src/validations/isoDate/isoDate.ts b/library/src/validations/isoDate/isoDate.ts index 4d800a7b6..d417bac9b 100644 --- a/library/src/validations/isoDate/isoDate.ts +++ b/library/src/validations/isoDate/isoDate.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO date validation type. */ -export type IsoDateValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_date'; - /** - * The ISO date regex. - */ - requirement: RegExp; - }; +export interface IsoDateValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_date'; + /** + * The ISO date regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a date. diff --git a/library/src/validations/isoDateTime/isoDateTime.ts b/library/src/validations/isoDateTime/isoDateTime.ts index f302e7455..2aea831bb 100644 --- a/library/src/validations/isoDateTime/isoDateTime.ts +++ b/library/src/validations/isoDateTime/isoDateTime.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO date time validation type. */ -export type IsoDateTimeValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_date_time'; - /** - * The ISO date time regex. - */ - requirement: RegExp; - }; +export interface IsoDateTimeValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_date_time'; + /** + * The ISO date time regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a datetime. diff --git a/library/src/validations/isoTime/isoTime.ts b/library/src/validations/isoTime/isoTime.ts index 98cd6982b..bd3dcfe77 100644 --- a/library/src/validations/isoTime/isoTime.ts +++ b/library/src/validations/isoTime/isoTime.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO time validation type. */ -export type IsoTimeValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_time'; - /** - * The ISO time regex. - */ - requirement: RegExp; - }; +export interface IsoTimeValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_time'; + /** + * The ISO time regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a time. diff --git a/library/src/validations/isoTimeSecond/isoTimeSecond.ts b/library/src/validations/isoTimeSecond/isoTimeSecond.ts index a92970e72..152af357b 100644 --- a/library/src/validations/isoTimeSecond/isoTimeSecond.ts +++ b/library/src/validations/isoTimeSecond/isoTimeSecond.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO time second validation type. */ -export type IsoTimeSecondValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_time_second'; - /** - * The ISO time second regex. - */ - requirement: RegExp; - }; +export interface IsoTimeSecondValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_time_second'; + /** + * The ISO time second regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a time with seconds. diff --git a/library/src/validations/isoTimestamp/isoTimestamp.ts b/library/src/validations/isoTimestamp/isoTimestamp.ts index 2ed69b857..84d9e0a82 100644 --- a/library/src/validations/isoTimestamp/isoTimestamp.ts +++ b/library/src/validations/isoTimestamp/isoTimestamp.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO timestamp validation type. */ -export type IsoTimestampValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_timestamp'; - /** - * The ISO timestamp regex. - */ - requirement: RegExp; - }; +export interface IsoTimestampValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_timestamp'; + /** + * The ISO timestamp regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a timestamp. diff --git a/library/src/validations/isoWeek/isoWeek.ts b/library/src/validations/isoWeek/isoWeek.ts index 20782cc2e..b63cb3168 100644 --- a/library/src/validations/isoWeek/isoWeek.ts +++ b/library/src/validations/isoWeek/isoWeek.ts @@ -5,17 +5,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ISO week validation type. */ -export type IsoWeekValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'iso_week'; - /** - * The ISO week regex. - */ - requirement: RegExp; - }; +export interface IsoWeekValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'iso_week'; + /** + * The ISO week regex. + */ + requirement: RegExp; +} /** * Creates a pipeline validation action that validates a week. diff --git a/library/src/validations/length/length.ts b/library/src/validations/length/length.ts index 853c3f17c..08a75d404 100644 --- a/library/src/validations/length/length.ts +++ b/library/src/validations/length/length.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Length validation type. */ -export type LengthValidation< +export interface LengthValidation< TInput extends string | any[], TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type LengthValidation< * The length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the length of a string diff --git a/library/src/validations/maxBytes/maxBytes.ts b/library/src/validations/maxBytes/maxBytes.ts index c5d927ec1..f131c3121 100644 --- a/library/src/validations/maxBytes/maxBytes.ts +++ b/library/src/validations/maxBytes/maxBytes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Max bytes validation type. */ -export type MaxBytesValidation< +export interface MaxBytesValidation< TInput extends string, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MaxBytesValidation< * The maximum byte length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the bytes of a string. diff --git a/library/src/validations/maxLength/maxLength.ts b/library/src/validations/maxLength/maxLength.ts index 1ddb32351..1f36a8892 100644 --- a/library/src/validations/maxLength/maxLength.ts +++ b/library/src/validations/maxLength/maxLength.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Max length validation type. */ -export type MaxLengthValidation< +export interface MaxLengthValidation< TInput extends string | any[], TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MaxLengthValidation< * The maximum length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the length of a string diff --git a/library/src/validations/maxSize/maxSize.ts b/library/src/validations/maxSize/maxSize.ts index 9232e0a35..26b71b51b 100644 --- a/library/src/validations/maxSize/maxSize.ts +++ b/library/src/validations/maxSize/maxSize.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Max size validation type. */ -export type MaxSizeValidation< +export interface MaxSizeValidation< TInput extends Map | Set | Blob, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MaxSizeValidation< * The maximum size. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the size of a map, set diff --git a/library/src/validations/maxValue/maxValue.ts b/library/src/validations/maxValue/maxValue.ts index cd1a0c46b..d0abf3f8c 100644 --- a/library/src/validations/maxValue/maxValue.ts +++ b/library/src/validations/maxValue/maxValue.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Max value validation type. */ -export type MaxValueValidation< +export interface MaxValueValidation< TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MaxValueValidation< * The maximum value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the value of a string, diff --git a/library/src/validations/mimeType/mimeType.ts b/library/src/validations/mimeType/mimeType.ts index 61c858f68..8e7278af7 100644 --- a/library/src/validations/mimeType/mimeType.ts +++ b/library/src/validations/mimeType/mimeType.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * MIME type validation type. */ -export type MimeTypeValidation< +export interface MimeTypeValidation< TInput extends Blob, TRequirement extends `${string}/${string}`[], -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MimeTypeValidation< * The MIME types. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the MIME type of a blob. diff --git a/library/src/validations/minBytes/minBytes.ts b/library/src/validations/minBytes/minBytes.ts index 6edb6a172..b373e8178 100644 --- a/library/src/validations/minBytes/minBytes.ts +++ b/library/src/validations/minBytes/minBytes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Min bytes validation type. */ -export type MinBytesValidation< +export interface MinBytesValidation< TInput extends string, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MinBytesValidation< * The minimum byte length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the bytes of a string. diff --git a/library/src/validations/minLength/minLength.ts b/library/src/validations/minLength/minLength.ts index d9e8e768d..9cfef0f4a 100644 --- a/library/src/validations/minLength/minLength.ts +++ b/library/src/validations/minLength/minLength.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Min length validation type. */ -export type MinLengthValidation< +export interface MinLengthValidation< TInput extends string | any[], TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MinLengthValidation< * The minimum length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the length of a string diff --git a/library/src/validations/minSize/minSize.ts b/library/src/validations/minSize/minSize.ts index 8bc76dfa3..d10c6ebc2 100644 --- a/library/src/validations/minSize/minSize.ts +++ b/library/src/validations/minSize/minSize.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Min size validation type. */ -export type MinSizeValidation< +export interface MinSizeValidation< TInput extends Map | Set | Blob, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MinSizeValidation< * The minimum size. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the size of a map, set diff --git a/library/src/validations/minValue/minValue.ts b/library/src/validations/minValue/minValue.ts index 9efb57886..4dbdfa6c2 100644 --- a/library/src/validations/minValue/minValue.ts +++ b/library/src/validations/minValue/minValue.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Min value validation type. */ -export type MinValueValidation< +export interface MinValueValidation< TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MinValueValidation< * The minimum value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the value of a string, diff --git a/library/src/validations/multipleOf/multipleOf.ts b/library/src/validations/multipleOf/multipleOf.ts index 16a059b02..645a5e267 100644 --- a/library/src/validations/multipleOf/multipleOf.ts +++ b/library/src/validations/multipleOf/multipleOf.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Multiple of validation type. */ -export type MultipleOfValidation< +export interface MultipleOfValidation< TInput extends number, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type MultipleOfValidation< * The divisor. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates whether a number is a diff --git a/library/src/validations/notBytes/notBytes.ts b/library/src/validations/notBytes/notBytes.ts index 8a54a9edb..b8e140bc1 100644 --- a/library/src/validations/notBytes/notBytes.ts +++ b/library/src/validations/notBytes/notBytes.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Not bytes validation type. */ -export type NotBytesValidation< +export interface NotBytesValidation< TInput extends string, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type NotBytesValidation< * The byte length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the bytes of a string. diff --git a/library/src/validations/notLength/notLength.ts b/library/src/validations/notLength/notLength.ts index c56a2cf9a..d218885f4 100644 --- a/library/src/validations/notLength/notLength.ts +++ b/library/src/validations/notLength/notLength.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Not length validation type. */ -export type NotLengthValidation< +export interface NotLengthValidation< TInput extends string | any[], TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type NotLengthValidation< * The length. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the length of a string diff --git a/library/src/validations/notSize/notSize.ts b/library/src/validations/notSize/notSize.ts index 76b320c4b..542113a5e 100644 --- a/library/src/validations/notSize/notSize.ts +++ b/library/src/validations/notSize/notSize.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Not size validation type. */ -export type NotSizeValidation< +export interface NotSizeValidation< TInput extends Map | Set | Blob, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type NotSizeValidation< * The size. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the size of a map, set diff --git a/library/src/validations/notValue/notValue.ts b/library/src/validations/notValue/notValue.ts index d4f07f12e..5dc35a87e 100644 --- a/library/src/validations/notValue/notValue.ts +++ b/library/src/validations/notValue/notValue.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Not value validation type. */ -export type NotValueValidation< +export interface NotValueValidation< TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type NotValueValidation< * The value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the value of a string diff --git a/library/src/validations/regex/regex.ts b/library/src/validations/regex/regex.ts index cfcb20ee3..d01f251ae 100644 --- a/library/src/validations/regex/regex.ts +++ b/library/src/validations/regex/regex.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Regex validation type. */ -export type RegexValidation = BaseValidation & { +export interface RegexValidation + extends BaseValidation { /** * The validation type. */ @@ -13,7 +14,7 @@ export type RegexValidation = BaseValidation & { * The regex pattern. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates a string with a regex. diff --git a/library/src/validations/safeInteger/safeInteger.ts b/library/src/validations/safeInteger/safeInteger.ts index 83582f801..a30c57d96 100644 --- a/library/src/validations/safeInteger/safeInteger.ts +++ b/library/src/validations/safeInteger/safeInteger.ts @@ -4,17 +4,17 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Safe integer validation type. */ -export type SafeIntegerValidation = - BaseValidation & { - /** - * The validation type. - */ - type: 'safe_integer'; - /** - * The validation function. - */ - requirement: (input: TInput) => boolean; - }; +export interface SafeIntegerValidation + extends BaseValidation { + /** + * The validation type. + */ + type: 'safe_integer'; + /** + * The validation function. + */ + requirement: (input: TInput) => boolean; +} /** * Creates a pipeline validation action that validates whether a number is a diff --git a/library/src/validations/size/size.ts b/library/src/validations/size/size.ts index 0e20ce3a0..31a9aa738 100644 --- a/library/src/validations/size/size.ts +++ b/library/src/validations/size/size.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Size validation type. */ -export type SizeValidation< +export interface SizeValidation< TInput extends Map | Set | Blob, TRequirement extends number, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type SizeValidation< * The size. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the size of a map, set diff --git a/library/src/validations/some/some.ts b/library/src/validations/some/some.ts index 39d1c4732..73a496c02 100644 --- a/library/src/validations/some/some.ts +++ b/library/src/validations/some/some.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Some validation type. */ -export type SomeValidation = BaseValidation & { +export interface SomeValidation + extends BaseValidation { /** * The validation type. */ @@ -17,7 +18,7 @@ export type SomeValidation = BaseValidation & { index: number, array: TInput[number][] ) => boolean; -}; +} /** * Creates a pipeline validation action that validates the items of an array. diff --git a/library/src/validations/startsWith/startsWith.ts b/library/src/validations/startsWith/startsWith.ts index 1b78894db..fa75e234b 100644 --- a/library/src/validations/startsWith/startsWith.ts +++ b/library/src/validations/startsWith/startsWith.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * Starts with validation type. */ -export type StartsWithValidation< +export interface StartsWithValidation< TInput extends string, TRequirement extends string, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type StartsWithValidation< * The start string. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the start of a string. diff --git a/library/src/validations/ulid/ulid.ts b/library/src/validations/ulid/ulid.ts index c4db8a2ec..a92009f44 100644 --- a/library/src/validations/ulid/ulid.ts +++ b/library/src/validations/ulid/ulid.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * ULID validation type. */ -export type UlidValidation = BaseValidation & { +export interface UlidValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type UlidValidation = BaseValidation & { * The ULID regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates a [ULID](https://github.com/ulid/spec). diff --git a/library/src/validations/url/url.ts b/library/src/validations/url/url.ts index 63b5ee401..dce30bc3e 100644 --- a/library/src/validations/url/url.ts +++ b/library/src/validations/url/url.ts @@ -4,7 +4,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * URL validation type. */ -export type UrlValidation = BaseValidation & { +export interface UrlValidation + extends BaseValidation { /** * The validation type. */ @@ -13,7 +14,7 @@ export type UrlValidation = BaseValidation & { * The validation function. */ requirement: (input: TInput) => boolean; -}; +} /** * Creates a pipeline validation action that validates a URL. diff --git a/library/src/validations/uuid/uuid.ts b/library/src/validations/uuid/uuid.ts index 3ddc8859e..6e841fe5c 100644 --- a/library/src/validations/uuid/uuid.ts +++ b/library/src/validations/uuid/uuid.ts @@ -5,7 +5,8 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; /** * UUID validation type. */ -export type UuidValidation = BaseValidation & { +export interface UuidValidation + extends BaseValidation { /** * The validation type. */ @@ -14,7 +15,7 @@ export type UuidValidation = BaseValidation & { * The UUID regex. */ requirement: RegExp; -}; +} /** * Creates a pipeline validation action that validates a [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier). diff --git a/library/src/validations/value/value.ts b/library/src/validations/value/value.ts index 177a68c05..d17d8ed39 100644 --- a/library/src/validations/value/value.ts +++ b/library/src/validations/value/value.ts @@ -4,10 +4,10 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; /** * Value validation type. */ -export type ValueValidation< +export interface ValueValidation< TInput extends string | number | bigint | boolean | Date, TRequirement extends TInput, -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type ValueValidation< * The value. */ requirement: TRequirement; -}; +} /** * Creates a pipeline validation action that validates the value of a string diff --git a/website/src/routes/api/(methods)/fallback/properties.ts b/website/src/routes/api/(methods)/fallback/properties.ts index 2c9887c3f..969337a80 100644 --- a/website/src/routes/api/(methods)/fallback/properties.ts +++ b/website/src/routes/api/(methods)/fallback/properties.ts @@ -12,45 +12,9 @@ export const properties: Record = { TFallback: { modifier: 'extends', type: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - { - type: 'function', - params: [ - { - type: { - type: 'custom', - name: 'FallbackInfo', - href: '../FallbackInfo/', - }, - name: 'info', - optional: true, - }, - ], - return: { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - }, - ], + type: 'custom', + name: 'Fallback', + href: '../Fallback/', }, }, schema: { diff --git a/website/src/routes/api/(schemas)/nullable/properties.ts b/website/src/routes/api/(schemas)/nullable/properties.ts index a69376abc..8016a7c28 100644 --- a/website/src/routes/api/(schemas)/nullable/properties.ts +++ b/website/src/routes/api/(schemas)/nullable/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, + name: 'TWrapped', }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(schemas)/nullish/properties.ts b/website/src/routes/api/(schemas)/nullish/properties.ts index 2005ca990..aeed019f6 100644 --- a/website/src/routes/api/(schemas)/nullish/properties.ts +++ b/website/src/routes/api/(schemas)/nullish/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, + name: 'TWrapped', }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(schemas)/optional/properties.ts b/website/src/routes/api/(schemas)/optional/properties.ts index c0bef0aec..d4bc5061a 100644 --- a/website/src/routes/api/(schemas)/optional/properties.ts +++ b/website/src/routes/api/(schemas)/optional/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, + name: 'TWrapped', }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/Default/index.mdx b/website/src/routes/api/(types)/Default/index.mdx new file mode 100644 index 000000000..b11bc6d3a --- /dev/null +++ b/website/src/routes/api/(types)/Default/index.mdx @@ -0,0 +1,21 @@ +--- +title: Default +description: Default type. +contributors: + - fabian-hiller +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# Default + +Default type. + +## Generics + +- `TSchema` + +## Definition + +- `Default` diff --git a/website/src/routes/api/(types)/Default/properties.ts b/website/src/routes/api/(types)/Default/properties.ts new file mode 100644 index 000000000..9ed93024d --- /dev/null +++ b/website/src/routes/api/(types)/Default/properties.ts @@ -0,0 +1,53 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TSchema: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseSchema', + href: '../BaseSchema/', + }, + }, + Default: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Input', + href: '../Input/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'function', + params: [], + return: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Input', + href: '../Input/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + 'undefined', + ], + }, + }, + 'undefined', + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/DefaultAsync/index.mdx b/website/src/routes/api/(types)/DefaultAsync/index.mdx new file mode 100644 index 000000000..0e82f95d7 --- /dev/null +++ b/website/src/routes/api/(types)/DefaultAsync/index.mdx @@ -0,0 +1,21 @@ +--- +title: DefaultAsync +description: Default async type. +contributors: + - fabian-hiller +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# DefaultAsync + +Default async type. + +## Generics + +- `TSchema` + +## Definition + +- `DefaultAsync` diff --git a/website/src/routes/api/(types)/DefaultAsync/properties.ts b/website/src/routes/api/(types)/DefaultAsync/properties.ts new file mode 100644 index 000000000..3a491dc67 --- /dev/null +++ b/website/src/routes/api/(types)/DefaultAsync/properties.ts @@ -0,0 +1,76 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TSchema: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseSchema', + href: '../BaseSchema/', + }, + }, + DefaultAsync: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Input', + href: '../Input/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'function', + params: [], + return: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Input', + href: '../Input/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'custom', + name: 'Promise', + generics: [ + { + type: 'union', + options: [ + { + type: 'custom', + name: 'Input', + href: '../Input/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + 'undefined', + ], + }, + ], + }, + 'undefined', + ], + }, + }, + 'undefined', + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/Fallback/index.mdx b/website/src/routes/api/(types)/Fallback/index.mdx new file mode 100644 index 000000000..e7f2e2765 --- /dev/null +++ b/website/src/routes/api/(types)/Fallback/index.mdx @@ -0,0 +1,21 @@ +--- +title: Fallback +description: Fallback type. +contributors: + - fabian-hiller +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# Fallback + +Fallback type. + +## Generics + +- `TSchema` + +## Definition + +- `Fallback` diff --git a/website/src/routes/api/(types)/Fallback/properties.ts b/website/src/routes/api/(types)/Fallback/properties.ts new file mode 100644 index 000000000..0aa56b849 --- /dev/null +++ b/website/src/routes/api/(types)/Fallback/properties.ts @@ -0,0 +1,56 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TSchema: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseSchema', + href: '../BaseSchema/', + }, + }, + Fallback: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Output', + href: '../Output/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'function', + params: [ + { + type: { + type: 'custom', + name: 'FallbackInfo', + href: '../FallbackInfo/', + }, + name: 'info', + optional: true, + }, + ], + return: { + type: 'custom', + name: 'Output', + href: '../Output/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/FallbackAsync/index.mdx b/website/src/routes/api/(types)/FallbackAsync/index.mdx new file mode 100644 index 000000000..18964f898 --- /dev/null +++ b/website/src/routes/api/(types)/FallbackAsync/index.mdx @@ -0,0 +1,21 @@ +--- +title: FallbackAsync +description: Fallback async type. +contributors: + - fabian-hiller +--- + +import { Property } from '~/components'; +import { properties } from './properties'; + +# FallbackAsync + +Fallback async type. + +## Generics + +- `TSchema` + +## Definition + +- `FallbackAsync` diff --git a/website/src/routes/api/(types)/FallbackAsync/properties.ts b/website/src/routes/api/(types)/FallbackAsync/properties.ts new file mode 100644 index 000000000..e6ed99dbc --- /dev/null +++ b/website/src/routes/api/(types)/FallbackAsync/properties.ts @@ -0,0 +1,78 @@ +import type { PropertyProps } from '~/components'; + +export const properties: Record = { + TSchema: { + modifier: 'extends', + type: { + type: 'custom', + name: 'BaseSchemaAsync', + href: '../BaseSchemaAsync/', + }, + }, + FallbackAsync: { + modifier: 'extends', + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Output', + href: '../Output/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'function', + params: [ + { + type: { + type: 'custom', + name: 'FallbackInfo', + href: '../FallbackInfo/', + }, + name: 'info', + optional: true, + }, + ], + return: { + type: 'union', + options: [ + { + type: 'custom', + name: 'Output', + href: '../Output/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + { + type: 'custom', + name: 'Promise', + generics: [ + { + type: 'custom', + name: 'Output', + href: '../Output/', + generics: [ + { + type: 'custom', + name: 'TSchema', + }, + ], + }, + ], + }, + ], + }, + }, + ], + }, + }, +}; diff --git a/website/src/routes/api/(types)/NullableSchema/properties.ts b/website/src/routes/api/(types)/NullableSchema/properties.ts index 322230320..a83441f7d 100644 --- a/website/src/routes/api/(types)/NullableSchema/properties.ts +++ b/website/src/routes/api/(types)/NullableSchema/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, + name: 'TWrapped', }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/NullableSchemaAsync/properties.ts b/website/src/routes/api/(types)/NullableSchemaAsync/properties.ts index 6f9dcdd3e..0c9590a30 100644 --- a/website/src/routes/api/(types)/NullableSchemaAsync/properties.ts +++ b/website/src/routes/api/(types)/NullableSchemaAsync/properties.ts @@ -22,59 +22,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'DefaultAsync', + href: '../DefaultAsync/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'custom', - name: 'Promise', - generics: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, - 'undefined', - ], - }, + name: 'TWrapped', }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/NullishSchema/properties.ts b/website/src/routes/api/(types)/NullishSchema/properties.ts index eba142724..80c9e67a4 100644 --- a/website/src/routes/api/(types)/NullishSchema/properties.ts +++ b/website/src/routes/api/(types)/NullishSchema/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], + name: 'TWrapped', }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, - }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/NullishSchemaAsync/properties.ts b/website/src/routes/api/(types)/NullishSchemaAsync/properties.ts index b4668b22e..c15fc0af9 100644 --- a/website/src/routes/api/(types)/NullishSchemaAsync/properties.ts +++ b/website/src/routes/api/(types)/NullishSchemaAsync/properties.ts @@ -22,59 +22,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'DefaultAsync', + href: '../DefaultAsync/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], + name: 'TWrapped', }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'custom', - name: 'Promise', - generics: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, - 'undefined', - ], - }, - }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/OptionalSchema/properties.ts b/website/src/routes/api/(types)/OptionalSchema/properties.ts index 672a6af5f..87edd73ef 100644 --- a/website/src/routes/api/(types)/OptionalSchema/properties.ts +++ b/website/src/routes/api/(types)/OptionalSchema/properties.ts @@ -12,41 +12,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Default', + href: '../Default/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], + name: 'TWrapped', }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, - }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/OptionalSchemaAsync/properties.ts b/website/src/routes/api/(types)/OptionalSchemaAsync/properties.ts index 2c6265204..8243ef567 100644 --- a/website/src/routes/api/(types)/OptionalSchemaAsync/properties.ts +++ b/website/src/routes/api/(types)/OptionalSchemaAsync/properties.ts @@ -22,59 +22,14 @@ export const properties: Record = { TDefault: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'DefaultAsync', + href: '../DefaultAsync/', + generics: [ { type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], + name: 'TWrapped', }, - { - type: 'function', - params: [], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - { - type: 'custom', - name: 'Promise', - generics: [ - { - type: 'custom', - name: 'Input', - href: '../Input/', - generics: [ - { - type: 'custom', - name: 'TWrapped', - }, - ], - }, - 'undefined', - ], - }, - 'undefined', - ], - }, - }, - 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/SchemaWithFallback/properties.ts b/website/src/routes/api/(types)/SchemaWithFallback/properties.ts index 86cebbb83..10e885c12 100644 --- a/website/src/routes/api/(types)/SchemaWithFallback/properties.ts +++ b/website/src/routes/api/(types)/SchemaWithFallback/properties.ts @@ -8,53 +8,29 @@ export const properties: Record = { name: 'BaseSchema', href: '../BaseSchema/', }, + default: { + type: 'custom', + name: 'BaseSchema', + href: '../BaseSchema/', + }, }, TFallback: { modifier: 'extends', type: { - type: 'union', - options: [ + type: 'custom', + name: 'Fallback', + href: '../Fallback/', + generics: [ { type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - { - type: 'function', - params: [ - { - name: 'info', - type: { - type: 'custom', - name: 'FallbackInfo', - href: '../FallbackInfo/', - }, - }, - ], - return: { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, + name: 'TSchema', }, ], }, default: { type: 'custom', - name: 'Output', - href: '../Output/', + name: 'Fallback', + href: '../Fallback/', generics: [ { type: 'custom', diff --git a/website/src/routes/api/(types)/SchemaWithMaybeFallback/index.mdx b/website/src/routes/api/(types)/SchemaWithMaybeFallback/index.mdx index 6744c6a85..23d8da8a8 100644 --- a/website/src/routes/api/(types)/SchemaWithMaybeFallback/index.mdx +++ b/website/src/routes/api/(types)/SchemaWithMaybeFallback/index.mdx @@ -15,7 +15,9 @@ Schema with maybe fallback type. ## Generics - `TSchema` +- `TFallback` ## Definition -- `SchemaWithMaybeFallback` +- `SchemaWithMaybeFallback` + - `fallback` diff --git a/website/src/routes/api/(types)/SchemaWithMaybeFallback/properties.ts b/website/src/routes/api/(types)/SchemaWithMaybeFallback/properties.ts index 545467966..1e19bc09b 100644 --- a/website/src/routes/api/(types)/SchemaWithMaybeFallback/properties.ts +++ b/website/src/routes/api/(types)/SchemaWithMaybeFallback/properties.ts @@ -14,64 +14,46 @@ export const properties: Record = { href: '../BaseSchema/', }, }, - SchemaWithMaybeFallback: { + TFallback: { + modifier: 'extends', type: { - type: 'intersect', - options: [ + type: 'custom', + name: 'Fallback', + href: '../Fallback/', + generics: [ { type: 'custom', name: 'TSchema', }, + ], + }, + default: { + type: 'custom', + name: 'Fallback', + href: '../Fallback/', + generics: [ { - type: 'object', - entries: [ - { - key: 'fallback', - optional: true, - value: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - { - type: 'function', - params: [ - { - name: 'info', - optional: true, - type: { - type: 'custom', - name: 'FallbackInfo', - href: '../FallbackInfo/', - }, - }, - ], - return: { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - }, - ], - }, - }, - ], + type: 'custom', + name: 'TSchema', + }, + ], + }, + }, + BaseSchema: { + type: { + type: 'custom', + name: 'TSchema', + }, + }, + fallback: { + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'TFallback', }, + 'undefined', ], }, }, diff --git a/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/index.mdx b/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/index.mdx index b46247666..1972d10d2 100644 --- a/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/index.mdx +++ b/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/index.mdx @@ -15,7 +15,9 @@ Schema with maybe fallback async type. ## Generics - `TSchema` +- `TFallback` ## Definition -- `SchemaWithMaybeFallbackAsync` +- `SchemaWithMaybeFallbackAsync` + - `fallback` diff --git a/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/properties.ts b/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/properties.ts index e2db08465..51a6070b4 100644 --- a/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/properties.ts +++ b/website/src/routes/api/(types)/SchemaWithMaybeFallbackAsync/properties.ts @@ -14,86 +14,46 @@ export const properties: Record = { href: '../BaseSchemaAsync/', }, }, - SchemaWithMaybeFallbackAsync: { + TFallback: { + modifier: 'extends', type: { - type: 'intersect', - options: [ + type: 'custom', + name: 'FallbackAsync', + href: '../FallbackAsync/', + generics: [ { type: 'custom', name: 'TSchema', }, + ], + }, + default: { + type: 'custom', + name: 'FallbackAsync', + href: '../FallbackAsync/', + generics: [ { - type: 'object', - entries: [ - { - key: 'fallback', - optional: true, - value: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - { - type: 'function', - params: [ - { - name: 'info', - optional: true, - type: { - type: 'custom', - name: 'FallbackInfo', - href: '../FallbackInfo/', - }, - }, - ], - return: { - type: 'union', - options: [ - { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - { - type: 'custom', - name: 'Promise', - generics: [ - { - type: 'custom', - name: 'Output', - href: '../Output/', - generics: [ - { - type: 'custom', - name: 'TSchema', - }, - ], - }, - ], - }, - ], - }, - }, - ], - }, - }, - ], + type: 'custom', + name: 'TSchema', + }, + ], + }, + }, + BaseSchema: { + type: { + type: 'custom', + name: 'TSchema', + }, + }, + fallback: { + type: { + type: 'union', + options: [ + { + type: 'custom', + name: 'TFallback', }, + 'undefined', ], }, }, diff --git a/website/src/routes/api/menu.md b/website/src/routes/api/menu.md index 8712320d4..435372c9d 100644 --- a/website/src/routes/api/menu.md +++ b/website/src/routes/api/menu.md @@ -228,6 +228,8 @@ - [CustomValidation](/api/CustomValidation/) - [DateSchema](/api/DateSchema/) - [DecimalValidation](/api/DecimalValidation/) +- [Default](/api/Default/) +- [DefaultAsync](/api/DefaultAsync/) - [DefaultValue](/api/DefaultValue/) - [DefaultValues](/api/DefaultValues/) - [EmailValidation](/api/EmailValidation/) @@ -239,6 +241,8 @@ - [ErrorMessage](/api/ErrorMessage/) - [EveryValidation](/api/EveryValidation/) - [ExcludesValidation](/api/ExcludesValidation/) +- [Fallback](/api/Fallback/) +- [FallbackAsync](/api/FallbackAsync/) - [FallbackInfo](/api/FallbackInfo/) - [FallbackValue](/api/FallbackValue/) - [FallbackValues](/api/FallbackValues/)