From fd869877e5071db0a557b7d27708d4e575895336 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Sun, 19 Nov 2023 08:43:17 -0800 Subject: [PATCH 01/21] Use `interface` instead of `type` for all Base types --- library/src/schemas/any/any.ts | 4 +- library/src/schemas/any/anyAsync.ts | 5 ++- library/src/schemas/array/array.ts | 6 +-- library/src/schemas/array/arrayAsync.ts | 6 +-- library/src/schemas/bigint/bigint.ts | 5 ++- library/src/schemas/bigint/bigintAsync.ts | 8 ++-- library/src/schemas/blob/blob.ts | 4 +- library/src/schemas/blob/blobAsync.ts | 5 ++- library/src/schemas/boolean/boolean.ts | 5 ++- library/src/schemas/boolean/booleanAsync.ts | 8 ++-- library/src/schemas/date/date.ts | 4 +- library/src/schemas/date/dateAsync.ts | 5 ++- library/src/schemas/enum/enum.ts | 8 ++-- library/src/schemas/enum/enumAsync.ts | 6 +-- library/src/schemas/instance/instance.ts | 6 +-- library/src/schemas/instance/instanceAsync.ts | 6 +-- library/src/schemas/intersect/intersect.ts | 6 +-- .../src/schemas/intersect/intersectAsync.ts | 6 +-- library/src/schemas/literal/literal.ts | 8 ++-- library/src/schemas/literal/literalAsync.ts | 6 +-- library/src/schemas/map/map.ts | 6 +-- library/src/schemas/map/mapAsync.ts | 6 +-- library/src/schemas/nan/nan.ts | 5 ++- library/src/schemas/nan/nanAsync.ts | 8 ++-- library/src/schemas/never/never.ts | 4 +- library/src/schemas/never/neverAsync.ts | 4 +- .../src/schemas/nonNullable/nonNullable.ts | 6 +-- .../schemas/nonNullable/nonNullableAsync.ts | 6 +-- library/src/schemas/nonNullish/nonNullish.ts | 6 +-- .../src/schemas/nonNullish/nonNullishAsync.ts | 6 +-- .../src/schemas/nonOptional/nonOptional.ts | 6 +-- .../schemas/nonOptional/nonOptionalAsync.ts | 6 +-- library/src/schemas/null/null.ts | 4 +- library/src/schemas/null/nullAsync.ts | 5 ++- library/src/schemas/nullable/nullable.ts | 6 +-- library/src/schemas/nullable/nullableAsync.ts | 6 +-- library/src/schemas/nullish/nullish.ts | 6 +-- library/src/schemas/nullish/nullishAsync.ts | 6 +-- library/src/schemas/number/number.ts | 5 ++- library/src/schemas/number/numberAsync.ts | 8 ++-- library/src/schemas/object/object.ts | 6 +-- library/src/schemas/object/objectAsync.ts | 6 +-- library/src/schemas/optional/optional.ts | 6 +-- library/src/schemas/optional/optionalAsync.ts | 6 +-- library/src/schemas/picklist/picklist.ts | 6 +-- library/src/schemas/picklist/picklistAsync.ts | 6 +-- library/src/schemas/record/record.ts | 6 +-- library/src/schemas/record/recordAsync.ts | 6 +-- library/src/schemas/recursive/recursive.ts | 6 +-- .../src/schemas/recursive/recursiveAsync.ts | 6 +-- library/src/schemas/set/set.ts | 6 +-- library/src/schemas/set/setAsync.ts | 6 +-- library/src/schemas/special/special.ts | 8 ++-- library/src/schemas/special/specialAsync.ts | 8 ++-- library/src/schemas/string/string.ts | 5 ++- library/src/schemas/string/stringAsync.ts | 8 ++-- library/src/schemas/symbol/symbol.ts | 5 ++- library/src/schemas/symbol/symbolAsync.ts | 8 ++-- library/src/schemas/tuple/tuple.ts | 6 +-- library/src/schemas/tuple/tupleAsync.ts | 6 +-- library/src/schemas/undefined/undefined.ts | 8 ++-- .../src/schemas/undefined/undefinedAsync.ts | 8 ++-- library/src/schemas/union/union.ts | 6 +-- library/src/schemas/union/unionAsync.ts | 6 +-- library/src/schemas/unknown/unknown.ts | 5 ++- library/src/schemas/unknown/unknownAsync.ts | 8 ++-- library/src/schemas/variant/variant.ts | 6 +-- library/src/schemas/variant/variantAsync.ts | 6 +-- library/src/schemas/void/void.ts | 4 +- library/src/schemas/void/voidAsync.ts | 5 ++- .../src/transformations/toCustom/toCustom.ts | 5 ++- .../transformations/toCustom/toCustomAsync.ts | 14 +++---- .../toLowerCase/toLowerCase.ts | 4 +- .../transformations/toMaxValue/toMaxValue.ts | 6 +-- .../transformations/toMinValue/toMinValue.ts | 6 +-- .../transformations/toTrimmed/toTrimmed.ts | 4 +- .../toTrimmedEnd/toTrimmedEnd.ts | 4 +- .../toTrimmedStart/toTrimmedStart.ts | 5 ++- .../toUpperCase/toUpperCase.ts | 4 +- library/src/types/pipe.ts | 40 +++++++++++++++---- library/src/types/schema.ts | 16 ++++++-- library/src/validations/bytes/bytes.ts | 6 +-- library/src/validations/cuid2/cuid2.ts | 5 ++- library/src/validations/custom/custom.ts | 4 +- library/src/validations/custom/customAsync.ts | 5 ++- library/src/validations/email/email.ts | 5 ++- library/src/validations/emoji/emoji.ts | 5 ++- library/src/validations/endsWith/endsWith.ts | 6 +-- library/src/validations/equal/equal.ts | 6 +-- library/src/validations/excludes/excludes.ts | 6 +-- library/src/validations/finite/finite.ts | 5 ++- library/src/validations/imei/imei.ts | 5 ++- library/src/validations/includes/includes.ts | 6 +-- library/src/validations/integer/integer.ts | 22 +++++----- library/src/validations/ip/ip.ts | 5 ++- library/src/validations/ipv4/ipv4.ts | 5 ++- library/src/validations/ipv6/ipv6.ts | 5 ++- library/src/validations/isoDate/isoDate.ts | 22 +++++----- .../validations/isoDateTime/isoDateTime.ts | 22 +++++----- library/src/validations/isoTime/isoTime.ts | 22 +++++----- .../isoTimeSecond/isoTimeSecond.ts | 22 +++++----- .../validations/isoTimestamp/isoTimestamp.ts | 22 +++++----- library/src/validations/isoWeek/isoWeek.ts | 22 +++++----- library/src/validations/length/length.ts | 6 +-- library/src/validations/maxBytes/maxBytes.ts | 6 +-- .../src/validations/maxLength/maxLength.ts | 6 +-- library/src/validations/maxSize/maxSize.ts | 6 +-- library/src/validations/maxValue/maxValue.ts | 6 +-- library/src/validations/mimeType/mimeType.ts | 6 +-- library/src/validations/minBytes/minBytes.ts | 6 +-- .../src/validations/minLength/minLength.ts | 6 +-- library/src/validations/minSize/minSize.ts | 6 +-- library/src/validations/minValue/minValue.ts | 6 +-- .../src/validations/multipleOf/multipleOf.ts | 6 +-- library/src/validations/notBytes/notBytes.ts | 6 +-- .../src/validations/notLength/notLength.ts | 6 +-- library/src/validations/notSize/notSize.ts | 6 +-- library/src/validations/notValue/notValue.ts | 6 +-- library/src/validations/regex/regex.ts | 5 ++- .../validations/safeInteger/safeInteger.ts | 22 +++++----- library/src/validations/size/size.ts | 6 +-- .../src/validations/startsWith/startsWith.ts | 6 +-- library/src/validations/ulid/ulid.ts | 5 ++- library/src/validations/url/url.ts | 5 ++- library/src/validations/uuid/uuid.ts | 5 ++- library/src/validations/value/value.ts | 6 +-- 126 files changed, 472 insertions(+), 439 deletions(-) diff --git a/library/src/schemas/any/any.ts b/library/src/schemas/any/any.ts index 1506b7576..45bba1b9c 100644 --- a/library/src/schemas/any/any.ts +++ b/library/src/schemas/any/any.ts @@ -4,7 +4,7 @@ import { executePipe } 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 a any schema. diff --git a/library/src/schemas/any/anyAsync.ts b/library/src/schemas/any/anyAsync.ts index 03648a964..4a8cf74c1 100644 --- a/library/src/schemas/any/anyAsync.ts +++ b/library/src/schemas/any/anyAsync.ts @@ -4,7 +4,8 @@ import { executePipeAsync } 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 7c68a0b32..27d85c637 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 f934e1b04..17bd96f4f 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 b5ede783e..a2f492688 100644 --- a/library/src/schemas/bigint/bigint.ts +++ b/library/src/schemas/bigint/bigint.ts @@ -8,7 +8,8 @@ import { /** * Bigint schema type. */ -export type BigintSchema = BaseSchema & { +export interface BigintSchema + extends BaseSchema { /** * The schema type. */ @@ -21,7 +22,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 9cb541a2a..f61d33762 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 c47fa5ba1..bf9066f22 100644 --- a/library/src/schemas/blob/blob.ts +++ b/library/src/schemas/blob/blob.ts @@ -8,7 +8,7 @@ import { /** * Blob schema type. */ -export type BlobSchema = BaseSchema & { +export interface BlobSchema extends BaseSchema { /** * The schema type. */ @@ -21,7 +21,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 355da23f7..c18c15027 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 8edd4758a..98932219d 100644 --- a/library/src/schemas/boolean/boolean.ts +++ b/library/src/schemas/boolean/boolean.ts @@ -8,7 +8,8 @@ import { /** * Boolean schema type. */ -export type BooleanSchema = BaseSchema & { +export interface BooleanSchema + extends BaseSchema { /** * The schema type. */ @@ -21,7 +22,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 a1952d9ff..82b2addc0 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 ec20f459b..aabe09caf 100644 --- a/library/src/schemas/date/date.ts +++ b/library/src/schemas/date/date.ts @@ -8,7 +8,7 @@ import { /** * Date schema type. */ -export type DateSchema = BaseSchema & { +export interface DateSchema extends BaseSchema { /** * The schema type. */ @@ -21,7 +21,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 ebcd2edb2..f95b506dc 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 f92c97b56..9700b55c3 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; -}; +} /** * Creates a enum schema. diff --git a/library/src/schemas/enum/enumAsync.ts b/library/src/schemas/enum/enumAsync.ts index 67bf76c23..90d00c59c 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; -}; +} /** * Creates an async enum schema. diff --git a/library/src/schemas/instance/instance.ts b/library/src/schemas/instance/instance.ts index a1f7384cd..4aeb4cd8f 100644 --- a/library/src/schemas/instance/instance.ts +++ b/library/src/schemas/instance/instance.ts @@ -13,10 +13,10 @@ export type Class = abstract new (...args: any) => any; /** * Instance schema type. */ -export type InstanceSchema< +export interface InstanceSchema< TClass extends Class, TOutput = InstanceType -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -33,7 +33,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 a18b03095..9929a6768 100644 --- a/library/src/schemas/instance/instanceAsync.ts +++ b/library/src/schemas/instance/instanceAsync.ts @@ -13,10 +13,10 @@ import { type Class } from './instance.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/intersect.ts b/library/src/schemas/intersect/intersect.ts index 3cb6a3d09..79b5b2024 100644 --- a/library/src/schemas/intersect/intersect.ts +++ b/library/src/schemas/intersect/intersect.ts @@ -11,10 +11,10 @@ export type IntersectOptions = [BaseSchema, BaseSchema, ...BaseSchema[]]; /** * Intersect schema type. */ -export type IntersectSchema< +export interface IntersectSchema< TOptions extends IntersectOptions, TOutput = IntersectOutput -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type IntersectSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an intersect schema. diff --git a/library/src/schemas/intersect/intersectAsync.ts b/library/src/schemas/intersect/intersectAsync.ts index 8ce220a14..64b91059d 100644 --- a/library/src/schemas/intersect/intersectAsync.ts +++ b/library/src/schemas/intersect/intersectAsync.ts @@ -20,10 +20,10 @@ export type IntersectOptionsAsync = [ /** * Intersect schema async type. */ -export type IntersectSchemaAsync< +export interface IntersectSchemaAsync< TOptions extends IntersectOptionsAsync, TOutput = IntersectOutput -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -36,7 +36,7 @@ export type IntersectSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an async intersect schema. diff --git a/library/src/schemas/literal/literal.ts b/library/src/schemas/literal/literal.ts index 06802db55..0b3ddd25b 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; -}; +} /** * Creates a literal schema. diff --git a/library/src/schemas/literal/literalAsync.ts b/library/src/schemas/literal/literalAsync.ts index 368789d90..2d79ac92b 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; -}; +} /** * Creates an async literal schema. diff --git a/library/src/schemas/map/map.ts b/library/src/schemas/map/map.ts index 68feea00a..15bfce29f 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 25952385b..60caa8020 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 8e2b492f9..e496839a7 100644 --- a/library/src/schemas/nan/nan.ts +++ b/library/src/schemas/nan/nan.ts @@ -4,7 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates a NaN schema. diff --git a/library/src/schemas/nan/nanAsync.ts b/library/src/schemas/nan/nanAsync.ts index daaa25972..24fe917fe 100644 --- a/library/src/schemas/nan/nanAsync.ts +++ b/library/src/schemas/nan/nanAsync.ts @@ -4,10 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates an async NaN schema. diff --git a/library/src/schemas/never/never.ts b/library/src/schemas/never/never.ts index 97385944d..398373169 100644 --- a/library/src/schemas/never/never.ts +++ b/library/src/schemas/never/never.ts @@ -4,7 +4,7 @@ import { getSchemaIssues } 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; -}; +} /** * Creates a never schema. diff --git a/library/src/schemas/never/neverAsync.ts b/library/src/schemas/never/neverAsync.ts index 4023ed8df..88704b0ef 100644 --- a/library/src/schemas/never/neverAsync.ts +++ b/library/src/schemas/never/neverAsync.ts @@ -4,7 +4,7 @@ import { getSchemaIssues } 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; -}; +} /** * Creates an async never schema. diff --git a/library/src/schemas/nonNullable/nonNullable.ts b/library/src/schemas/nonNullable/nonNullable.ts index d149e888f..78a15549b 100644 --- a/library/src/schemas/nonNullable/nonNullable.ts +++ b/library/src/schemas/nonNullable/nonNullable.ts @@ -14,10 +14,10 @@ export type NonNullable = T extends null ? never : T; /** * Non nullable schema type. */ -export type NonNullableSchema< +export interface NonNullableSchema< TWrapped extends BaseSchema, TOutput = NonNullable> -> = BaseSchema>, TOutput> & { +> extends BaseSchema>, TOutput> { /** * The schema type. */ @@ -30,7 +30,7 @@ export type NonNullableSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates a non nullable schema. diff --git a/library/src/schemas/nonNullable/nonNullableAsync.ts b/library/src/schemas/nonNullable/nonNullableAsync.ts index b9eb6c2ec..5096da31b 100644 --- a/library/src/schemas/nonNullable/nonNullableAsync.ts +++ b/library/src/schemas/nonNullable/nonNullableAsync.ts @@ -11,10 +11,10 @@ import type { NonNullable } from './nonNullable.ts'; /** * Non nullable schema async type. */ -export type NonNullableSchemaAsync< +export interface NonNullableSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonNullable> -> = BaseSchemaAsync>, TOutput> & { +> extends BaseSchemaAsync>, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type NonNullableSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an async non nullable schema. diff --git a/library/src/schemas/nonNullish/nonNullish.ts b/library/src/schemas/nonNullish/nonNullish.ts index 2644a0cac..29f8d809b 100644 --- a/library/src/schemas/nonNullish/nonNullish.ts +++ b/library/src/schemas/nonNullish/nonNullish.ts @@ -14,10 +14,10 @@ export type NonNullish = T extends null | undefined ? never : T; /** * Non nullish schema type. */ -export type NonNullishSchema< +export interface NonNullishSchema< TWrapped extends BaseSchema, TOutput = NonNullish> -> = BaseSchema>, TOutput> & { +> extends BaseSchema>, TOutput> { /** * The schema type. */ @@ -30,7 +30,7 @@ export type NonNullishSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates a non nullish schema. diff --git a/library/src/schemas/nonNullish/nonNullishAsync.ts b/library/src/schemas/nonNullish/nonNullishAsync.ts index c325f75f1..e08ed951b 100644 --- a/library/src/schemas/nonNullish/nonNullishAsync.ts +++ b/library/src/schemas/nonNullish/nonNullishAsync.ts @@ -11,10 +11,10 @@ import type { NonNullish } from './nonNullish.ts'; /** * Non nullish schema async type. */ -export type NonNullishSchemaAsync< +export interface NonNullishSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonNullish> -> = BaseSchemaAsync>, TOutput> & { +> extends BaseSchemaAsync>, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type NonNullishSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an async non nullish schema. diff --git a/library/src/schemas/nonOptional/nonOptional.ts b/library/src/schemas/nonOptional/nonOptional.ts index 5d7163181..9ae221866 100644 --- a/library/src/schemas/nonOptional/nonOptional.ts +++ b/library/src/schemas/nonOptional/nonOptional.ts @@ -14,10 +14,10 @@ export type NonOptional = T extends undefined ? never : T; /** * Non optional schema type. */ -export type NonOptionalSchema< +export interface NonOptionalSchema< TWrapped extends BaseSchema, TOutput = NonOptional> -> = BaseSchema>, TOutput> & { +> extends BaseSchema>, TOutput> { /** * The schema type. */ @@ -30,7 +30,7 @@ export type NonOptionalSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates a non optional schema. diff --git a/library/src/schemas/nonOptional/nonOptionalAsync.ts b/library/src/schemas/nonOptional/nonOptionalAsync.ts index e85bba606..dbcfaff9c 100644 --- a/library/src/schemas/nonOptional/nonOptionalAsync.ts +++ b/library/src/schemas/nonOptional/nonOptionalAsync.ts @@ -11,10 +11,10 @@ import type { NonOptional } from './nonOptional.ts'; /** * Non optional schema async type. */ -export type NonOptionalSchemaAsync< +export interface NonOptionalSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TOutput = NonOptional> -> = BaseSchemaAsync>, TOutput> & { +> extends BaseSchemaAsync>, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type NonOptionalSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an async non optional schema. diff --git a/library/src/schemas/null/null.ts b/library/src/schemas/null/null.ts index 0a4b35a89..591bdd8b1 100644 --- a/library/src/schemas/null/null.ts +++ b/library/src/schemas/null/null.ts @@ -4,7 +4,7 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates a null schema. diff --git a/library/src/schemas/null/nullAsync.ts b/library/src/schemas/null/nullAsync.ts index 7ef970675..578cf83ac 100644 --- a/library/src/schemas/null/nullAsync.ts +++ b/library/src/schemas/null/nullAsync.ts @@ -4,7 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates an async null schema. diff --git a/library/src/schemas/nullable/nullable.ts b/library/src/schemas/nullable/nullable.ts index 9e1e7d14c..770d081a9 100644 --- a/library/src/schemas/nullable/nullable.ts +++ b/library/src/schemas/nullable/nullable.ts @@ -5,7 +5,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Nullable schema type. */ -export type NullableSchema< +export interface NullableSchema< TWrapped extends BaseSchema, TDefault extends | Input @@ -14,7 +14,7 @@ export type NullableSchema< TOutput = TDefault extends Input ? Output : Output | null -> = BaseSchema | null, TOutput> & { +> extends BaseSchema | null, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type NullableSchema< * The default value. */ default: TDefault; -}; +} /** * Creates a nullable schema. diff --git a/library/src/schemas/nullable/nullableAsync.ts b/library/src/schemas/nullable/nullableAsync.ts index 2ef37f20c..1fa2f9186 100644 --- a/library/src/schemas/nullable/nullableAsync.ts +++ b/library/src/schemas/nullable/nullableAsync.ts @@ -10,7 +10,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Nullable schema async type. */ -export type NullableSchemaAsync< +export interface NullableSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TDefault extends | Input @@ -19,7 +19,7 @@ export type NullableSchemaAsync< TOutput = Awaited extends Input ? Output : Output | null -> = BaseSchemaAsync | null, TOutput> & { +> extends BaseSchemaAsync | null, TOutput> { /** * The schema type. */ @@ -32,7 +32,7 @@ export type NullableSchemaAsync< * Returns the default value. */ default: TDefault; -}; +} /** * Creates an async nullable schema. diff --git a/library/src/schemas/nullish/nullish.ts b/library/src/schemas/nullish/nullish.ts index cb872cad4..30b90bc1f 100644 --- a/library/src/schemas/nullish/nullish.ts +++ b/library/src/schemas/nullish/nullish.ts @@ -5,7 +5,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Nullish schema type. */ -export type NullishSchema< +export interface NullishSchema< TWrapped extends BaseSchema, TDefault extends | Input @@ -14,7 +14,7 @@ export type NullishSchema< TOutput = TDefault extends Input ? Output : Output | null | undefined -> = BaseSchema | null | undefined, TOutput> & { +> extends BaseSchema | null | undefined, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type NullishSchema< * Returns the default value. */ default: TDefault; -}; +} /** * Creates a nullish schema. diff --git a/library/src/schemas/nullish/nullishAsync.ts b/library/src/schemas/nullish/nullishAsync.ts index df2328cf0..a941f5e9e 100644 --- a/library/src/schemas/nullish/nullishAsync.ts +++ b/library/src/schemas/nullish/nullishAsync.ts @@ -10,7 +10,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Nullish schema async type. */ -export type NullishSchemaAsync< +export interface NullishSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TDefault extends | Input @@ -19,7 +19,7 @@ export type NullishSchemaAsync< TOutput = Awaited extends Input ? Output : Output | null | undefined -> = BaseSchemaAsync | null | undefined, TOutput> & { +> extends BaseSchemaAsync | null | undefined, TOutput> { /** * The schema type. */ @@ -32,7 +32,7 @@ export type NullishSchemaAsync< * Retutns the default value. */ default: TDefault; -}; +} /** * Creates an async nullish schema. diff --git a/library/src/schemas/number/number.ts b/library/src/schemas/number/number.ts index 1505e3d66..666f93b4c 100644 --- a/library/src/schemas/number/number.ts +++ b/library/src/schemas/number/number.ts @@ -8,7 +8,8 @@ import { /** * Number schema type. */ -export type NumberSchema = BaseSchema & { +export interface NumberSchema + extends BaseSchema { /** * The schema type. */ @@ -21,7 +22,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 e25275f1e..d6fea2740 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 6416341e9..9ac784442 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 ffd42a99e..fe9965b2d 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 b8b48a123..69811ab23 100644 --- a/library/src/schemas/optional/optional.ts +++ b/library/src/schemas/optional/optional.ts @@ -5,7 +5,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Optional schema type. */ -export type OptionalSchema< +export interface OptionalSchema< TWrapped extends BaseSchema, TDefault extends | Input @@ -14,7 +14,7 @@ export type OptionalSchema< TOutput = TDefault extends Input ? Output : Output | undefined -> = BaseSchema | undefined, TOutput> & { +> extends BaseSchema | undefined, TOutput> { /** * The schema type. */ @@ -27,7 +27,7 @@ export type OptionalSchema< * Returns the default value. */ default: TDefault; -}; +} /** * Creates a optional schema. diff --git a/library/src/schemas/optional/optionalAsync.ts b/library/src/schemas/optional/optionalAsync.ts index 6d4a44b52..b478e48cf 100644 --- a/library/src/schemas/optional/optionalAsync.ts +++ b/library/src/schemas/optional/optionalAsync.ts @@ -10,7 +10,7 @@ import { getOutput } from '../../utils/index.ts'; /** * Optional schema async type. */ -export type OptionalSchemaAsync< +export interface OptionalSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, TDefault extends | Input @@ -19,7 +19,7 @@ export type OptionalSchemaAsync< TOutput = Awaited extends Input ? Output : Output | undefined -> = BaseSchemaAsync | undefined, TOutput> & { +> extends BaseSchemaAsync | undefined, TOutput> { /** * The schema type. */ @@ -32,7 +32,7 @@ export type OptionalSchemaAsync< * Returns the default value. */ default: TDefault; -}; +} /** * Creates an async optional schema. diff --git a/library/src/schemas/picklist/picklist.ts b/library/src/schemas/picklist/picklist.ts index 40e2401c1..727b270e7 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; -}; +} /** * Creates a picklist schema. diff --git a/library/src/schemas/picklist/picklistAsync.ts b/library/src/schemas/picklist/picklistAsync.ts index 18e474629..51c6319e8 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; -}; +} /** * Creates an async picklist schema. diff --git a/library/src/schemas/record/record.ts b/library/src/schemas/record/record.ts index fb57fe948..c6fef5ae7 100644 --- a/library/src/schemas/record/record.ts +++ b/library/src/schemas/record/record.ts @@ -25,11 +25,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. */ @@ -50,7 +50,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 8ba29707e..0dbc3dddf 100644 --- a/library/src/schemas/record/recordAsync.ts +++ b/library/src/schemas/record/recordAsync.ts @@ -34,11 +34,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. */ @@ -59,7 +59,7 @@ export type RecordSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async record schema. diff --git a/library/src/schemas/recursive/recursive.ts b/library/src/schemas/recursive/recursive.ts index 98f64f63e..39591fe2f 100644 --- a/library/src/schemas/recursive/recursive.ts +++ b/library/src/schemas/recursive/recursive.ts @@ -3,10 +3,10 @@ import type { BaseSchema, Input, Output } from '../../types/index.ts'; /** * Recursive schema type. */ -export type RecursiveSchema< +export interface RecursiveSchema< TSchemaGetter extends () => BaseSchema, TOutput = Output> -> = BaseSchema>, TOutput> & { +> extends BaseSchema>, TOutput> { /** * The schema type. */ @@ -15,7 +15,7 @@ export type RecursiveSchema< * The schema getter. */ getter: TSchemaGetter; -}; +} /** * Creates a recursive schema. diff --git a/library/src/schemas/recursive/recursiveAsync.ts b/library/src/schemas/recursive/recursiveAsync.ts index 14547825e..b433e3ca7 100644 --- a/library/src/schemas/recursive/recursiveAsync.ts +++ b/library/src/schemas/recursive/recursiveAsync.ts @@ -8,10 +8,10 @@ import type { /** * Recursive schema async type. */ -export type RecursiveSchemaAsync< +export interface RecursiveSchemaAsync< TSchemaGetter extends () => BaseSchema | BaseSchemaAsync, TOutput = Output> -> = BaseSchemaAsync>, TOutput> & { +> extends BaseSchemaAsync>, TOutput> { /** * The schema type. */ @@ -20,7 +20,7 @@ export type RecursiveSchemaAsync< * The schema getter. */ getter: TSchemaGetter; -}; +} /** * Creates an async recursive schema. diff --git a/library/src/schemas/set/set.ts b/library/src/schemas/set/set.ts index 7e54123ce..1e3c7c5a2 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 1832d49a9..debd897eb 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 34f6731b9..502f7c4c4 100644 --- a/library/src/schemas/special/special.ts +++ b/library/src/schemas/special/special.ts @@ -8,10 +8,8 @@ import { /** * Special schema type. */ -export type SpecialSchema = BaseSchema< - TInput, - TOutput -> & { +export interface SpecialSchema + extends BaseSchema { /** * The schema type. */ @@ -28,7 +26,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 9b4fefc33..986663240 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 209b15111..385788197 100644 --- a/library/src/schemas/string/string.ts +++ b/library/src/schemas/string/string.ts @@ -8,7 +8,8 @@ import { /** * String schema type. */ -export type StringSchema = BaseSchema & { +export interface StringSchema + extends BaseSchema { /** * The schema type. */ @@ -21,7 +22,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 e868c3efc..1887febd2 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 3d97cf83b..917898916 100644 --- a/library/src/schemas/symbol/symbol.ts +++ b/library/src/schemas/symbol/symbol.ts @@ -4,7 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates a symbol schema. diff --git a/library/src/schemas/symbol/symbolAsync.ts b/library/src/schemas/symbol/symbolAsync.ts index f1358f631..fad48bb1d 100644 --- a/library/src/schemas/symbol/symbolAsync.ts +++ b/library/src/schemas/symbol/symbolAsync.ts @@ -4,10 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates an async symbol schema. diff --git a/library/src/schemas/tuple/tuple.ts b/library/src/schemas/tuple/tuple.ts index b2921c8a3..596f84d05 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 f04db6a09..68b5df86d 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 3438c4059..2d0a6d7ae 100644 --- a/library/src/schemas/undefined/undefined.ts +++ b/library/src/schemas/undefined/undefined.ts @@ -4,10 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates a undefined schema. diff --git a/library/src/schemas/undefined/undefinedAsync.ts b/library/src/schemas/undefined/undefinedAsync.ts index dcdaa362a..33bd08809 100644 --- a/library/src/schemas/undefined/undefinedAsync.ts +++ b/library/src/schemas/undefined/undefinedAsync.ts @@ -4,10 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates an async undefined schema. diff --git a/library/src/schemas/union/union.ts b/library/src/schemas/union/union.ts index e947d849f..a372e546d 100644 --- a/library/src/schemas/union/union.ts +++ b/library/src/schemas/union/union.ts @@ -15,10 +15,10 @@ export type UnionOptions = [BaseSchema, BaseSchema, ...BaseSchema[]]; /** * Union schema type. */ -export type UnionSchema< +export interface UnionSchema< TOptions extends UnionOptions, TOutput = Output -> = BaseSchema, TOutput> & { +> extends BaseSchema, TOutput> { /** * The schema type. */ @@ -31,7 +31,7 @@ export type UnionSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates a union schema. diff --git a/library/src/schemas/union/unionAsync.ts b/library/src/schemas/union/unionAsync.ts index 59557380a..b96c47853 100644 --- a/library/src/schemas/union/unionAsync.ts +++ b/library/src/schemas/union/unionAsync.ts @@ -20,10 +20,10 @@ export type UnionOptionsAsync = [ /** * Union schema async type. */ -export type UnionSchemaAsync< +export interface UnionSchemaAsync< TOptions extends UnionOptionsAsync, TOutput = Output -> = BaseSchemaAsync, TOutput> & { +> extends BaseSchemaAsync, TOutput> { /** * The schema type. */ @@ -36,7 +36,7 @@ export type UnionSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * Creates an async union schema. diff --git a/library/src/schemas/unknown/unknown.ts b/library/src/schemas/unknown/unknown.ts index a199270c8..2dec0f9c1 100644 --- a/library/src/schemas/unknown/unknown.ts +++ b/library/src/schemas/unknown/unknown.ts @@ -4,7 +4,8 @@ import { executePipe } 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 32b41b2d5..e061ffbb3 100644 --- a/library/src/schemas/unknown/unknownAsync.ts +++ b/library/src/schemas/unknown/unknownAsync.ts @@ -4,10 +4,8 @@ import { executePipeAsync } 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 7d29fb990..5ca8333ad 100644 --- a/library/src/schemas/variant/variant.ts +++ b/library/src/schemas/variant/variant.ts @@ -30,11 +30,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. */ @@ -51,7 +51,7 @@ export type VariantSchema< * The error message. */ message: ErrorMessage; -}; +} /** * Creates a variant (aka discriminated union) schema. diff --git a/library/src/schemas/variant/variantAsync.ts b/library/src/schemas/variant/variantAsync.ts index 6c540cab1..a46d9072f 100644 --- a/library/src/schemas/variant/variantAsync.ts +++ b/library/src/schemas/variant/variantAsync.ts @@ -32,11 +32,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. */ @@ -53,7 +53,7 @@ export type VariantSchemaAsync< * The error message. */ message: ErrorMessage; -}; +} /** * 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 026534154..f27cd01db 100644 --- a/library/src/schemas/void/void.ts +++ b/library/src/schemas/void/void.ts @@ -4,7 +4,7 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates a void schema. diff --git a/library/src/schemas/void/voidAsync.ts b/library/src/schemas/void/voidAsync.ts index f4409c8f6..34f2d3e56 100644 --- a/library/src/schemas/void/voidAsync.ts +++ b/library/src/schemas/void/voidAsync.ts @@ -4,7 +4,8 @@ import { getSchemaIssues, getOutput } 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; -}; +} /** * Creates an async void schema. diff --git a/library/src/transformations/toCustom/toCustom.ts b/library/src/transformations/toCustom/toCustom.ts index 28e288123..d15345bf3 100644 --- a/library/src/transformations/toCustom/toCustom.ts +++ b/library/src/transformations/toCustom/toCustom.ts @@ -4,12 +4,13 @@ import { getOutput } 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 transformation function. diff --git a/library/src/transformations/toCustom/toCustomAsync.ts b/library/src/transformations/toCustom/toCustomAsync.ts index 0c8c57ef3..44b637df4 100644 --- a/library/src/transformations/toCustom/toCustomAsync.ts +++ b/library/src/transformations/toCustom/toCustomAsync.ts @@ -4,13 +4,13 @@ import { getOutput } 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 dc2f3d1f1..10d9dc444 100644 --- a/library/src/transformations/toLowerCase/toLowerCase.ts +++ b/library/src/transformations/toLowerCase/toLowerCase.ts @@ -4,12 +4,12 @@ import { getOutput } 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 transformation function that converts all the alphabetic diff --git a/library/src/transformations/toMaxValue/toMaxValue.ts b/library/src/transformations/toMaxValue/toMaxValue.ts index 175036b29..92df502f5 100644 --- a/library/src/transformations/toMaxValue/toMaxValue.ts +++ b/library/src/transformations/toMaxValue/toMaxValue.ts @@ -4,10 +4,10 @@ import { getOutput } 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 transformation function that sets a string, number or date to a diff --git a/library/src/transformations/toMinValue/toMinValue.ts b/library/src/transformations/toMinValue/toMinValue.ts index 2d3d0943d..20c63e08d 100644 --- a/library/src/transformations/toMinValue/toMinValue.ts +++ b/library/src/transformations/toMinValue/toMinValue.ts @@ -4,10 +4,10 @@ import { getOutput } 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 transformation function that sets a string, number or date to a diff --git a/library/src/transformations/toTrimmed/toTrimmed.ts b/library/src/transformations/toTrimmed/toTrimmed.ts index c8b162f12..9bbfa8c77 100644 --- a/library/src/transformations/toTrimmed/toTrimmed.ts +++ b/library/src/transformations/toTrimmed/toTrimmed.ts @@ -4,12 +4,12 @@ import { getOutput } 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 transformation function that removes the leading and trailing diff --git a/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts b/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts index ce42ba4f4..0112633ad 100644 --- a/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts +++ b/library/src/transformations/toTrimmedEnd/toTrimmedEnd.ts @@ -4,12 +4,12 @@ import { getOutput } 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 transformation function that removes the trailing white space and diff --git a/library/src/transformations/toTrimmedStart/toTrimmedStart.ts b/library/src/transformations/toTrimmedStart/toTrimmedStart.ts index cd878cd28..d52fe8bd9 100644 --- a/library/src/transformations/toTrimmedStart/toTrimmedStart.ts +++ b/library/src/transformations/toTrimmedStart/toTrimmedStart.ts @@ -4,12 +4,13 @@ import { getOutput } 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 transformation function that removes the leading white space and diff --git a/library/src/transformations/toUpperCase/toUpperCase.ts b/library/src/transformations/toUpperCase/toUpperCase.ts index 39956f94b..005916cac 100644 --- a/library/src/transformations/toUpperCase/toUpperCase.ts +++ b/library/src/transformations/toUpperCase/toUpperCase.ts @@ -4,12 +4,12 @@ import { getOutput } 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 transformation function that converts all the alphabetic diff --git a/library/src/types/pipe.ts b/library/src/types/pipe.ts index e6c4c12ea..220bcd147 100644 --- a/library/src/types/pipe.ts +++ b/library/src/types/pipe.ts @@ -35,7 +35,11 @@ export type PipeResult = /** * Base validation type. */ -export type BaseValidation = { +export interface BaseValidation { + /** + * The validation type. + */ + type: string; /** * Whether it's async. */ @@ -44,6 +48,10 @@ export type BaseValidation = { * The error message. */ message: ErrorMessage; + /** + * The validation requirement. + */ + requirement: unknown; /** * Parses unknown input based on its requirement. * @@ -54,12 +62,16 @@ export type BaseValidation = { * @internal */ _parse(input: TInput): PipeResult; -}; +} /** * Base validation async type. */ -export type BaseValidationAsync = { +export interface BaseValidationAsync { + /** + * The validation type. + */ + type: string; /** * Whether it's async. */ @@ -68,6 +80,10 @@ export type BaseValidationAsync = { * The error message. */ message: ErrorMessage; + /** + * The validation requirement. + */ + requirement: unknown; /** * Parses unknown input based on its requirement. * @@ -78,12 +94,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. */ @@ -98,12 +118,16 @@ export type BaseTransformation = { * @internal */ _parse(input: TInput): PipeResult; -}; +} /** * Base transformation async type. */ -export type BaseTransformationAsync = { +export interface BaseTransformationAsync { + /** + * The transformation type. + */ + type: string; /** * Whether it's async. */ @@ -118,7 +142,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 41f8ae441..6a5c83e42 100644 --- a/library/src/types/schema.ts +++ b/library/src/types/schema.ts @@ -35,7 +35,11 @@ export type _ParseResult = /** * Base schema type. */ -export type BaseSchema = { +export interface BaseSchema { + /** + * The schema type. + */ + type: string; /** * Whether it's async. */ @@ -57,12 +61,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; /** * Whether it's async. */ @@ -84,7 +92,7 @@ export type BaseSchemaAsync = { * @internal */ _types?: { input: TInput; output: TOutput }; -}; +} /** * Input inference type. diff --git a/library/src/validations/bytes/bytes.ts b/library/src/validations/bytes/bytes.ts index 044758722..70d0e5430 100644 --- a/library/src/validations/bytes/bytes.ts +++ b/library/src/validations/bytes/bytes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the byte length of a string. diff --git a/library/src/validations/cuid2/cuid2.ts b/library/src/validations/cuid2/cuid2.ts index cfaf8685a..2b2b9d2c5 100644 --- a/library/src/validations/cuid2/cuid2.ts +++ b/library/src/validations/cuid2/cuid2.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 7a213b0d2..8b14a9b81 100644 --- a/library/src/validations/custom/custom.ts +++ b/library/src/validations/custom/custom.ts @@ -4,7 +4,7 @@ import { getOutput, getPipeIssues } 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 validation function. diff --git a/library/src/validations/custom/customAsync.ts b/library/src/validations/custom/customAsync.ts index 1ef9041c2..d6d340628 100644 --- a/library/src/validations/custom/customAsync.ts +++ b/library/src/validations/custom/customAsync.ts @@ -4,7 +4,8 @@ import { getOutput, getPipeIssues } 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 03793463c..8d506b576 100644 --- a/library/src/validations/email/email.ts +++ b/library/src/validations/email/email.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function that validates a email. diff --git a/library/src/validations/emoji/emoji.ts b/library/src/validations/emoji/emoji.ts index 7f6f611ae..052245cee 100644 --- a/library/src/validations/emoji/emoji.ts +++ b/library/src/validations/emoji/emoji.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function that validates an emoji. diff --git a/library/src/validations/endsWith/endsWith.ts b/library/src/validations/endsWith/endsWith.ts index 107e6c835..576f9648f 100644 --- a/library/src/validations/endsWith/endsWith.ts +++ b/library/src/validations/endsWith/endsWith.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the end of a string. diff --git a/library/src/validations/equal/equal.ts b/library/src/validations/equal/equal.ts index e04570632..3c983870d 100644 --- a/library/src/validations/equal/equal.ts +++ b/library/src/validations/equal/equal.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that checks the value for equality. diff --git a/library/src/validations/excludes/excludes.ts b/library/src/validations/excludes/excludes.ts index e284dbd8e..55ac05f2a 100644 --- a/library/src/validations/excludes/excludes.ts +++ b/library/src/validations/excludes/excludes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the content of a string or array. diff --git a/library/src/validations/finite/finite.ts b/library/src/validations/finite/finite.ts index 465422fae..17a8c2b8d 100644 --- a/library/src/validations/finite/finite.ts +++ b/library/src/validations/finite/finite.ts @@ -4,7 +4,8 @@ import { getOutput, getPipeIssues } 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 validation function that validates whether a number is finite. diff --git a/library/src/validations/imei/imei.ts b/library/src/validations/imei/imei.ts index 63a4c7f16..8a34d1e16 100644 --- a/library/src/validations/imei/imei.ts +++ b/library/src/validations/imei/imei.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues, 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, (input: string) => boolean]; -}; +} /** * Creates a validation function 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 2f6f5f8fa..232541322 100644 --- a/library/src/validations/includes/includes.ts +++ b/library/src/validations/includes/includes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the content of a string or array. diff --git a/library/src/validations/integer/integer.ts b/library/src/validations/integer/integer.ts index 30814b17d..b69db18db 100644 --- a/library/src/validations/integer/integer.ts +++ b/library/src/validations/integer/integer.ts @@ -4,17 +4,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates whether a number is an integer. diff --git a/library/src/validations/ip/ip.ts b/library/src/validations/ip/ip.ts index 5238cd483..d60f62c33 100644 --- a/library/src/validations/ip/ip.ts +++ b/library/src/validations/ip/ip.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 5373d009c..b2309959f 100644 --- a/library/src/validations/ipv4/ipv4.ts +++ b/library/src/validations/ipv4/ipv4.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 4479965fd..a11a94838 100644 --- a/library/src/validations/ipv6/ipv6.ts +++ b/library/src/validations/ipv6/ipv6.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 1f184e5f8..4c46585e0 100644 --- a/library/src/validations/isoDate/isoDate.ts +++ b/library/src/validations/isoDate/isoDate.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a date. diff --git a/library/src/validations/isoDateTime/isoDateTime.ts b/library/src/validations/isoDateTime/isoDateTime.ts index d65fd42df..9fb228015 100644 --- a/library/src/validations/isoDateTime/isoDateTime.ts +++ b/library/src/validations/isoDateTime/isoDateTime.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a datetime. diff --git a/library/src/validations/isoTime/isoTime.ts b/library/src/validations/isoTime/isoTime.ts index 8ca5b77d2..4c01b218c 100644 --- a/library/src/validations/isoTime/isoTime.ts +++ b/library/src/validations/isoTime/isoTime.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a time. diff --git a/library/src/validations/isoTimeSecond/isoTimeSecond.ts b/library/src/validations/isoTimeSecond/isoTimeSecond.ts index b9fa932d3..9d6af2dd2 100644 --- a/library/src/validations/isoTimeSecond/isoTimeSecond.ts +++ b/library/src/validations/isoTimeSecond/isoTimeSecond.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a time with seconds. diff --git a/library/src/validations/isoTimestamp/isoTimestamp.ts b/library/src/validations/isoTimestamp/isoTimestamp.ts index cdd2a1b10..fcad071e3 100644 --- a/library/src/validations/isoTimestamp/isoTimestamp.ts +++ b/library/src/validations/isoTimestamp/isoTimestamp.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a timestamp. diff --git a/library/src/validations/isoWeek/isoWeek.ts b/library/src/validations/isoWeek/isoWeek.ts index 2fb01e899..74e961ee4 100644 --- a/library/src/validations/isoWeek/isoWeek.ts +++ b/library/src/validations/isoWeek/isoWeek.ts @@ -5,17 +5,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates a week. diff --git a/library/src/validations/length/length.ts b/library/src/validations/length/length.ts index 6788bbe35..2638228bf 100644 --- a/library/src/validations/length/length.ts +++ b/library/src/validations/length/length.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the length of a string or array. diff --git a/library/src/validations/maxBytes/maxBytes.ts b/library/src/validations/maxBytes/maxBytes.ts index 7236f8dfd..214de738c 100644 --- a/library/src/validations/maxBytes/maxBytes.ts +++ b/library/src/validations/maxBytes/maxBytes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the byte length of a string. diff --git a/library/src/validations/maxLength/maxLength.ts b/library/src/validations/maxLength/maxLength.ts index 8e5149ccb..55811bf45 100644 --- a/library/src/validations/maxLength/maxLength.ts +++ b/library/src/validations/maxLength/maxLength.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the length of a string or array. diff --git a/library/src/validations/maxSize/maxSize.ts b/library/src/validations/maxSize/maxSize.ts index 474383ab9..1acaceff2 100644 --- a/library/src/validations/maxSize/maxSize.ts +++ b/library/src/validations/maxSize/maxSize.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the size of a map, set or blob. diff --git a/library/src/validations/maxValue/maxValue.ts b/library/src/validations/maxValue/maxValue.ts index 65affe2ca..07dcd49c9 100644 --- a/library/src/validations/maxValue/maxValue.ts +++ b/library/src/validations/maxValue/maxValue.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the value of a string, number or date. diff --git a/library/src/validations/mimeType/mimeType.ts b/library/src/validations/mimeType/mimeType.ts index 81db88abd..a4b1f83b1 100644 --- a/library/src/validations/mimeType/mimeType.ts +++ b/library/src/validations/mimeType/mimeType.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the MIME type of a file. diff --git a/library/src/validations/minBytes/minBytes.ts b/library/src/validations/minBytes/minBytes.ts index dec89b191..025cc3ecb 100644 --- a/library/src/validations/minBytes/minBytes.ts +++ b/library/src/validations/minBytes/minBytes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the byte length of a string. diff --git a/library/src/validations/minLength/minLength.ts b/library/src/validations/minLength/minLength.ts index d5db655f0..48d623a62 100644 --- a/library/src/validations/minLength/minLength.ts +++ b/library/src/validations/minLength/minLength.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the length of a string or array. diff --git a/library/src/validations/minSize/minSize.ts b/library/src/validations/minSize/minSize.ts index 39dbfafb9..f10e02e72 100644 --- a/library/src/validations/minSize/minSize.ts +++ b/library/src/validations/minSize/minSize.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the size of a map, set or blob. diff --git a/library/src/validations/minValue/minValue.ts b/library/src/validations/minValue/minValue.ts index ac03e2213..df3932608 100644 --- a/library/src/validations/minValue/minValue.ts +++ b/library/src/validations/minValue/minValue.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the value of a string, number or date. diff --git a/library/src/validations/multipleOf/multipleOf.ts b/library/src/validations/multipleOf/multipleOf.ts index 706b16042..511ce4cbd 100644 --- a/library/src/validations/multipleOf/multipleOf.ts +++ b/library/src/validations/multipleOf/multipleOf.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates whether a number is a multiple. diff --git a/library/src/validations/notBytes/notBytes.ts b/library/src/validations/notBytes/notBytes.ts index a29b4783d..c10be40c5 100644 --- a/library/src/validations/notBytes/notBytes.ts +++ b/library/src/validations/notBytes/notBytes.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the byte length of a string. diff --git a/library/src/validations/notLength/notLength.ts b/library/src/validations/notLength/notLength.ts index 46b91d62e..a6670af57 100644 --- a/library/src/validations/notLength/notLength.ts +++ b/library/src/validations/notLength/notLength.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the length of a string or array. diff --git a/library/src/validations/notSize/notSize.ts b/library/src/validations/notSize/notSize.ts index 443f5369c..9db32231f 100644 --- a/library/src/validations/notSize/notSize.ts +++ b/library/src/validations/notSize/notSize.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the size of a map, set or blob. diff --git a/library/src/validations/notValue/notValue.ts b/library/src/validations/notValue/notValue.ts index 769a5cb3e..4a4afdd68 100644 --- a/library/src/validations/notValue/notValue.ts +++ b/library/src/validations/notValue/notValue.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } from '../../utils/index.ts'; /** * Not value validation type. */ -export type NotValueValidation< +export interface NotValueValidation< TInput extends string | number | bigint | Date, TRequirement extends TInput -> = BaseValidation & { +> extends BaseValidation { /** * The validation type. */ @@ -16,7 +16,7 @@ export type NotValueValidation< * The value. */ requirement: TRequirement; -}; +} /** * Creates a validation function that validates the value of a string or number. diff --git a/library/src/validations/regex/regex.ts b/library/src/validations/regex/regex.ts index f932d9d40..9dc7dd1f1 100644 --- a/library/src/validations/regex/regex.ts +++ b/library/src/validations/regex/regex.ts @@ -4,7 +4,8 @@ import { getOutput, getPipeIssues } 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 validation function that validates a string with a regex. diff --git a/library/src/validations/safeInteger/safeInteger.ts b/library/src/validations/safeInteger/safeInteger.ts index b8614cd73..1b9c861e6 100644 --- a/library/src/validations/safeInteger/safeInteger.ts +++ b/library/src/validations/safeInteger/safeInteger.ts @@ -4,17 +4,17 @@ import { getOutput, getPipeIssues } 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 validation function that validates whether a number is a safe integer. diff --git a/library/src/validations/size/size.ts b/library/src/validations/size/size.ts index d259f93af..ee4728150 100644 --- a/library/src/validations/size/size.ts +++ b/library/src/validations/size/size.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the size of a map, set or blob. diff --git a/library/src/validations/startsWith/startsWith.ts b/library/src/validations/startsWith/startsWith.ts index 2a930c65b..054d0226e 100644 --- a/library/src/validations/startsWith/startsWith.ts +++ b/library/src/validations/startsWith/startsWith.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the start of a string. diff --git a/library/src/validations/ulid/ulid.ts b/library/src/validations/ulid/ulid.ts index 3abdc18c9..417ebce62 100644 --- a/library/src/validations/ulid/ulid.ts +++ b/library/src/validations/ulid/ulid.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 380a2e346..0f34ca042 100644 --- a/library/src/validations/url/url.ts +++ b/library/src/validations/url/url.ts @@ -4,7 +4,8 @@ import { getOutput, getPipeIssues } 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 validation function that validates a URL. diff --git a/library/src/validations/uuid/uuid.ts b/library/src/validations/uuid/uuid.ts index 17f87b2ab..e75593f13 100644 --- a/library/src/validations/uuid/uuid.ts +++ b/library/src/validations/uuid/uuid.ts @@ -5,7 +5,8 @@ import { getOutput, getPipeIssues } 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 validation function 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 300389849..a07f52f33 100644 --- a/library/src/validations/value/value.ts +++ b/library/src/validations/value/value.ts @@ -4,10 +4,10 @@ import { getOutput, getPipeIssues } 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 validation function that validates the value of a string or number. From 990140ac4352fb9660e0227d48224baad68034da Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Tue, 21 Nov 2023 01:15:33 -0800 Subject: [PATCH 02/21] Refactor Fallback and Default methods, Add Schema Type Predicates Using some basic type predicate functions for base schemas, object schemas, and tuple schemas, I refactored the fallback and default methods which simplifies both their types and the logic for each method. Note that because each of these methods relied on a mutable return value typed as `any`, Typescript did not catch any logic errors when calculating default or fallback values. With the refactors, in some cases an `as` type assertion is necessary. For some of the method types, I reorganized them such that they no longer introduce a circular dependency (even if only at the type level). --- library/src/methods/fallback/fallback.ts | 17 +---- library/src/methods/fallback/fallbackAsync.ts | 19 +---- library/src/methods/fallback/types.ts | 24 ++++++- library/src/methods/getDefault/getDefault.ts | 14 +--- .../src/methods/getDefault/getDefaultAsync.ts | 25 ++----- library/src/methods/getDefault/types.ts | 28 +++++++- .../src/methods/getDefaults/getDefaults.ts | 54 +++++---------- .../methods/getDefaults/getDefaultsAsync.ts | 69 ++++++------------- .../src/methods/getFallback/getFallback.ts | 14 +--- .../methods/getFallback/getFallbackAsync.ts | 22 ++---- library/src/methods/getFallback/types.ts | 27 +++++++- .../src/methods/getFallbacks/getFallbacks.ts | 54 +++++---------- .../methods/getFallbacks/getFallbacksAsync.ts | 67 ++++++------------ library/src/schemas/object/index.ts | 1 + library/src/schemas/object/isObjectSchema.ts | 10 +++ library/src/schemas/tuple/index.ts | 1 + library/src/schemas/tuple/isTupleSchema.ts | 10 +++ library/src/utils/index.ts | 2 + library/src/utils/isNonNullable.ts | 23 +++++++ library/src/utils/isSchema.ts | 12 ++++ 20 files changed, 224 insertions(+), 269 deletions(-) create mode 100644 library/src/schemas/object/isObjectSchema.ts create mode 100644 library/src/schemas/tuple/isTupleSchema.ts create mode 100644 library/src/utils/isNonNullable.ts create mode 100644 library/src/utils/isSchema.ts diff --git a/library/src/methods/fallback/fallback.ts b/library/src/methods/fallback/fallback.ts index 8ab38e8a1..2294e5500 100644 --- a/library/src/methods/fallback/fallback.ts +++ b/library/src/methods/fallback/fallback.ts @@ -1,22 +1,7 @@ import type { BaseSchema, Output } from '../../types/index.ts'; import { getOutput } from '../../utils/index.ts'; import { getFallback } from '../getFallback/index.ts'; -import type { FallbackInfo } from './types.ts'; - -/** - * Schema with fallback type. - */ -export type SchemaWithFallback< - TSchema extends BaseSchema = BaseSchema, - TFallback extends - | Output - | ((info?: FallbackInfo) => Output) = Output -> = TSchema & { - /** - * The fallback value. - */ - fallback: TFallback; -}; +import type { FallbackInfo, SchemaWithFallback } from './types.ts'; /** * Returns a fallback value when validating the passed schema failed. diff --git a/library/src/methods/fallback/fallbackAsync.ts b/library/src/methods/fallback/fallbackAsync.ts index ce1970da5..69cea461d 100644 --- a/library/src/methods/fallback/fallbackAsync.ts +++ b/library/src/methods/fallback/fallbackAsync.ts @@ -1,24 +1,7 @@ import type { BaseSchemaAsync, Output } from '../../types/index.ts'; import { getOutput } from '../../utils/index.ts'; import { getFallbackAsync } from '../getFallback/index.ts'; -import type { FallbackInfo } from './types.ts'; - -/** - * Schema with fallback async type. - */ -export type SchemaWithFallbackAsync< - TSchema extends BaseSchemaAsync = BaseSchemaAsync, - TFallback extends - | Output - | (( - info?: FallbackInfo - ) => Output | Promise>) = Output -> = TSchema & { - /** - * The fallback value. - */ - fallback: TFallback; -}; +import type { FallbackInfo, SchemaWithFallbackAsync } from './types.ts'; /** * Returns a fallback value when validating the passed schema failed. diff --git a/library/src/methods/fallback/types.ts b/library/src/methods/fallback/types.ts index f253225e9..064d408fc 100644 --- a/library/src/methods/fallback/types.ts +++ b/library/src/methods/fallback/types.ts @@ -1,4 +1,4 @@ -import type { Issues } from '../../types/index.ts'; +import type { Issues, BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; /** * Fallback info type. @@ -7,3 +7,25 @@ export type FallbackInfo = { input: unknown; issues: Issues; }; + +/** + * Schema with fallback type. + */ +export interface SchemaWithFallback + extends BaseSchema { + /** + * The fallback value. + */ + fallback: TOutput | ((info?: FallbackInfo) => TOutput); +} + +/** + * Schema with fallback async type. + */ +export interface SchemaWithFallbackAsync + extends BaseSchemaAsync { + /** + * The fallback value. + */ + fallback: TOutput | ((info?: FallbackInfo) => TOutput | Promise); +} diff --git a/library/src/methods/getDefault/getDefault.ts b/library/src/methods/getDefault/getDefault.ts index 2713acf47..aa9d2e1e9 100644 --- a/library/src/methods/getDefault/getDefault.ts +++ b/library/src/methods/getDefault/getDefault.ts @@ -1,16 +1,4 @@ -import type { BaseSchema, Output } 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); - }; +import type { DefaultValue, SchemaWithMaybeDefault } from './types.ts'; /** * Returns the default value of the schema. diff --git a/library/src/methods/getDefault/getDefaultAsync.ts b/library/src/methods/getDefault/getDefaultAsync.ts index 36df7bb74..9c0460b45 100644 --- a/library/src/methods/getDefault/getDefaultAsync.ts +++ b/library/src/methods/getDefault/getDefaultAsync.ts @@ -1,23 +1,8 @@ -import type { BaseSchemaAsync, Output } from '../../types/index.ts'; -import type { SchemaWithMaybeDefault } from './getDefault.ts'; -import type { DefaultValue } from './types.ts'; - -/** - * Schema with maybe default async type. - */ -export type SchemaWithMaybeDefaultAsync< - TSchema extends BaseSchemaAsync = BaseSchemaAsync -> = TSchema & { - /** - * The optional default value. - */ - default?: - | Output - | (() => - | Output - | Promise | undefined> - | undefined); -}; +import type { + DefaultValue, + SchemaWithMaybeDefault, + SchemaWithMaybeDefaultAsync, +} from './types.ts'; /** * Returns the default value of the schema. diff --git a/library/src/methods/getDefault/types.ts b/library/src/methods/getDefault/types.ts index cb8a4b2f7..367e6261d 100644 --- a/library/src/methods/getDefault/types.ts +++ b/library/src/methods/getDefault/types.ts @@ -1,6 +1,28 @@ -import type { Output } from '../../types/index.ts'; -import type { SchemaWithMaybeDefault } from './getDefault.ts'; -import type { SchemaWithMaybeDefaultAsync } from './getDefaultAsync.ts'; +import type { BaseSchema, BaseSchemaAsync, Output } from '../../types/index.ts'; + +/** + * Schema with maybe default type. + */ +export interface SchemaWithMaybeDefault + extends BaseSchema { + /** + * The optional default value. + */ + default?: TOutput | (() => TOutput | undefined); +} + +/** + * Schema with maybe default async type. + */ +export interface SchemaWithMaybeDefaultAsync + extends BaseSchemaAsync { + /** + * The optional default value. + */ + default?: + | TOutput + | (() => TOutput | Promise | undefined); +} /** * Default value type. diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index bc060c642..48c0ef018 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -1,10 +1,4 @@ -import type { - ObjectEntries, - ObjectSchema, - TupleItems, - TupleSchema, -} from '../../schemas/index.ts'; -import type { BaseSchema } from '../../types/index.ts'; +import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; import { getDefault, type SchemaWithMaybeDefault, @@ -22,36 +16,24 @@ import type { DefaultValues } from './types.ts'; * * @returns The default values. */ -export function getDefaults< - TSchema extends SchemaWithMaybeDefault< - BaseSchema | ObjectSchema | TupleSchema - > ->(schema: TSchema): DefaultValues { - // Create defaults variable - let defaults: any; - +export function getDefaults( + schema: TSchema +): DefaultValues | undefined { // If schema contains a default function, set its default value if (schema.default) { - defaults = 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 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])); - } - } + return getDefault(schema); + } + // Otherwise, check if schema is of kind object or tuple + // If it is an object schema, set object with default value of each entry + if (isObjectSchema(schema)) { + return Object.entries(schema.entries).reduce( + (hash, [key, value]) => + Object.assign(hash, { [key]: getDefaults(value) }), + {} + ) as DefaultValues; + } + // If it is a tuple schema, set array with default value of each item + if (isTupleSchema(schema)) { + return schema.items.map(getDefaults) as DefaultValues; } - - // Return default values - return defaults; } diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index c6f592fb6..b93af404f 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -1,14 +1,4 @@ -import type { - ObjectEntries, - ObjectEntriesAsync, - ObjectSchema, - ObjectSchemaAsync, - TupleItems, - TupleItemsAsync, - TupleSchema, - TupleSchemaAsync, -} from '../../schemas/index.ts'; -import type { BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; +import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; import { getDefaultAsync, type SchemaWithMaybeDefault, @@ -28,43 +18,28 @@ import type { DefaultValues } from './types.ts'; * @returns The default values. */ export async function getDefaultsAsync< - TSchema extends - | SchemaWithMaybeDefault< - | BaseSchema - | ObjectSchema - | TupleSchema - > - | SchemaWithMaybeDefaultAsync< - | BaseSchemaAsync - | ObjectSchemaAsync - | TupleSchemaAsync - > ->(schema: TSchema): Promise> { - // Create defaults variable - let defaults: any; - + TSchema extends SchemaWithMaybeDefault | SchemaWithMaybeDefaultAsync +>(schema: TSchema): Promise | undefined> { // If schema contains a default function, set its default value if (schema.default) { - defaults = await 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 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])); - } - } + return getDefaultAsync(schema); + } + // Otherwise, check if schema is of kind object or tuple + // If it is an object schema, set object with default value of each entry + if (isObjectSchema(schema)) { + return Object.fromEntries( + await Promise.all( + Object.entries(schema.entries).map(async ([key, value]) => [ + key, + await getDefaultsAsync(value), + ]) + ) + ); + } + // If it is a tuple schema, set array with default value of each item + if (isTupleSchema(schema)) { + return Promise.all( + schema.items.map(getDefaultsAsync) + ) as DefaultValues; } - - // Return default values - return defaults; } diff --git a/library/src/methods/getFallback/getFallback.ts b/library/src/methods/getFallback/getFallback.ts index 5106258c6..bfa07ddbc 100644 --- a/library/src/methods/getFallback/getFallback.ts +++ b/library/src/methods/getFallback/getFallback.ts @@ -1,17 +1,5 @@ -import type { BaseSchema, Output } from '../../types/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); - }; +import type { FallbackValue, SchemaWithMaybeFallback } from './types.ts'; /** * Returns the fallback value of the schema. diff --git a/library/src/methods/getFallback/getFallbackAsync.ts b/library/src/methods/getFallback/getFallbackAsync.ts index 0ab6a975d..7b51f0be1 100644 --- a/library/src/methods/getFallback/getFallbackAsync.ts +++ b/library/src/methods/getFallback/getFallbackAsync.ts @@ -1,21 +1,9 @@ -import type { BaseSchemaAsync, Output } from '../../types/index.ts'; import type { FallbackInfo } from '../fallback/types.ts'; -import type { SchemaWithMaybeFallback } from './getFallback.ts'; -import type { FallbackValue } from './types.ts'; - -/** - * Schema with maybe fallback async type. - */ -export type SchemaWithMaybeFallbackAsync< - TSchema extends BaseSchemaAsync = BaseSchemaAsync -> = TSchema & { - /** - * The optional fallback value. - */ - fallback?: - | Output - | ((info?: FallbackInfo) => Output | Promise>); -}; +import type { + FallbackValue, + SchemaWithMaybeFallback, + SchemaWithMaybeFallbackAsync, +} from './types.ts'; /** * Returns the fallback value of the schema. diff --git a/library/src/methods/getFallback/types.ts b/library/src/methods/getFallback/types.ts index 8715e6c38..fd1d92dc9 100644 --- a/library/src/methods/getFallback/types.ts +++ b/library/src/methods/getFallback/types.ts @@ -1,6 +1,27 @@ -import type { Output } from '../../types/schema.ts'; -import type { SchemaWithMaybeFallback } from './getFallback.ts'; -import type { SchemaWithMaybeFallbackAsync } from './getFallbackAsync.ts'; +import type { BaseSchema, BaseSchemaAsync, Output } from '../../types/index.ts'; +import type { FallbackInfo } from '../fallback/types.ts'; + +/** + * Schema with maybe fallback type. + */ +export interface SchemaWithMaybeFallback + extends BaseSchema { + /** + * The optional fallback value. + */ + fallback?: TOutput | ((info?: FallbackInfo) => TOutput); +} + +/** + * Schema with maybe fallback async type. + */ +export interface SchemaWithMaybeFallbackAsync + extends BaseSchemaAsync { + /** + * The optional fallback value. + */ + fallback?: TOutput | ((info?: FallbackInfo) => TOutput | Promise); +} /** * Fallback value type. diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index 7f0b79bef..f702ebd93 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -1,10 +1,4 @@ -import type { - ObjectEntries, - ObjectSchema, - TupleItems, - TupleSchema, -} from '../../schemas/index.ts'; -import type { BaseSchema } from '../../types/index.ts'; +import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; import { getFallback, type SchemaWithMaybeFallback, @@ -22,36 +16,24 @@ import type { FallbackValues } from './types.ts'; * * @returns The fallback values. */ -export function getFallbacks< - TSchema extends SchemaWithMaybeFallback< - BaseSchema | ObjectSchema | TupleSchema - > ->(schema: TSchema): FallbackValues { - // Create fallbacks variable - let fallbacks: any; - +export function getFallbacks( + schema: TSchema +): FallbackValues | undefined { // If schema has a fallback, set its value if (schema.fallback) { - fallbacks = 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 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])); - } - } + return getFallback(schema); + } + // Otherwise, check if schema is of kind object or tuple + // If it is an object schema, set object with fallback value of each entry + if (isObjectSchema(schema)) { + return Object.entries(schema.entries).reduce( + (hash, [key, value]) => + Object.assign(hash, { [key]: getFallbacks(value) }), + {} + ) as FallbackValues; + } + // If it is a tuple schema, set array with fallback value of each item + if (isTupleSchema(schema)) { + return schema.items.map(getFallbacks) as FallbackValues; } - - // Return fallback values - return fallbacks; } diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 09ff91147..37b1f4d7c 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -1,14 +1,4 @@ -import type { - ObjectEntries, - ObjectEntriesAsync, - ObjectSchema, - ObjectSchemaAsync, - TupleItems, - TupleItemsAsync, - TupleSchema, - TupleSchemaAsync, -} from '../../schemas/index.ts'; -import type { BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; +import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; import { getFallbackAsync, type SchemaWithMaybeFallback, @@ -28,43 +18,28 @@ import type { FallbackValues } from './types.ts'; * @returns The fallback values. */ export async function getFallbacksAsync< - TSchema extends - | SchemaWithMaybeFallback< - | BaseSchema - | ObjectSchema - | TupleSchema - > - | SchemaWithMaybeFallbackAsync< - | BaseSchemaAsync - | ObjectSchemaAsync - | TupleSchemaAsync - > ->(schema: TSchema): Promise> { - // Create fallbacks variable - let fallbacks: any; - + TSchema extends SchemaWithMaybeFallback | SchemaWithMaybeFallbackAsync +>(schema: TSchema): Promise | undefined> { // If schema has a fallback, set its value if (schema.fallback) { - fallbacks = await getFallbackAsync(schema); - - // Otherwise, check if schema is of kind object or tuple - } else if ('type' in schema) { - if (schema.type === 'object') { - fallbacks = {}; + return getFallbackAsync(schema); + } + // Otherwise, check if schema is of kind object or tuple + // If it is an object schema, set object with fallback value of each entry + if (isObjectSchema(schema)) { + return Object.fromEntries( await Promise.all( - Object.entries(schema.entries).map(async ([key, schema]) => { - fallbacks[key] = await getFallbacksAsync(schema); - }) - ); - - // 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)) - ); - } + Object.entries(schema.entries).map(async ([key, value]) => [ + key, + await getFallbacksAsync(value), + ]) + ) + ); + } + // If it is a tuple schema, set array with fallback value of each item + if (isTupleSchema(schema)) { + return Promise.all( + schema.items.map(getFallbacksAsync) + ) as FallbackValues; } - - // Return fallback values - return fallbacks; } diff --git a/library/src/schemas/object/index.ts b/library/src/schemas/object/index.ts index e56eae4b7..19b9a6508 100644 --- a/library/src/schemas/object/index.ts +++ b/library/src/schemas/object/index.ts @@ -1,3 +1,4 @@ export * from './object.ts'; +export * from './isObjectSchema.ts'; export * from './objectAsync.ts'; export * from './types.ts'; diff --git a/library/src/schemas/object/isObjectSchema.ts b/library/src/schemas/object/isObjectSchema.ts new file mode 100644 index 000000000..6becaa7bc --- /dev/null +++ b/library/src/schemas/object/isObjectSchema.ts @@ -0,0 +1,10 @@ +import { ObjectSchemaAsync, ObjectEntriesAsync } from './objectAsync.ts'; +import { ObjectSchema, ObjectEntries } from './object.ts'; +import { isSchema } from '../../utils/isSchema.ts'; + +export const isObjectSchema = ( + val: unknown +): val is + | ObjectSchema + | ObjectSchemaAsync => + isSchema(val) && val.type === `object`; diff --git a/library/src/schemas/tuple/index.ts b/library/src/schemas/tuple/index.ts index 3ad498f30..49451b83e 100644 --- a/library/src/schemas/tuple/index.ts +++ b/library/src/schemas/tuple/index.ts @@ -1,3 +1,4 @@ +export * from './isTupleSchema.ts'; export * from './tuple.ts'; export * from './tupleAsync.ts'; export * from './types.ts'; diff --git a/library/src/schemas/tuple/isTupleSchema.ts b/library/src/schemas/tuple/isTupleSchema.ts new file mode 100644 index 000000000..b7c255728 --- /dev/null +++ b/library/src/schemas/tuple/isTupleSchema.ts @@ -0,0 +1,10 @@ +import { TupleSchemaAsync, TupleItemsAsync } from './tupleAsync.ts'; +import { TupleSchema, TupleItems } from './tuple.ts'; +import { isSchema } from '../../utils/isSchema.ts'; + +export const isTupleSchema = ( + val: unknown +): val is + | TupleSchema + | TupleSchemaAsync => + isSchema(val) && val.type === `tuple`; diff --git a/library/src/utils/index.ts b/library/src/utils/index.ts index 61fbc228f..2f967cefa 100644 --- a/library/src/utils/index.ts +++ b/library/src/utils/index.ts @@ -6,3 +6,5 @@ export * from './getPipeIssues/index.ts'; export * from './getRestAndDefaultArgs/index.ts'; export * from './getSchemaIssues/index.ts'; export * from './isLuhnAlgo/index.ts'; +export * from './isNonNullable.ts'; +export * from './isSchema.ts'; diff --git a/library/src/utils/isNonNullable.ts b/library/src/utils/isNonNullable.ts new file mode 100644 index 000000000..888a0aeb3 --- /dev/null +++ b/library/src/utils/isNonNullable.ts @@ -0,0 +1,23 @@ +export type Maybe = T | null | undefined; + +/** + * Used to test whether a `Maybe` typed value is `null` or `undefined`. + * + * When called, the given value's type is narrowed to `NonNullable`. + * + * ### Example Usage: + * + * ```ts + * const fn = (str: Maybe) => { + * if (!isNonNullable(str)) { + * // typeof str = null | undefined + * // ... + * } + * // typeof str = string + * // ... + * } + * ``` + */ +export const isNonNullable = >( + val?: T +): val is NonNullable => typeof val !== `undefined` && val !== null; diff --git a/library/src/utils/isSchema.ts b/library/src/utils/isSchema.ts new file mode 100644 index 000000000..397786991 --- /dev/null +++ b/library/src/utils/isSchema.ts @@ -0,0 +1,12 @@ +import { BaseSchema, BaseSchemaAsync } from '../types/schema'; +import { isNonNullable } from './isNonNullable'; + +export const isSchema = (val: unknown): val is BaseSchema | BaseSchemaAsync => + isNonNullable(val) && + typeof val === `object` && + 'type' in val && + typeof val.type === `string` && + 'async' in val && + typeof val.async === `boolean` && + '_parse' in val && + typeof val._parse === `function`; From 5b483f480738f3dabb8d4736b1824256f9ddf03b Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Wed, 22 Nov 2023 10:32:25 -0800 Subject: [PATCH 03/21] Fix file extensions lint errors --- library/src/schemas/object/isObjectSchema.ts | 4 ++-- library/src/schemas/tuple/isTupleSchema.ts | 4 ++-- library/src/utils/isSchema.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/library/src/schemas/object/isObjectSchema.ts b/library/src/schemas/object/isObjectSchema.ts index 6becaa7bc..64039ef6a 100644 --- a/library/src/schemas/object/isObjectSchema.ts +++ b/library/src/schemas/object/isObjectSchema.ts @@ -1,5 +1,5 @@ -import { ObjectSchemaAsync, ObjectEntriesAsync } from './objectAsync.ts'; -import { ObjectSchema, ObjectEntries } from './object.ts'; +import type { ObjectSchemaAsync, ObjectEntriesAsync } from './objectAsync.ts'; +import type { ObjectSchema, ObjectEntries } from './object.ts'; import { isSchema } from '../../utils/isSchema.ts'; export const isObjectSchema = ( diff --git a/library/src/schemas/tuple/isTupleSchema.ts b/library/src/schemas/tuple/isTupleSchema.ts index b7c255728..8fd7d9a08 100644 --- a/library/src/schemas/tuple/isTupleSchema.ts +++ b/library/src/schemas/tuple/isTupleSchema.ts @@ -1,5 +1,5 @@ -import { TupleSchemaAsync, TupleItemsAsync } from './tupleAsync.ts'; -import { TupleSchema, TupleItems } from './tuple.ts'; +import type { TupleSchemaAsync, TupleItemsAsync } from './tupleAsync.ts'; +import type { TupleSchema, TupleItems } from './tuple.ts'; import { isSchema } from '../../utils/isSchema.ts'; export const isTupleSchema = ( diff --git a/library/src/utils/isSchema.ts b/library/src/utils/isSchema.ts index 397786991..af992dbbb 100644 --- a/library/src/utils/isSchema.ts +++ b/library/src/utils/isSchema.ts @@ -1,5 +1,5 @@ -import { BaseSchema, BaseSchemaAsync } from '../types/schema'; -import { isNonNullable } from './isNonNullable'; +import type { BaseSchema, BaseSchemaAsync } from '../types/schema.ts'; +import { isNonNullable } from './isNonNullable.ts'; export const isSchema = (val: unknown): val is BaseSchema | BaseSchemaAsync => isNonNullable(val) && From a1584f1171ece634ecbf7b90e575dadefd8482f0 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Wed, 22 Nov 2023 10:36:15 -0800 Subject: [PATCH 04/21] Add jsdoc `@param` and `@returns` required by linting rules --- library/src/utils/isNonNullable.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/src/utils/isNonNullable.ts b/library/src/utils/isNonNullable.ts index 888a0aeb3..0f6eb5e7c 100644 --- a/library/src/utils/isNonNullable.ts +++ b/library/src/utils/isNonNullable.ts @@ -5,6 +5,10 @@ export type Maybe = T | null | undefined; * * When called, the given value's type is narrowed to `NonNullable`. * + * @param val The value to be checked. + * + * @returns Whether the value is non-nullable. + * * ### Example Usage: * * ```ts From c08f73221d434331e89100a2aa97a45a7b09da43 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Wed, 22 Nov 2023 11:11:07 -0800 Subject: [PATCH 05/21] Resolve Flatten type errors In each case here, `TRest` can possibly be `undefined`, which means the resulting type intersection `(BaseSchema | BaseSchemaAsync) & TRest` where `TRest` is `undefined` causes the whole intersection to be `undefined`. To solve for this, we can instead compare `TRest` to `NonNullable` to narrow it down to `BaseSchema | BaseSchemaAsync`. --- library/src/error/flatten/flatten.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/error/flatten/flatten.ts b/library/src/error/flatten/flatten.ts index 461407a3c..1b4ff66c5 100644 --- a/library/src/error/flatten/flatten.ts +++ b/library/src/error/flatten/flatten.ts @@ -78,7 +78,7 @@ type NestedPath = TSchema extends | ObjectSchema | ObjectSchemaAsync - ? TRest extends BaseSchema | BaseSchemaAsync + ? TRest extends NonNullable ? ObjectPath | DotPath : ObjectPath : // Record @@ -102,7 +102,7 @@ type NestedPath = TSchema extends | TupleSchema | TupleSchemaAsync - ? TRest extends BaseSchema | BaseSchemaAsync + ? TRest extends NonNullable ? TuplePath | DotPath : TuplePath : // Union From 7f84338d5e4974c9508bcf5145f8c158a4785a28 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Wed, 22 Nov 2023 12:01:47 -0800 Subject: [PATCH 06/21] Fix broken export for `intersectAsync` This is a bugfix for an issue on main --- library/src/schemas/intersect/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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'; From a89b4862edaf4f11b70161b35669269e2271f396 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Tue, 5 Dec 2023 09:04:34 -0800 Subject: [PATCH 07/21] Fix eslint error --- library/src/types/pipe.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/library/src/types/pipe.ts b/library/src/types/pipe.ts index 0eaad70b6..22e66f0fa 100644 --- a/library/src/types/pipe.ts +++ b/library/src/types/pipe.ts @@ -75,7 +75,7 @@ export interface BaseValidation { * @internal */ _parse(input: TInput): PipeActionResult; -}; +} /** * Base validation async type. @@ -107,7 +107,7 @@ export interface BaseValidationAsync { * @internal */ _parse(input: TInput): Promise>; -}; +} /** * Base transformation type. @@ -131,7 +131,7 @@ export interface BaseTransformation { * @internal */ _parse(input: TInput): PipeActionResult; -}; +} /** * Base transformation async type. @@ -155,7 +155,7 @@ export interface BaseTransformationAsync { * @internal */ _parse(input: TInput): Promise>; -}; +} /** * Pipe type. From 5078f724edd838c2110b0f4a440f83b2f272d9d2 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Sat, 6 Jan 2024 11:38:50 -0800 Subject: [PATCH 08/21] Resolve lint errors (no-extra-semi) --- library/src/schemas/intersect/intersect.ts | 2 +- library/src/schemas/intersect/intersectAsync.ts | 2 +- library/src/schemas/union/union.ts | 2 +- library/src/schemas/union/unionAsync.ts | 2 +- library/src/schemas/variant/variant.ts | 2 +- library/src/schemas/variant/variantAsync.ts | 2 +- library/src/validations/imei/imei.ts | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/src/schemas/intersect/intersect.ts b/library/src/schemas/intersect/intersect.ts index 38ad623fe..868d0548f 100644 --- a/library/src/schemas/intersect/intersect.ts +++ b/library/src/schemas/intersect/intersect.ts @@ -44,7 +44,7 @@ export interface 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 7b04fcfa6..e8be8ad44 100644 --- a/library/src/schemas/intersect/intersectAsync.ts +++ b/library/src/schemas/intersect/intersectAsync.ts @@ -49,7 +49,7 @@ export interface IntersectSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async intersect schema. diff --git a/library/src/schemas/union/union.ts b/library/src/schemas/union/union.ts index 47f2f6457..08fdb77df 100644 --- a/library/src/schemas/union/union.ts +++ b/library/src/schemas/union/union.ts @@ -37,7 +37,7 @@ export interface 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 900ff7056..59d26256d 100644 --- a/library/src/schemas/union/unionAsync.ts +++ b/library/src/schemas/union/unionAsync.ts @@ -42,7 +42,7 @@ export interface UnionSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async union schema. diff --git a/library/src/schemas/variant/variant.ts b/library/src/schemas/variant/variant.ts index 631ca39db..4971977fa 100644 --- a/library/src/schemas/variant/variant.ts +++ b/library/src/schemas/variant/variant.ts @@ -61,7 +61,7 @@ export interface 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 89d70b84c..4ee78aae3 100644 --- a/library/src/schemas/variant/variantAsync.ts +++ b/library/src/schemas/variant/variantAsync.ts @@ -63,7 +63,7 @@ export interface VariantSchemaAsync< * The validation and transformation pipeline. */ pipe: PipeAsync> | undefined; -}; +} /** * Creates an async variant (aka discriminated union) schema. diff --git a/library/src/validations/imei/imei.ts b/library/src/validations/imei/imei.ts index ebbcff0b9..6a671321f 100644 --- a/library/src/validations/imei/imei.ts +++ b/library/src/validations/imei/imei.ts @@ -15,7 +15,7 @@ export interface ImeiValidation * 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). From c2dc3650ea52124768833bb1a1232790b1847c0c Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Thu, 18 Jan 2024 11:50:33 -0800 Subject: [PATCH 09/21] Fix extra semi errors from merge --- library/src/schemas/union/union.ts | 2 +- library/src/schemas/variant/variant.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/schemas/union/union.ts b/library/src/schemas/union/union.ts index 441673cb7..0908b15c9 100644 --- a/library/src/schemas/union/union.ts +++ b/library/src/schemas/union/union.ts @@ -39,7 +39,7 @@ export interface UnionSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a union schema. diff --git a/library/src/schemas/variant/variant.ts b/library/src/schemas/variant/variant.ts index 77af747b8..0a6c6169a 100644 --- a/library/src/schemas/variant/variant.ts +++ b/library/src/schemas/variant/variant.ts @@ -56,7 +56,7 @@ export interface VariantSchema< * The validation and transformation pipeline. */ pipe: Pipe> | undefined; -}; +} /** * Creates a variant (aka discriminated union) schema. From 0676aff159a1709060c5834e0ff426c222d6dc43 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Wed, 24 Jan 2024 09:17:51 -0800 Subject: [PATCH 10/21] Fix merge errors --- library/src/schemas/recursive/recursive.ts | 3 ++- library/src/schemas/recursive/recursiveAsync.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/src/schemas/recursive/recursive.ts b/library/src/schemas/recursive/recursive.ts index 399d5bce9..35b67dcfc 100644 --- a/library/src/schemas/recursive/recursive.ts +++ b/library/src/schemas/recursive/recursive.ts @@ -3,7 +3,7 @@ import type { BaseSchema, Input, Output } from '../../types/index.ts'; /** * Recursive schema type. */ -export type RecursiveSchema< +export interface RecursiveSchema< TGetter extends () => BaseSchema, TOutput = Output> > extends BaseSchema>, TOutput> { @@ -15,6 +15,7 @@ export type RecursiveSchema< * The schema getter. */ getter: TGetter; +} /** * Creates a recursive schema. diff --git a/library/src/schemas/recursive/recursiveAsync.ts b/library/src/schemas/recursive/recursiveAsync.ts index 2f0228fd5..05b39e75f 100644 --- a/library/src/schemas/recursive/recursiveAsync.ts +++ b/library/src/schemas/recursive/recursiveAsync.ts @@ -8,7 +8,7 @@ import type { /** * Recursive schema async type. */ -export type RecursiveSchemaAsync< +export interface RecursiveSchemaAsync< TGetter extends () => BaseSchema | BaseSchemaAsync, TOutput = Output> > extends BaseSchemaAsync>, TOutput> { @@ -20,6 +20,7 @@ export type RecursiveSchemaAsync< * The schema getter. */ getter: TGetter; +} /** * Creates an async recursive schema. From bb424a086dc794e7de1c1eb3de11471bfac660e4 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Mon, 5 Feb 2024 15:54:32 -0800 Subject: [PATCH 11/21] Fix formatting --- library/src/methods/fallback/types.ts | 6 +++++- library/src/methods/getDefaults/getDefaults.ts | 7 ++++--- library/src/schemas/object/isObjectSchema.ts | 4 ++-- library/src/schemas/tuple/isTupleSchema.ts | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/library/src/methods/fallback/types.ts b/library/src/methods/fallback/types.ts index f38d757f2..37149ae5c 100644 --- a/library/src/methods/fallback/types.ts +++ b/library/src/methods/fallback/types.ts @@ -1,4 +1,8 @@ -import type { SchemaIssues, BaseSchema, BaseSchemaAsync } from '../../types/index.ts'; +import type { + BaseSchema, + BaseSchemaAsync, + SchemaIssues, +} from '../../types/index.ts'; /** * Fallback info type. diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index c598859c9..2eba49abf 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -27,9 +27,10 @@ export function getDefaults( // If it is an object schema, set object with default value of each entry if (isObjectSchema(schema)) { return Object.fromEntries( - Object.entries(schema.entries).map( - ([key, value]) => [key, getDefaults(value)] - ) + 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 diff --git a/library/src/schemas/object/isObjectSchema.ts b/library/src/schemas/object/isObjectSchema.ts index 64039ef6a..5510cbd5c 100644 --- a/library/src/schemas/object/isObjectSchema.ts +++ b/library/src/schemas/object/isObjectSchema.ts @@ -1,6 +1,6 @@ -import type { ObjectSchemaAsync, ObjectEntriesAsync } from './objectAsync.ts'; -import type { ObjectSchema, ObjectEntries } from './object.ts'; import { isSchema } from '../../utils/isSchema.ts'; +import type { ObjectEntries, ObjectSchema } from './object.ts'; +import type { ObjectEntriesAsync, ObjectSchemaAsync } from './objectAsync.ts'; export const isObjectSchema = ( val: unknown diff --git a/library/src/schemas/tuple/isTupleSchema.ts b/library/src/schemas/tuple/isTupleSchema.ts index 8fd7d9a08..36e4c4186 100644 --- a/library/src/schemas/tuple/isTupleSchema.ts +++ b/library/src/schemas/tuple/isTupleSchema.ts @@ -1,6 +1,6 @@ -import type { TupleSchemaAsync, TupleItemsAsync } from './tupleAsync.ts'; -import type { TupleSchema, TupleItems } from './tuple.ts'; import { isSchema } from '../../utils/isSchema.ts'; +import type { TupleItems, TupleSchema } from './tuple.ts'; +import type { TupleItemsAsync, TupleSchemaAsync } from './tupleAsync.ts'; export const isTupleSchema = ( val: unknown From 0a5889a26eff2f5442b8f01aad06769c5d5150a9 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Sat, 17 Feb 2024 15:46:02 -0500 Subject: [PATCH 12/21] Fix types and exports of fallback method --- library/src/methods/fallback/fallback.ts | 12 +++----- library/src/methods/fallback/fallbackAsync.ts | 13 ++++++++- library/src/methods/fallback/types.ts | 28 +------------------ 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/library/src/methods/fallback/fallback.ts b/library/src/methods/fallback/fallback.ts index 32f57f982..4bd0efdd3 100644 --- a/library/src/methods/fallback/fallback.ts +++ b/library/src/methods/fallback/fallback.ts @@ -8,17 +8,13 @@ import type { FallbackInfo } from './types.ts'; /** * Schema with fallback type. */ -export type SchemaWithFallback< - TSchema extends BaseSchema = BaseSchema, - TFallback extends - | Output - | ((info?: FallbackInfo) => Output) = Output -> = TSchema & { +export interface SchemaWithFallback + extends BaseSchema { /** * The fallback value. */ - fallback: TFallback; -}; + fallback: TOutput | ((info?: FallbackInfo) => TOutput); +} /** * Returns a fallback output value when validating the passed schema failed. diff --git a/library/src/methods/fallback/fallbackAsync.ts b/library/src/methods/fallback/fallbackAsync.ts index 3bc1cf124..1a6f856d5 100644 --- a/library/src/methods/fallback/fallbackAsync.ts +++ b/library/src/methods/fallback/fallbackAsync.ts @@ -1,7 +1,18 @@ import type { BaseSchemaAsync, Output } from '../../types/index.ts'; import { schemaResult } from '../../utils/index.ts'; import { getFallbackAsync } from '../getFallback/index.ts'; -import type { FallbackInfo, SchemaWithFallbackAsync } from './types.ts'; +import type { FallbackInfo } from './types.ts'; + +/** + * Schema with fallback async type. + */ +export interface SchemaWithFallbackAsync + extends BaseSchemaAsync { + /** + * The fallback value. + */ + fallback: TOutput | ((info?: FallbackInfo) => TOutput | Promise); +} /** * Returns a fallback output value when validating the passed schema failed. diff --git a/library/src/methods/fallback/types.ts b/library/src/methods/fallback/types.ts index 37149ae5c..2e626bf26 100644 --- a/library/src/methods/fallback/types.ts +++ b/library/src/methods/fallback/types.ts @@ -1,8 +1,4 @@ -import type { - BaseSchema, - BaseSchemaAsync, - SchemaIssues, -} from '../../types/index.ts'; +import type { SchemaIssues } from '../../types/index.ts'; /** * Fallback info type. @@ -11,25 +7,3 @@ export type FallbackInfo = { input: unknown; issues: SchemaIssues; }; - -/** - * Schema with fallback type. - */ -export interface SchemaWithFallback - extends BaseSchema { - /** - * The fallback value. - */ - fallback: TOutput | ((info?: FallbackInfo) => TOutput); -} - -/** - * Schema with fallback async type. - */ -export interface SchemaWithFallbackAsync - extends BaseSchemaAsync { - /** - * The fallback value. - */ - fallback: TOutput | ((info?: FallbackInfo) => TOutput | Promise); -} From fe36ae1b634dc18a67fd2241e921be265e225621 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Tue, 27 Feb 2024 12:37:34 -0800 Subject: [PATCH 13/21] Add `isOfType` utility and refactor type guard implementations --- .../src/methods/getDefaults/getDefaults.ts | 20 +++++++++----- .../methods/getDefaults/getDefaultsAsync.ts | 27 ++++++++++++++++--- .../src/methods/getFallbacks/getFallbacks.ts | 20 +++++++++----- .../methods/getFallbacks/getFallbacksAsync.ts | 27 ++++++++++++++++--- library/src/schemas/object/index.ts | 1 - library/src/schemas/object/isObjectSchema.ts | 10 ------- library/src/schemas/tuple/index.ts | 1 - library/src/schemas/tuple/isTupleSchema.ts | 10 ------- library/src/utils/index.ts | 3 +-- library/src/utils/isNonNullable.ts | 27 ------------------- library/src/utils/isOfType.ts | 7 +++++ library/src/utils/isSchema.ts | 12 --------- 12 files changed, 82 insertions(+), 83 deletions(-) delete mode 100644 library/src/schemas/object/isObjectSchema.ts delete mode 100644 library/src/schemas/tuple/isTupleSchema.ts delete mode 100644 library/src/utils/isNonNullable.ts create mode 100644 library/src/utils/isOfType.ts delete mode 100644 library/src/utils/isSchema.ts diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index 2eba49abf..3fef58cfc 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -1,4 +1,11 @@ -import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; +import type { + ObjectEntries, + ObjectSchema, + TupleItems, + TupleSchema, +} from '../../schemas/index.ts'; +import type { BaseSchema } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefault, type SchemaWithMaybeDefault, @@ -16,16 +23,17 @@ import type { DefaultValues } from './types.ts'; * * @returns The default values. */ -export function getDefaults( - schema: TSchema -): DefaultValues | undefined { +export function getDefaults< + TSchema extends SchemaWithMaybeDefault & + (BaseSchema | ObjectSchema | TupleSchema) +>(schema: TSchema): DefaultValues | undefined { // If schema contains a default function, set its default value if (schema.default !== undefined) { return getDefault(schema); } // Otherwise, check if schema is of kind object or tuple // If it is an object schema, set object with default value of each entry - if (isObjectSchema(schema)) { + if (isOfType(schema, 'object')) { return Object.fromEntries( Object.entries(schema.entries).map(([key, value]) => [ key, @@ -34,7 +42,7 @@ export function getDefaults( ) as DefaultValues; } // If it is a tuple schema, set array with default value of each item - if (isTupleSchema(schema)) { + if (isOfType(schema, 'tuple')) { return schema.items.map(getDefaults) as DefaultValues; } } diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index 74a337505..9bda63a52 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -1,4 +1,15 @@ -import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; +import type { + ObjectEntries, + ObjectEntriesAsync, + ObjectSchema, + ObjectSchemaAsync, + TupleItems, + TupleItemsAsync, + TupleSchema, + TupleSchemaAsync, +} from '../../schemas/index.ts'; +import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefaultAsync, type SchemaWithMaybeDefault, @@ -18,7 +29,15 @@ import type { DefaultValues } from './types.ts'; * @returns The default values. */ export async function getDefaultsAsync< - TSchema extends SchemaWithMaybeDefault | SchemaWithMaybeDefaultAsync + TSchema extends + | (SchemaWithMaybeDefault & + (BaseSchema | ObjectSchema | TupleSchema)) + | (SchemaWithMaybeDefaultAsync & + ( + | BaseSchemaAsync + | ObjectSchemaAsync + | TupleSchemaAsync + )) >(schema: TSchema): Promise | undefined> { // If schema contains a default function, set its default value if (schema.default !== undefined) { @@ -26,7 +45,7 @@ export async function getDefaultsAsync< } // Otherwise, check if schema is of kind object or tuple // If it is an object schema, set object with default value of each entry - if (isObjectSchema(schema)) { + if (isOfType(schema, 'object')) { return Object.fromEntries( await Promise.all( Object.entries(schema.entries).map(async ([key, value]) => [ @@ -37,7 +56,7 @@ export async function getDefaultsAsync< ); } // If it is a tuple schema, set array with default value of each item - if (isTupleSchema(schema)) { + if (isOfType(schema, 'tuple')) { return Promise.all( schema.items.map(getDefaultsAsync) ) as DefaultValues; diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index eda70f9fe..c062370d9 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -1,4 +1,11 @@ -import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; +import type { + ObjectEntries, + ObjectSchema, + TupleItems, + TupleSchema, +} from '../../schemas/index.ts'; +import type { BaseSchema } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallback, type SchemaWithMaybeFallback, @@ -16,16 +23,17 @@ import type { FallbackValues } from './types.ts'; * * @returns The fallback values. */ -export function getFallbacks( - schema: TSchema -): FallbackValues | undefined { +export function getFallbacks< + TSchema extends SchemaWithMaybeFallback & + (BaseSchema | ObjectSchema | TupleSchema) +>(schema: TSchema): FallbackValues | undefined { // If schema has a fallback, set its value if (schema.fallback !== undefined) { return getFallback(schema); } // Otherwise, check if schema is of kind object or tuple // If it is an object schema, set object with fallback value of each entry - if (isObjectSchema(schema)) { + if (isOfType(schema, 'object')) { return Object.entries(schema.entries).reduce( (hash, [key, value]) => Object.assign(hash, { [key]: getFallbacks(value) }), @@ -33,7 +41,7 @@ export function getFallbacks( ) as FallbackValues; } // If it is a tuple schema, set array with fallback value of each item - if (isTupleSchema(schema)) { + if (isOfType(schema, 'tuple')) { return schema.items.map(getFallbacks) as FallbackValues; } } diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 67d12f15a..6147eb2fe 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -1,4 +1,15 @@ -import { isObjectSchema, isTupleSchema } from '../../schemas/index.ts'; +import type { + ObjectEntries, + ObjectEntriesAsync, + ObjectSchema, + ObjectSchemaAsync, + TupleItems, + TupleItemsAsync, + TupleSchema, + TupleSchemaAsync, +} from '../../schemas/index.ts'; +import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallbackAsync, type SchemaWithMaybeFallback, @@ -18,7 +29,15 @@ import type { FallbackValues } from './types.ts'; * @returns The fallback values. */ export async function getFallbacksAsync< - TSchema extends SchemaWithMaybeFallback | SchemaWithMaybeFallbackAsync + TSchema extends + | (SchemaWithMaybeFallback & + (BaseSchema | ObjectSchema | TupleSchema)) + | (SchemaWithMaybeFallbackAsync & + ( + | BaseSchemaAsync + | ObjectSchemaAsync + | TupleSchemaAsync + )) >(schema: TSchema): Promise | undefined> { // If schema has a fallback, set its value if (schema.fallback !== undefined) { @@ -26,7 +45,7 @@ export async function getFallbacksAsync< } // Otherwise, check if schema is of kind object or tuple // If it is an object schema, set object with fallback value of each entry - if (isObjectSchema(schema)) { + if (isOfType(schema, 'object')) { return Object.fromEntries( await Promise.all( Object.entries(schema.entries).map(async ([key, value]) => [ @@ -37,7 +56,7 @@ export async function getFallbacksAsync< ); } // If it is a tuple schema, set array with fallback value of each item - if (isTupleSchema(schema)) { + if (isOfType(schema, 'tuple')) { return Promise.all( schema.items.map(getFallbacksAsync) ) as FallbackValues; diff --git a/library/src/schemas/object/index.ts b/library/src/schemas/object/index.ts index 19b9a6508..e56eae4b7 100644 --- a/library/src/schemas/object/index.ts +++ b/library/src/schemas/object/index.ts @@ -1,4 +1,3 @@ export * from './object.ts'; -export * from './isObjectSchema.ts'; export * from './objectAsync.ts'; export * from './types.ts'; diff --git a/library/src/schemas/object/isObjectSchema.ts b/library/src/schemas/object/isObjectSchema.ts deleted file mode 100644 index 5510cbd5c..000000000 --- a/library/src/schemas/object/isObjectSchema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { isSchema } from '../../utils/isSchema.ts'; -import type { ObjectEntries, ObjectSchema } from './object.ts'; -import type { ObjectEntriesAsync, ObjectSchemaAsync } from './objectAsync.ts'; - -export const isObjectSchema = ( - val: unknown -): val is - | ObjectSchema - | ObjectSchemaAsync => - isSchema(val) && val.type === `object`; diff --git a/library/src/schemas/tuple/index.ts b/library/src/schemas/tuple/index.ts index 49451b83e..3ad498f30 100644 --- a/library/src/schemas/tuple/index.ts +++ b/library/src/schemas/tuple/index.ts @@ -1,4 +1,3 @@ -export * from './isTupleSchema.ts'; export * from './tuple.ts'; export * from './tupleAsync.ts'; export * from './types.ts'; diff --git a/library/src/schemas/tuple/isTupleSchema.ts b/library/src/schemas/tuple/isTupleSchema.ts deleted file mode 100644 index 36e4c4186..000000000 --- a/library/src/schemas/tuple/isTupleSchema.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { isSchema } from '../../utils/isSchema.ts'; -import type { TupleItems, TupleSchema } from './tuple.ts'; -import type { TupleItemsAsync, TupleSchemaAsync } from './tupleAsync.ts'; - -export const isTupleSchema = ( - val: unknown -): val is - | TupleSchema - | TupleSchemaAsync => - isSchema(val) && val.type === `tuple`; diff --git a/library/src/utils/index.ts b/library/src/utils/index.ts index ef51250c9..87d374a8b 100644 --- a/library/src/utils/index.ts +++ b/library/src/utils/index.ts @@ -3,8 +3,7 @@ export * from './actionOutput/index.ts'; export * from './defaultArgs/index.ts'; export * from './i18n/index.ts'; export * from './isLuhnAlgo/index.ts'; -export * from './isNonNullable.ts'; -export * from './isSchema.ts'; +export * from './isOfType.ts'; export * from './pipeResult/index.ts'; export * from './restAndDefaultArgs/index.ts'; export * from './schemaIssue/index.ts'; diff --git a/library/src/utils/isNonNullable.ts b/library/src/utils/isNonNullable.ts deleted file mode 100644 index 0f6eb5e7c..000000000 --- a/library/src/utils/isNonNullable.ts +++ /dev/null @@ -1,27 +0,0 @@ -export type Maybe = T | null | undefined; - -/** - * Used to test whether a `Maybe` typed value is `null` or `undefined`. - * - * When called, the given value's type is narrowed to `NonNullable`. - * - * @param val The value to be checked. - * - * @returns Whether the value is non-nullable. - * - * ### Example Usage: - * - * ```ts - * const fn = (str: Maybe) => { - * if (!isNonNullable(str)) { - * // typeof str = null | undefined - * // ... - * } - * // typeof str = string - * // ... - * } - * ``` - */ -export const isNonNullable = >( - val?: T -): val is NonNullable => typeof val !== `undefined` && val !== null; diff --git a/library/src/utils/isOfType.ts b/library/src/utils/isOfType.ts new file mode 100644 index 000000000..e01ba9b0a --- /dev/null +++ b/library/src/utils/isOfType.ts @@ -0,0 +1,7 @@ +export const isOfType = < + U extends { type: string }, + const T extends string = string +>( + val: U, + type: T +): val is Extract => val?.type === type; diff --git a/library/src/utils/isSchema.ts b/library/src/utils/isSchema.ts deleted file mode 100644 index af992dbbb..000000000 --- a/library/src/utils/isSchema.ts +++ /dev/null @@ -1,12 +0,0 @@ -import type { BaseSchema, BaseSchemaAsync } from '../types/schema.ts'; -import { isNonNullable } from './isNonNullable.ts'; - -export const isSchema = (val: unknown): val is BaseSchema | BaseSchemaAsync => - isNonNullable(val) && - typeof val === `object` && - 'type' in val && - typeof val.type === `string` && - 'async' in val && - typeof val.async === `boolean` && - '_parse' in val && - typeof val._parse === `function`; From 02b17d558fdf1c61ba245154d913f672d10687f9 Mon Sep 17 00:00:00 2001 From: Drake Costa Date: Mon, 4 Mar 2024 13:35:08 -0800 Subject: [PATCH 14/21] run prettier and fix lint warnings --- library/src/error/flatten/flatten.ts | 100 ++++++++++-------- library/src/methods/brand/brand.ts | 4 +- library/src/methods/fallback/fallback.ts | 5 +- library/src/methods/fallback/fallbackAsync.ts | 2 +- library/src/methods/forward/forwardAsync.ts | 2 +- .../src/methods/getDefault/getDefaultAsync.ts | 2 +- .../src/methods/getDefaults/getDefaults.ts | 2 +- .../methods/getDefaults/getDefaultsAsync.ts | 2 +- library/src/methods/getDefaults/types.ts | 16 +-- library/src/methods/getFallback/types.ts | 17 +-- .../src/methods/getFallbacks/getFallbacks.ts | 2 +- .../methods/getFallbacks/getFallbacksAsync.ts | 2 +- library/src/methods/getFallbacks/types.ts | 23 ++-- library/src/methods/keyof/keyof.ts | 11 +- library/src/methods/merge/merge.ts | 8 +- library/src/methods/merge/mergeAsync.ts | 8 +- library/src/methods/merge/types.ts | 28 ++--- library/src/methods/omit/omit.ts | 10 +- library/src/methods/omit/omitAsync.ts | 10 +- library/src/methods/partial/partial.ts | 6 +- library/src/methods/partial/partialAsync.ts | 10 +- .../src/methods/passthrough/passthrough.ts | 2 +- .../methods/passthrough/passthroughAsync.ts | 2 +- library/src/methods/pick/pick.ts | 10 +- library/src/methods/pick/pickAsync.ts | 10 +- library/src/methods/required/required.ts | 6 +- library/src/methods/required/requiredAsync.ts | 10 +- .../src/methods/safeParse/safeParse.test.ts | 1 - .../methods/safeParse/safeParseAsync.test.ts | 1 - .../src/methods/safeParse/safeParseAsync.ts | 2 +- library/src/methods/strict/strictAsync.ts | 2 +- library/src/methods/strip/stripAsync.ts | 2 +- .../src/methods/transform/transformAsync.ts | 8 +- library/src/methods/unwrap/unwrap.ts | 2 +- library/src/schemas/array/array.ts | 2 +- library/src/schemas/array/arrayAsync.ts | 2 +- library/src/schemas/enum/enumAsync.ts | 2 +- library/src/schemas/instance/instance.ts | 2 +- library/src/schemas/instance/instanceAsync.ts | 2 +- library/src/schemas/intersect/intersect.ts | 2 +- .../src/schemas/intersect/intersectAsync.ts | 4 +- library/src/schemas/intersect/types.ts | 25 ++--- library/src/schemas/lazy/lazy.ts | 2 +- library/src/schemas/lazy/lazyAsync.ts | 6 +- library/src/schemas/literal/literalAsync.ts | 2 +- library/src/schemas/map/map.ts | 2 +- library/src/schemas/map/mapAsync.ts | 8 +- library/src/schemas/map/types.ts | 4 +- .../src/schemas/nonNullable/nonNullable.ts | 2 +- .../schemas/nonNullable/nonNullableAsync.ts | 2 +- library/src/schemas/nonNullish/nonNullish.ts | 2 +- .../src/schemas/nonNullish/nonNullishAsync.ts | 2 +- .../src/schemas/nonOptional/nonOptional.ts | 2 +- .../schemas/nonOptional/nonOptionalAsync.ts | 2 +- library/src/schemas/nullable/nullable.ts | 6 +- library/src/schemas/nullable/nullableAsync.ts | 6 +- library/src/schemas/nullish/nullish.ts | 2 +- library/src/schemas/nullish/nullishAsync.ts | 2 +- library/src/schemas/object/object.ts | 2 +- library/src/schemas/object/objectAsync.ts | 2 +- library/src/schemas/optional/optional.ts | 2 +- library/src/schemas/optional/optionalAsync.ts | 2 +- library/src/schemas/picklist/picklist.ts | 2 +- library/src/schemas/picklist/picklistAsync.ts | 2 +- library/src/schemas/record/record.ts | 2 +- library/src/schemas/record/recordAsync.ts | 8 +- library/src/schemas/record/types.ts | 4 +- .../record/utils/recordArgs/recordArgs.ts | 2 +- library/src/schemas/set/set.ts | 2 +- library/src/schemas/set/setAsync.ts | 2 +- library/src/schemas/tuple/tuple.ts | 8 +- library/src/schemas/tuple/tupleAsync.ts | 10 +- library/src/schemas/union/union.ts | 2 +- library/src/schemas/union/unionAsync.ts | 2 +- library/src/schemas/variant/variant.ts | 10 +- library/src/schemas/variant/variantAsync.ts | 10 +- .../transformations/toMaxValue/toMaxValue.ts | 4 +- .../transformations/toMinValue/toMinValue.ts | 4 +- library/src/types/other.ts | 2 +- library/src/utils/hasType.ts | 2 +- library/src/utils/index.ts | 2 +- .../restAndDefaultArgs/restAndDefaultArgs.ts | 2 +- library/src/utils/stringify/stringify.ts | 4 +- library/src/validations/bytes/bytes.ts | 2 +- library/src/validations/endsWith/endsWith.ts | 2 +- library/src/validations/equal/equal.ts | 4 +- library/src/validations/excludes/excludes.ts | 2 +- library/src/validations/includes/includes.ts | 2 +- library/src/validations/length/length.ts | 2 +- library/src/validations/maxBytes/maxBytes.ts | 2 +- .../src/validations/maxLength/maxLength.ts | 2 +- library/src/validations/maxSize/maxSize.ts | 2 +- library/src/validations/maxValue/maxValue.ts | 2 +- library/src/validations/mimeType/mimeType.ts | 2 +- library/src/validations/minBytes/minBytes.ts | 2 +- .../src/validations/minLength/minLength.ts | 2 +- library/src/validations/minSize/minSize.ts | 2 +- library/src/validations/minValue/minValue.ts | 2 +- .../src/validations/multipleOf/multipleOf.ts | 2 +- library/src/validations/notBytes/notBytes.ts | 2 +- .../src/validations/notLength/notLength.ts | 2 +- library/src/validations/notSize/notSize.ts | 2 +- library/src/validations/notValue/notValue.ts | 2 +- library/src/validations/size/size.ts | 2 +- .../src/validations/startsWith/startsWith.ts | 2 +- library/src/validations/value/value.ts | 2 +- 106 files changed, 287 insertions(+), 276 deletions(-) diff --git a/library/src/error/flatten/flatten.ts b/library/src/error/flatten/flatten.ts index 939e8bbfc..e614a6019 100644 --- a/library/src/error/flatten/flatten.ts +++ b/library/src/error/flatten/flatten.ts @@ -66,52 +66,60 @@ type NestedPath = TSchema extends ArraySchema ? DotPath : TSchema extends ArraySchemaAsync< - infer TItem extends BaseSchema | BaseSchemaAsync - > - ? DotPath - : // Map - TSchema extends - | MapSchema - | MapSchemaAsync - ? DotPath, TValue> - : // Object - TSchema extends - | ObjectSchema - | ObjectSchemaAsync - ? TRest extends NonNullable - ? ObjectPath | DotPath - : ObjectPath - : // Record - TSchema extends - | RecordSchema - | RecordSchemaAsync - ? DotPath, TValue> - : // Lazy - TSchema extends LazySchema BaseSchema> - ? NestedPath> - : TSchema extends LazySchemaAsync< - infer TSchemaGetter extends () => BaseSchema | BaseSchemaAsync - > - ? NestedPath> - : // Set - TSchema extends SetSchema | SetSchemaAsync - ? DotPath - : // Tuple - TSchema extends - | TupleSchema - | TupleSchemaAsync - ? TRest extends NonNullable - ? TuplePath | DotPath - : TuplePath - : // Union - TSchema extends UnionSchema - ? NestedPath - : TSchema extends UnionSchemaAsync< - infer TUnionOptions extends UnionOptionsAsync - > - ? NestedPath - : // Otherwise - never; + infer TItem extends BaseSchema | BaseSchemaAsync + > + ? DotPath + : // Map + TSchema extends + | MapSchema + | MapSchemaAsync + ? DotPath, TValue> + : // Object + TSchema extends + | ObjectSchema + | ObjectSchemaAsync + ? TRest extends NonNullable + ? ObjectPath | DotPath + : ObjectPath + : // Record + TSchema extends + | RecordSchema + | RecordSchemaAsync + ? DotPath, TValue> + : // Lazy + TSchema extends LazySchema< + infer TSchemaGetter extends () => BaseSchema + > + ? NestedPath> + : TSchema extends LazySchemaAsync< + infer TSchemaGetter extends () => + | BaseSchema + | BaseSchemaAsync + > + ? NestedPath> + : // Set + TSchema extends + | SetSchema + | SetSchemaAsync + ? DotPath + : // Tuple + TSchema extends + | TupleSchema + | TupleSchemaAsync + ? TRest extends NonNullable + ? TuplePath | DotPath + : TuplePath + : // Union + TSchema extends UnionSchema< + infer TUnionOptions extends UnionOptions + > + ? NestedPath + : TSchema extends UnionSchemaAsync< + infer TUnionOptions extends UnionOptionsAsync + > + ? NestedPath + : // Otherwise + never; /** * Flat errors type. diff --git a/library/src/methods/brand/brand.ts b/library/src/methods/brand/brand.ts index 9fa6781f0..4acd3c16a 100644 --- a/library/src/methods/brand/brand.ts +++ b/library/src/methods/brand/brand.ts @@ -27,7 +27,7 @@ export type Brand = { */ export type SchemaWithBrand< TSchema extends BaseSchema | BaseSchemaAsync, - TName extends BrandName + TName extends BrandName, > = Omit & { _types?: { input: Input; @@ -45,7 +45,7 @@ export type SchemaWithBrand< */ export function brand< TSchema extends BaseSchema | BaseSchemaAsync, - TName extends BrandName + TName extends BrandName, >( schema: TSchema, // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/library/src/methods/fallback/fallback.ts b/library/src/methods/fallback/fallback.ts index 4bd0efdd3..e69592fb8 100644 --- a/library/src/methods/fallback/fallback.ts +++ b/library/src/methods/fallback/fallback.ts @@ -26,9 +26,8 @@ export interface SchemaWithFallback */ export function fallback< TSchema extends BaseSchema, - const TFallback extends // TODO: Should we also allow `undefined` - | Output - | ((info?: FallbackInfo) => Output) + const TFallback extends // TODO: Should we also allow `undefined` + Output | ((info?: FallbackInfo) => Output), >( schema: TSchema, fallback: TFallback diff --git a/library/src/methods/fallback/fallbackAsync.ts b/library/src/methods/fallback/fallbackAsync.ts index 1a6f856d5..0cc590e23 100644 --- a/library/src/methods/fallback/fallbackAsync.ts +++ b/library/src/methods/fallback/fallbackAsync.ts @@ -26,7 +26,7 @@ export function fallbackAsync< TSchema extends BaseSchemaAsync, const TFallback extends | Output - | ((info?: FallbackInfo) => Output | Promise>) + | ((info?: FallbackInfo) => Output | Promise>), >( schema: TSchema, fallback: TFallback diff --git a/library/src/methods/forward/forwardAsync.ts b/library/src/methods/forward/forwardAsync.ts index 39c4c6514..36971f3c4 100644 --- a/library/src/methods/forward/forwardAsync.ts +++ b/library/src/methods/forward/forwardAsync.ts @@ -10,7 +10,7 @@ import type { PathList } from './types.ts'; * @returns The passed validation. */ export function forwardAsync< - TInput extends unknown[] | Record + TInput extends unknown[] | Record, >( validation: BaseValidationAsync, pathList: PathList diff --git a/library/src/methods/getDefault/getDefaultAsync.ts b/library/src/methods/getDefault/getDefaultAsync.ts index 9c0460b45..2f3dce61b 100644 --- a/library/src/methods/getDefault/getDefaultAsync.ts +++ b/library/src/methods/getDefault/getDefaultAsync.ts @@ -12,7 +12,7 @@ import type { * @returns The default value. */ export async function getDefaultAsync< - TSchema extends SchemaWithMaybeDefault | SchemaWithMaybeDefaultAsync + TSchema extends SchemaWithMaybeDefault | SchemaWithMaybeDefaultAsync, >(schema: TSchema): Promise> { return typeof schema.default === 'function' ? await schema.default() diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index dfe0a112d..ea2d5e79e 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -25,7 +25,7 @@ import type { DefaultValues } from './types.ts'; */ export function getDefaults< TSchema extends SchemaWithMaybeDefault & - (BaseSchema | ObjectSchema | TupleSchema) + (BaseSchema | ObjectSchema | TupleSchema), >(schema: TSchema): DefaultValues | undefined { // If schema contains a default function, set its default value if (schema.default !== undefined) { diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index e560c6916..e60759aa3 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -37,7 +37,7 @@ export async function getDefaultsAsync< | BaseSchemaAsync | ObjectSchemaAsync | TupleSchemaAsync - )) + )), >(schema: TSchema): Promise | undefined> { // If schema contains a default function, set its default value if (schema.default !== undefined) { diff --git a/library/src/methods/getDefaults/types.ts b/library/src/methods/getDefaults/types.ts index 1aa8aebe8..20cdee78a 100644 --- a/library/src/methods/getDefaults/types.ts +++ b/library/src/methods/getDefaults/types.ts @@ -16,11 +16,11 @@ export type DefaultValues = TSchema extends ObjectSchema ? { [TKey in keyof TEntries]: DefaultValues } : TSchema extends ObjectSchemaAsync< - infer TEntries extends ObjectEntriesAsync - > - ? { [TKey in keyof TEntries]: DefaultValues } - : TSchema extends TupleSchema - ? { [TKey in keyof TItems]: DefaultValues } - : TSchema extends TupleSchemaAsync - ? { [TKey in keyof TItems]: DefaultValues } - : DefaultValue; + infer TEntries extends ObjectEntriesAsync + > + ? { [TKey in keyof TEntries]: DefaultValues } + : TSchema extends TupleSchema + ? { [TKey in keyof TItems]: DefaultValues } + : TSchema extends TupleSchemaAsync + ? { [TKey in keyof TItems]: DefaultValues } + : DefaultValue; diff --git a/library/src/methods/getFallback/types.ts b/library/src/methods/getFallback/types.ts index 99e645781..bd4844ad3 100644 --- a/library/src/methods/getFallback/types.ts +++ b/library/src/methods/getFallback/types.ts @@ -27,11 +27,12 @@ export interface SchemaWithMaybeFallbackAsync * Fallback value inference type. */ export type FallbackValue< - TSchema extends SchemaWithMaybeFallback | SchemaWithMaybeFallbackAsync -> = TSchema['fallback'] extends Output - ? TSchema['fallback'] - : TSchema['fallback'] extends () => Output - ? ReturnType - : TSchema['fallback'] extends () => Promise> - ? Awaited> - : undefined; + TSchema extends SchemaWithMaybeFallback | SchemaWithMaybeFallbackAsync, +> = + TSchema['fallback'] extends Output + ? TSchema['fallback'] + : TSchema['fallback'] extends () => Output + ? ReturnType + : TSchema['fallback'] extends () => Promise> + ? Awaited> + : undefined; diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index 33420acb1..a602981c3 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -25,7 +25,7 @@ import type { FallbackValues } from './types.ts'; */ export function getFallbacks< TSchema extends SchemaWithMaybeFallback & - (BaseSchema | ObjectSchema | TupleSchema) + (BaseSchema | ObjectSchema | TupleSchema), >(schema: TSchema): FallbackValues | undefined { // If schema has a fallback, set its value if (schema.fallback !== undefined) { diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 4e5c9eed8..09097c754 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -37,7 +37,7 @@ export async function getFallbacksAsync< | BaseSchemaAsync | ObjectSchemaAsync | TupleSchemaAsync - )) + )), >(schema: TSchema): Promise | undefined> { // If schema has a fallback, set its value if (schema.fallback !== undefined) { diff --git a/library/src/methods/getFallbacks/types.ts b/library/src/methods/getFallbacks/types.ts index b4218d4d6..2c2c6cd50 100644 --- a/library/src/methods/getFallbacks/types.ts +++ b/library/src/methods/getFallbacks/types.ts @@ -29,13 +29,16 @@ export type FallbackValues< | BaseSchemaAsync | ObjectSchemaAsync | TupleSchemaAsync - > -> = TSchema extends ObjectSchema - ? { [TKey in keyof TEntries]: FallbackValues } - : TSchema extends ObjectSchemaAsync - ? { [TKey in keyof TEntries]: FallbackValues } - : TSchema extends TupleSchema - ? { [TKey in keyof TItems]: FallbackValues } - : TSchema extends TupleSchemaAsync - ? { [TKey in keyof TItems]: FallbackValues } - : FallbackValue; + >, +> = + TSchema extends ObjectSchema + ? { [TKey in keyof TEntries]: FallbackValues } + : TSchema extends ObjectSchemaAsync< + infer TEntries extends ObjectEntriesAsync + > + ? { [TKey in keyof TEntries]: FallbackValues } + : TSchema extends TupleSchema + ? { [TKey in keyof TItems]: FallbackValues } + : TSchema extends TupleSchemaAsync + ? { [TKey in keyof TItems]: FallbackValues } + : FallbackValue; diff --git a/library/src/methods/keyof/keyof.ts b/library/src/methods/keyof/keyof.ts index 6553c28b1..730193841 100644 --- a/library/src/methods/keyof/keyof.ts +++ b/library/src/methods/keyof/keyof.ts @@ -17,11 +17,10 @@ type UnionToIntersection = ( /** * Converts union to tuple types. */ -type UnionToTuple = UnionToIntersection< - T extends never ? never : () => T -> extends () => infer W - ? [...UnionToTuple>, W] - : []; +type UnionToTuple = + UnionToIntersection T> extends () => infer W + ? [...UnionToTuple>, W] + : []; /** * Returns a tuple or never type. @@ -36,7 +35,7 @@ type TupleOrNever = T extends [string, ...string[]] ? T : never; * @returns A picklist schema. */ export function keyof< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, >( schema: TSchema ): PicklistSchema>> { diff --git a/library/src/methods/merge/merge.ts b/library/src/methods/merge/merge.ts index 627c7308f..aa11db40d 100644 --- a/library/src/methods/merge/merge.ts +++ b/library/src/methods/merge/merge.ts @@ -13,7 +13,7 @@ import type { MergeObjects } from './types.ts'; type ObjectSchemas = [ ObjectSchema, ObjectSchema, - ...ObjectSchema[] + ...ObjectSchema[], ]; /** @@ -58,7 +58,7 @@ export function merge( */ export function merge< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schemas: TSchemas, rest: TRest, @@ -78,7 +78,7 @@ export function merge< */ export function merge< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schemas: TSchemas, rest: TRest, @@ -88,7 +88,7 @@ export function merge< export function merge< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schemas: TSchemas, arg2?: diff --git a/library/src/methods/merge/mergeAsync.ts b/library/src/methods/merge/mergeAsync.ts index e66edc5db..6f74174b0 100644 --- a/library/src/methods/merge/mergeAsync.ts +++ b/library/src/methods/merge/mergeAsync.ts @@ -19,7 +19,7 @@ import type { MergeObjects } from './types.ts'; type ObjectSchemas = [ ObjectSchema | ObjectSchemaAsync, ObjectSchema | ObjectSchemaAsync, - ...(ObjectSchema | ObjectSchemaAsync)[] + ...(ObjectSchema | ObjectSchemaAsync)[], ]; /** @@ -64,7 +64,7 @@ export function mergeAsync( */ export function mergeAsync< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schemas: TSchemas, rest: TRest, @@ -84,7 +84,7 @@ export function mergeAsync< */ export function mergeAsync< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schemas: TSchemas, rest: TRest, @@ -94,7 +94,7 @@ export function mergeAsync< export function mergeAsync< TSchemas extends ObjectSchemas, - TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, >( schemas: TSchemas, arg2?: diff --git a/library/src/methods/merge/types.ts b/library/src/methods/merge/types.ts index 74a40ca34..b26729d35 100644 --- a/library/src/methods/merge/types.ts +++ b/library/src/methods/merge/types.ts @@ -4,23 +4,23 @@ import type { ObjectSchema, ObjectSchemaAsync } from '../../schemas/index.ts'; * Merges objects types. */ export type MergeObjects< - TSchemas extends (ObjectSchema | ObjectSchemaAsync)[] + TSchemas extends (ObjectSchema | ObjectSchemaAsync)[], > = TSchemas extends [infer TFirstSchema] ? TFirstSchema extends ObjectSchema | ObjectSchemaAsync ? TFirstSchema['entries'] : never : TSchemas extends [infer TFirstSchema, ...infer TRestSchemas] - ? TFirstSchema extends ObjectSchema | ObjectSchemaAsync - ? TRestSchemas extends ( - | ObjectSchema - | ObjectSchemaAsync - )[] - ? { - [TKey in Exclude< - keyof TFirstSchema['entries'], - keyof MergeObjects - >]: TFirstSchema['entries'][TKey]; - } & MergeObjects + ? TFirstSchema extends ObjectSchema | ObjectSchemaAsync + ? TRestSchemas extends ( + | ObjectSchema + | ObjectSchemaAsync + )[] + ? { + [TKey in Exclude< + keyof TFirstSchema['entries'], + keyof MergeObjects + >]: TFirstSchema['entries'][TKey]; + } & MergeObjects + : never : never - : never - : never; + : never; diff --git a/library/src/methods/omit/omit.ts b/library/src/methods/omit/omit.ts index 999a8cc74..38a102af1 100644 --- a/library/src/methods/omit/omit.ts +++ b/library/src/methods/omit/omit.ts @@ -23,7 +23,7 @@ import { restAndDefaultArgs } from '../../utils/index.ts'; */ export function omit< TSchema extends ObjectSchema, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -43,7 +43,7 @@ export function omit< */ export function omit< TSchema extends ObjectSchema, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -65,7 +65,7 @@ export function omit< export function omit< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, keys: TKeys, @@ -88,7 +88,7 @@ export function omit< export function omit< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, keys: TKeys, @@ -100,7 +100,7 @@ export function omit< export function omit< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schema: TSchema, keys: TKeys, diff --git a/library/src/methods/omit/omitAsync.ts b/library/src/methods/omit/omitAsync.ts index a99225d67..3473b6093 100644 --- a/library/src/methods/omit/omitAsync.ts +++ b/library/src/methods/omit/omitAsync.ts @@ -25,7 +25,7 @@ import { restAndDefaultArgs } from '../../utils/index.ts'; */ export function omitAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -47,7 +47,7 @@ export function omitAsync< */ export function omitAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -71,7 +71,7 @@ export function omitAsync< export function omitAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, keys: TKeys, @@ -94,7 +94,7 @@ export function omitAsync< export function omitAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, keys: TKeys, @@ -106,7 +106,7 @@ export function omitAsync< export function omitAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, >( schema: TSchema, keys: TKeys, diff --git a/library/src/methods/partial/partial.ts b/library/src/methods/partial/partial.ts index ff9553b6d..4e9a71ed8 100644 --- a/library/src/methods/partial/partial.ts +++ b/library/src/methods/partial/partial.ts @@ -58,7 +58,7 @@ export function partial>( */ export function partial< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -78,7 +78,7 @@ export function partial< */ export function partial< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -88,7 +88,7 @@ export function partial< export function partial< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schema: TSchema, arg2?: diff --git a/library/src/methods/partial/partialAsync.ts b/library/src/methods/partial/partialAsync.ts index 0c2a35c59..18c7b1194 100644 --- a/library/src/methods/partial/partialAsync.ts +++ b/library/src/methods/partial/partialAsync.ts @@ -32,7 +32,7 @@ export type PartialObjectEntriesAsync = { * @returns An async object schema. */ export function partialAsync< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, >( schema: TSchema, pipe?: PipeAsync< @@ -51,7 +51,7 @@ export function partialAsync< * @returns An async object schema. */ export function partialAsync< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, >( schema: TSchema, message?: ErrorMessage, @@ -72,7 +72,7 @@ export function partialAsync< */ export function partialAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -94,7 +94,7 @@ export function partialAsync< */ export function partialAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -106,7 +106,7 @@ export function partialAsync< export function partialAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schema: TSchema, arg2?: diff --git a/library/src/methods/passthrough/passthrough.ts b/library/src/methods/passthrough/passthrough.ts index 7465a7ef5..4da90f827 100644 --- a/library/src/methods/passthrough/passthrough.ts +++ b/library/src/methods/passthrough/passthrough.ts @@ -13,7 +13,7 @@ import type { * @returns A object schema. */ export function passthrough< - TSchema extends ObjectSchema + TSchema extends ObjectSchema, >(schema: TSchema): TSchema { return { ...schema, diff --git a/library/src/methods/passthrough/passthroughAsync.ts b/library/src/methods/passthrough/passthroughAsync.ts index 6a69f3dde..ace170bd7 100644 --- a/library/src/methods/passthrough/passthroughAsync.ts +++ b/library/src/methods/passthrough/passthroughAsync.ts @@ -13,7 +13,7 @@ import type { * @returns A object schema. */ export function passthroughAsync< - TSchema extends ObjectSchemaAsync + TSchema extends ObjectSchemaAsync, >(schema: TSchema): TSchema { return { ...schema, diff --git a/library/src/methods/pick/pick.ts b/library/src/methods/pick/pick.ts index 2a1f55547..e11ace13e 100644 --- a/library/src/methods/pick/pick.ts +++ b/library/src/methods/pick/pick.ts @@ -23,7 +23,7 @@ import { restAndDefaultArgs } from '../../utils/index.ts'; */ export function pick< TSchema extends ObjectSchema, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -43,7 +43,7 @@ export function pick< */ export function pick< TSchema extends ObjectSchema, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -65,7 +65,7 @@ export function pick< export function pick< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, keys: TKeys, @@ -88,7 +88,7 @@ export function pick< export function pick< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, keys: TKeys, @@ -100,7 +100,7 @@ export function pick< export function pick< TSchema extends ObjectSchema, TKeys extends ObjectKeys, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schema: TSchema, keys: TKeys, diff --git a/library/src/methods/pick/pickAsync.ts b/library/src/methods/pick/pickAsync.ts index 2ffc61637..25fb733aa 100644 --- a/library/src/methods/pick/pickAsync.ts +++ b/library/src/methods/pick/pickAsync.ts @@ -25,7 +25,7 @@ import { restAndDefaultArgs } from '../../utils/index.ts'; */ export function pickAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -47,7 +47,7 @@ export function pickAsync< */ export function pickAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TKeys extends ObjectKeys + TKeys extends ObjectKeys, >( schema: TSchema, keys: TKeys, @@ -71,7 +71,7 @@ export function pickAsync< export function pickAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, keys: TKeys, @@ -94,7 +94,7 @@ export function pickAsync< export function pickAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, keys: TKeys, @@ -106,7 +106,7 @@ export function pickAsync< export function pickAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, TKeys extends ObjectKeys, - TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, >( schema: TSchema, keys: TKeys, diff --git a/library/src/methods/required/required.ts b/library/src/methods/required/required.ts index 186797810..b286c14c2 100644 --- a/library/src/methods/required/required.ts +++ b/library/src/methods/required/required.ts @@ -58,7 +58,7 @@ export function required>( */ export function required< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -78,7 +78,7 @@ export function required< */ export function required< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( schema: TSchema, rest: TRest, @@ -88,7 +88,7 @@ export function required< export function required< TSchema extends ObjectSchema, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( schema: TSchema, arg2?: diff --git a/library/src/methods/required/requiredAsync.ts b/library/src/methods/required/requiredAsync.ts index 45a0ba964..ad5ed53ad 100644 --- a/library/src/methods/required/requiredAsync.ts +++ b/library/src/methods/required/requiredAsync.ts @@ -32,7 +32,7 @@ type Required = { * @returns An async object schema. */ export function requiredAsync< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, >( schema: TSchema, pipe?: PipeAsync, undefined>> @@ -49,7 +49,7 @@ export function requiredAsync< * @returns An async object schema. */ export function requiredAsync< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, >( schema: TSchema, message?: ErrorMessage, @@ -68,7 +68,7 @@ export function requiredAsync< */ export function requiredAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, rest: TRest, @@ -88,7 +88,7 @@ export function requiredAsync< */ export function requiredAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( schema: TSchema, rest: TRest, @@ -98,7 +98,7 @@ export function requiredAsync< export function requiredAsync< TSchema extends ObjectSchema | ObjectSchemaAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, >( schema: TSchema, arg2?: 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/methods/safeParse/safeParseAsync.ts b/library/src/methods/safeParse/safeParseAsync.ts index 7f7a24981..74eae53f6 100644 --- a/library/src/methods/safeParse/safeParseAsync.ts +++ b/library/src/methods/safeParse/safeParseAsync.ts @@ -16,7 +16,7 @@ import type { SafeParseResult } from './types.ts'; * @returns The parsed output. */ export async function safeParseAsync< - TSchema extends BaseSchema | BaseSchemaAsync + TSchema extends BaseSchema | BaseSchemaAsync, >( schema: TSchema, input: unknown, diff --git a/library/src/methods/strict/strictAsync.ts b/library/src/methods/strict/strictAsync.ts index c0e50df8f..5f86cd9c4 100644 --- a/library/src/methods/strict/strictAsync.ts +++ b/library/src/methods/strict/strictAsync.ts @@ -16,7 +16,7 @@ import { schemaIssue } from '../../utils/index.ts'; * @returns A strict object schema. */ export function strictAsync< - TSchema extends ObjectSchemaAsync + TSchema extends ObjectSchemaAsync, >(schema: TSchema): TSchema { return { ...schema, diff --git a/library/src/methods/strip/stripAsync.ts b/library/src/methods/strip/stripAsync.ts index 68ce230e9..3680962b9 100644 --- a/library/src/methods/strip/stripAsync.ts +++ b/library/src/methods/strip/stripAsync.ts @@ -13,7 +13,7 @@ import type { * @returns A object schema. */ export function stripAsync< - TSchema extends ObjectSchemaAsync + TSchema extends ObjectSchemaAsync, >(schema: TSchema): TSchema { // Create cached keys let cachedKeys: string[]; diff --git a/library/src/methods/transform/transformAsync.ts b/library/src/methods/transform/transformAsync.ts index 796b205e1..3a650bb19 100644 --- a/library/src/methods/transform/transformAsync.ts +++ b/library/src/methods/transform/transformAsync.ts @@ -15,7 +15,7 @@ import type { TransformInfo } from './types.ts'; */ export type SchemaWithTransformAsync< TSchema extends BaseSchema | BaseSchemaAsync, - TOutput + TOutput, > = Omit & { async: true; _parse(input: unknown, config?: SchemaConfig): Promise>; @@ -37,7 +37,7 @@ export type SchemaWithTransformAsync< */ export function transformAsync< TSchema extends BaseSchema | BaseSchemaAsync, - TOutput + TOutput, >( schema: TSchema, action: ( @@ -59,7 +59,7 @@ export function transformAsync< */ export function transformAsync< TSchema extends BaseSchema | BaseSchemaAsync, - TOutput + TOutput, >( schema: TSchema, action: ( @@ -71,7 +71,7 @@ export function transformAsync< export function transformAsync< TSchema extends BaseSchema | BaseSchemaAsync, - TOutput + TOutput, >( schema: TSchema, action: ( diff --git a/library/src/methods/unwrap/unwrap.ts b/library/src/methods/unwrap/unwrap.ts index 45921b4aa..5422599ee 100644 --- a/library/src/methods/unwrap/unwrap.ts +++ b/library/src/methods/unwrap/unwrap.ts @@ -33,7 +33,7 @@ export function unwrap< | NonNullableSchema | NonNullableSchemaAsync | NonNullishSchema - | NonNullishSchemaAsync + | NonNullishSchemaAsync, >(schema: TSchema): TSchema['wrapped'] { return schema.wrapped; } diff --git a/library/src/schemas/array/array.ts b/library/src/schemas/array/array.ts index 09d0eb022..709ef0e47 100644 --- a/library/src/schemas/array/array.ts +++ b/library/src/schemas/array/array.ts @@ -19,7 +19,7 @@ import type { ArrayPathItem } from './types.ts'; */ export interface ArraySchema< TItem extends BaseSchema, - TOutput = Output[] + TOutput = Output[], > extends BaseSchema[], TOutput> { /** * The schema type. diff --git a/library/src/schemas/array/arrayAsync.ts b/library/src/schemas/array/arrayAsync.ts index ae2ef21ac..19b57f87a 100644 --- a/library/src/schemas/array/arrayAsync.ts +++ b/library/src/schemas/array/arrayAsync.ts @@ -20,7 +20,7 @@ import type { ArrayPathItem } from './types.ts'; */ export interface ArraySchemaAsync< TItem extends BaseSchema | BaseSchemaAsync, - TOutput = Output[] + TOutput = Output[], > extends BaseSchemaAsync[], TOutput> { /** * The schema type. diff --git a/library/src/schemas/enum/enumAsync.ts b/library/src/schemas/enum/enumAsync.ts index f676bf90d..f2dc8accd 100644 --- a/library/src/schemas/enum/enumAsync.ts +++ b/library/src/schemas/enum/enumAsync.ts @@ -7,7 +7,7 @@ import type { Enum } from './enum.ts'; */ export interface EnumSchemaAsync< TEnum extends Enum, - TOutput = TEnum[keyof TEnum] + TOutput = TEnum[keyof TEnum], > extends BaseSchemaAsync { /** * The schema type. diff --git a/library/src/schemas/instance/instance.ts b/library/src/schemas/instance/instance.ts index c8ca02eaf..56ff50717 100644 --- a/library/src/schemas/instance/instance.ts +++ b/library/src/schemas/instance/instance.ts @@ -7,7 +7,7 @@ import type { Class } from './types.ts'; */ export interface InstanceSchema< TClass extends Class, - TOutput = InstanceType + TOutput = InstanceType, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/instance/instanceAsync.ts b/library/src/schemas/instance/instanceAsync.ts index f0ddabf1b..1f201ddba 100644 --- a/library/src/schemas/instance/instanceAsync.ts +++ b/library/src/schemas/instance/instanceAsync.ts @@ -15,7 +15,7 @@ import type { Class } from './types.ts'; */ export interface InstanceSchemaAsync< TClass extends Class, - TOutput = InstanceType + TOutput = InstanceType, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/intersect/intersect.ts b/library/src/schemas/intersect/intersect.ts index 8deaeb88f..6271b4179 100644 --- a/library/src/schemas/intersect/intersect.ts +++ b/library/src/schemas/intersect/intersect.ts @@ -26,7 +26,7 @@ export type IntersectOptions = MaybeReadonly< */ export interface IntersectSchema< TOptions extends IntersectOptions, - TOutput = IntersectOutput + TOutput = IntersectOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/intersect/intersectAsync.ts b/library/src/schemas/intersect/intersectAsync.ts index b0ee71b9b..8f13c04ce 100644 --- a/library/src/schemas/intersect/intersectAsync.ts +++ b/library/src/schemas/intersect/intersectAsync.ts @@ -22,7 +22,7 @@ export type IntersectOptionsAsync = MaybeReadonly< [ BaseSchema | BaseSchemaAsync, BaseSchema | BaseSchemaAsync, - ...(BaseSchema[] | BaseSchemaAsync[]) + ...(BaseSchema[] | BaseSchemaAsync[]), ] >; @@ -31,7 +31,7 @@ export type IntersectOptionsAsync = MaybeReadonly< */ export interface IntersectSchemaAsync< TOptions extends IntersectOptionsAsync, - TOutput = IntersectOutput + TOutput = IntersectOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/intersect/types.ts b/library/src/schemas/intersect/types.ts index 62ca60abf..682b30734 100644 --- a/library/src/schemas/intersect/types.ts +++ b/library/src/schemas/intersect/types.ts @@ -6,34 +6,35 @@ import type { IntersectOptionsAsync } from './intersectAsync.ts'; * Intersect input inference type. */ export type IntersectInput< - TIntersectOptions extends IntersectOptions | IntersectOptionsAsync + TIntersectOptions extends IntersectOptions | IntersectOptionsAsync, > = TIntersectOptions extends [ BaseSchema | BaseSchemaAsync, - ...infer TRest + ...infer TRest, ] ? TRest extends IntersectOptions ? TInput1 & IntersectOutput : TRest extends [ - BaseSchema | BaseSchemaAsync - ] - ? TInput1 & TInput2 - : never + BaseSchema | BaseSchemaAsync, + ] + ? TInput1 & TInput2 + : never : never; /** * Intersect output inference type. */ export type IntersectOutput< - TIntersectOptions extends IntersectOptions | IntersectOptionsAsync + TIntersectOptions extends IntersectOptions | IntersectOptionsAsync, > = TIntersectOptions extends [ BaseSchema | BaseSchemaAsync, - ...infer TRest + ...infer TRest, ] ? TRest extends IntersectOptions ? TOutput1 & IntersectOutput : TRest extends [ - BaseSchema | BaseSchemaAsync - ] - ? TOutput1 & TOutput2 - : never + | BaseSchema + | BaseSchemaAsync, + ] + ? TOutput1 & TOutput2 + : never : never; diff --git a/library/src/schemas/lazy/lazy.ts b/library/src/schemas/lazy/lazy.ts index 6a564816b..b212a084b 100644 --- a/library/src/schemas/lazy/lazy.ts +++ b/library/src/schemas/lazy/lazy.ts @@ -5,7 +5,7 @@ import type { BaseSchema, Input, Output } from '../../types/index.ts'; */ export interface LazySchema< TGetter extends (input: unknown) => BaseSchema, - TOutput = Output> + TOutput = Output>, > extends BaseSchema>, TOutput> { /** * The schema type. diff --git a/library/src/schemas/lazy/lazyAsync.ts b/library/src/schemas/lazy/lazyAsync.ts index 689d51a7a..77d4231c5 100644 --- a/library/src/schemas/lazy/lazyAsync.ts +++ b/library/src/schemas/lazy/lazyAsync.ts @@ -13,7 +13,7 @@ export interface LazySchemaAsync< TGetter extends ( input: unknown ) => MaybePromise, - TOutput = Output>> + TOutput = Output>>, > extends BaseSchemaAsync>>, TOutput> { /** * The schema type. @@ -33,7 +33,9 @@ export interface LazySchemaAsync< * @returns An async lazy schema. */ export function lazyAsync< - TGetter extends (input: unknown) => MaybePromise + TGetter extends ( + input: unknown + ) => MaybePromise, >(getter: TGetter): LazySchemaAsync { return { type: 'lazy', diff --git a/library/src/schemas/literal/literalAsync.ts b/library/src/schemas/literal/literalAsync.ts index 034efaa26..5daa5b6b9 100644 --- a/library/src/schemas/literal/literalAsync.ts +++ b/library/src/schemas/literal/literalAsync.ts @@ -7,7 +7,7 @@ import type { Literal } from './types.ts'; */ export interface LiteralSchemaAsync< TLiteral extends Literal, - TOutput = TLiteral + TOutput = TLiteral, > extends BaseSchemaAsync { /** * The schema type. diff --git a/library/src/schemas/map/map.ts b/library/src/schemas/map/map.ts index 46fdbeacd..3b32bfb0a 100644 --- a/library/src/schemas/map/map.ts +++ b/library/src/schemas/map/map.ts @@ -19,7 +19,7 @@ import type { MapInput, MapOutput, MapPathItem } from './types.ts'; export interface MapSchema< TKey extends BaseSchema, TValue extends BaseSchema, - TOutput = MapOutput + TOutput = MapOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/map/mapAsync.ts b/library/src/schemas/map/mapAsync.ts index 287e37093..bc3ded5d0 100644 --- a/library/src/schemas/map/mapAsync.ts +++ b/library/src/schemas/map/mapAsync.ts @@ -20,7 +20,7 @@ import type { MapInput, MapOutput, MapPathItem } from './types.ts'; export interface MapSchemaAsync< TKey extends BaseSchema | BaseSchemaAsync, TValue extends BaseSchema | BaseSchemaAsync, - TOutput = MapOutput + TOutput = MapOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. @@ -55,7 +55,7 @@ export interface MapSchemaAsync< */ export function mapAsync< TKey extends BaseSchema | BaseSchemaAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( key: TKey, value: TValue, @@ -74,7 +74,7 @@ export function mapAsync< */ export function mapAsync< TKey extends BaseSchema | BaseSchemaAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( key: TKey, value: TValue, @@ -84,7 +84,7 @@ export function mapAsync< export function mapAsync< TKey extends BaseSchema | BaseSchemaAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( key: TKey, value: TValue, diff --git a/library/src/schemas/map/types.ts b/library/src/schemas/map/types.ts index 9f665c831..c2e5d562b 100644 --- a/library/src/schemas/map/types.ts +++ b/library/src/schemas/map/types.ts @@ -21,7 +21,7 @@ export type MapPathItem = { */ export type MapInput< TKey extends BaseSchema | BaseSchemaAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, > = Map, Input>; /** @@ -29,5 +29,5 @@ export type MapInput< */ export type MapOutput< TKey extends BaseSchema | BaseSchemaAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, > = Map, Output>; diff --git a/library/src/schemas/nonNullable/nonNullable.ts b/library/src/schemas/nonNullable/nonNullable.ts index 7c73159dd..1e20d01cc 100644 --- a/library/src/schemas/nonNullable/nonNullable.ts +++ b/library/src/schemas/nonNullable/nonNullable.ts @@ -7,7 +7,7 @@ import type { NonNullableInput, NonNullableOutput } from './types.ts'; */ export interface NonNullableSchema< TWrapped extends BaseSchema, - TOutput = NonNullableOutput + TOutput = NonNullableOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nonNullable/nonNullableAsync.ts b/library/src/schemas/nonNullable/nonNullableAsync.ts index 826e1cc45..be7f04853 100644 --- a/library/src/schemas/nonNullable/nonNullableAsync.ts +++ b/library/src/schemas/nonNullable/nonNullableAsync.ts @@ -11,7 +11,7 @@ import type { NonNullableInput, NonNullableOutput } from './types.ts'; */ export interface NonNullableSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TOutput = NonNullableOutput + TOutput = NonNullableOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nonNullish/nonNullish.ts b/library/src/schemas/nonNullish/nonNullish.ts index 5611990f3..4005a5b2f 100644 --- a/library/src/schemas/nonNullish/nonNullish.ts +++ b/library/src/schemas/nonNullish/nonNullish.ts @@ -7,7 +7,7 @@ import type { NonNullishInput, NonNullishOutput } from './types.ts'; */ export interface NonNullishSchema< TWrapped extends BaseSchema, - TOutput = NonNullishOutput + TOutput = NonNullishOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nonNullish/nonNullishAsync.ts b/library/src/schemas/nonNullish/nonNullishAsync.ts index 4f5720ad1..5b43078a9 100644 --- a/library/src/schemas/nonNullish/nonNullishAsync.ts +++ b/library/src/schemas/nonNullish/nonNullishAsync.ts @@ -11,7 +11,7 @@ import type { NonNullishInput, NonNullishOutput } from './types.ts'; */ export interface NonNullishSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TOutput = NonNullishOutput + TOutput = NonNullishOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nonOptional/nonOptional.ts b/library/src/schemas/nonOptional/nonOptional.ts index b83803a5e..dbf6cc854 100644 --- a/library/src/schemas/nonOptional/nonOptional.ts +++ b/library/src/schemas/nonOptional/nonOptional.ts @@ -7,7 +7,7 @@ import type { NonOptionalInput, NonOptionalOutput } from './types.ts'; */ export interface NonOptionalSchema< TWrapped extends BaseSchema, - TOutput = NonOptionalOutput + TOutput = NonOptionalOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nonOptional/nonOptionalAsync.ts b/library/src/schemas/nonOptional/nonOptionalAsync.ts index 8b804b8e5..3990e856b 100644 --- a/library/src/schemas/nonOptional/nonOptionalAsync.ts +++ b/library/src/schemas/nonOptional/nonOptionalAsync.ts @@ -11,7 +11,7 @@ import type { NonOptionalInput, NonOptionalOutput } from './types.ts'; */ export interface NonOptionalSchemaAsync< TWrapped extends BaseSchema | BaseSchemaAsync, - TOutput = NonOptionalOutput + TOutput = NonOptionalOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nullable/nullable.ts b/library/src/schemas/nullable/nullable.ts index 437ebceda..f4037fb62 100644 --- a/library/src/schemas/nullable/nullable.ts +++ b/library/src/schemas/nullable/nullable.ts @@ -13,7 +13,7 @@ export interface NullableSchema< | undefined = undefined, TOutput = TDefault extends Input | (() => Input) ? Output - : Output | null + : Output | null, > extends BaseSchema | null, TOutput> { /** * The schema type. @@ -53,7 +53,7 @@ export function nullable< TDefault extends | Input | (() => Input | undefined) - | undefined + | undefined, >(wrapped: TWrapped, default_: TDefault): NullableSchema; export function nullable< @@ -61,7 +61,7 @@ export function nullable< TDefault extends | Input | (() => Input | undefined) - | undefined = undefined + | undefined = 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 254d1f365..f7c018fdf 100644 --- a/library/src/schemas/nullable/nullableAsync.ts +++ b/library/src/schemas/nullable/nullableAsync.ts @@ -20,7 +20,7 @@ export interface NullableSchemaAsync< | Input | (() => Input | Promise>) ? Output - : Output | null + : Output | null, > extends BaseSchemaAsync | null, TOutput> { /** * The schema type. @@ -60,7 +60,7 @@ export function nullableAsync< TDefault extends | Input | (() => Input | Promise | undefined> | undefined) - | undefined + | undefined, >( wrapped: TWrapped, default_: TDefault @@ -71,7 +71,7 @@ export function nullableAsync< TDefault extends | Input | (() => Input | Promise | undefined> | undefined) - | undefined = undefined + | undefined = undefined, >( wrapped: TWrapped, default_?: TDefault diff --git a/library/src/schemas/nullish/nullish.ts b/library/src/schemas/nullish/nullish.ts index 0f87dd21e..ac9adf81d 100644 --- a/library/src/schemas/nullish/nullish.ts +++ b/library/src/schemas/nullish/nullish.ts @@ -13,7 +13,7 @@ export interface NullishSchema< | undefined = undefined, TOutput = TDefault extends Input | (() => Input) ? Output - : Output | null | undefined + : Output | null | undefined, > extends BaseSchema | null | undefined, TOutput> { /** * The schema type. diff --git a/library/src/schemas/nullish/nullishAsync.ts b/library/src/schemas/nullish/nullishAsync.ts index cf78d5e76..1375e504c 100644 --- a/library/src/schemas/nullish/nullishAsync.ts +++ b/library/src/schemas/nullish/nullishAsync.ts @@ -20,7 +20,7 @@ export interface NullishSchemaAsync< | Input | (() => Input | Promise>) ? Output - : Output | null | undefined + : Output | null | undefined, > extends BaseSchemaAsync | null | undefined, TOutput> { /** * The schema type. diff --git a/library/src/schemas/object/object.ts b/library/src/schemas/object/object.ts index a3e22ac53..9383c30c6 100644 --- a/library/src/schemas/object/object.ts +++ b/library/src/schemas/object/object.ts @@ -23,7 +23,7 @@ export type ObjectEntries = Record; export interface ObjectSchema< TEntries extends ObjectEntries, TRest extends BaseSchema | undefined = undefined, - TOutput = ObjectOutput + TOutput = ObjectOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/object/objectAsync.ts b/library/src/schemas/object/objectAsync.ts index 433b32159..99b4c4756 100644 --- a/library/src/schemas/object/objectAsync.ts +++ b/library/src/schemas/object/objectAsync.ts @@ -24,7 +24,7 @@ export type ObjectEntriesAsync = Record; export interface ObjectSchemaAsync< TEntries extends ObjectEntriesAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, - TOutput = ObjectOutput + TOutput = ObjectOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/optional/optional.ts b/library/src/schemas/optional/optional.ts index e17a15f54..a596be6dd 100644 --- a/library/src/schemas/optional/optional.ts +++ b/library/src/schemas/optional/optional.ts @@ -13,7 +13,7 @@ export interface OptionalSchema< | undefined = undefined, TOutput = TDefault extends Input | (() => Input) ? Output - : Output | undefined + : Output | undefined, > extends BaseSchema | undefined, TOutput> { /** * The schema type. diff --git a/library/src/schemas/optional/optionalAsync.ts b/library/src/schemas/optional/optionalAsync.ts index c89cc1934..d17dc6cc0 100644 --- a/library/src/schemas/optional/optionalAsync.ts +++ b/library/src/schemas/optional/optionalAsync.ts @@ -20,7 +20,7 @@ export interface OptionalSchemaAsync< | Input | (() => Input | Promise>) ? Output - : Output | undefined + : Output | undefined, > extends BaseSchemaAsync | undefined, TOutput> { /** * The schema type. diff --git a/library/src/schemas/picklist/picklist.ts b/library/src/schemas/picklist/picklist.ts index 0d113d087..031368104 100644 --- a/library/src/schemas/picklist/picklist.ts +++ b/library/src/schemas/picklist/picklist.ts @@ -7,7 +7,7 @@ import type { PicklistOptions } from './types.ts'; */ export interface PicklistSchema< TOptions extends PicklistOptions, - TOutput = TOptions[number] + TOutput = TOptions[number], > extends BaseSchema { /** * The schema type. diff --git a/library/src/schemas/picklist/picklistAsync.ts b/library/src/schemas/picklist/picklistAsync.ts index c9f71f0d5..8ecf895b3 100644 --- a/library/src/schemas/picklist/picklistAsync.ts +++ b/library/src/schemas/picklist/picklistAsync.ts @@ -7,7 +7,7 @@ import type { PicklistOptions } from './types.ts'; */ export interface PicklistSchemaAsync< TOptions extends PicklistOptions, - TOutput = TOptions[number] + TOutput = TOptions[number], > extends BaseSchemaAsync { /** * The schema type. diff --git a/library/src/schemas/record/record.ts b/library/src/schemas/record/record.ts index 9e91e7d90..2fbe89b68 100644 --- a/library/src/schemas/record/record.ts +++ b/library/src/schemas/record/record.ts @@ -30,7 +30,7 @@ export type RecordKey = export interface RecordSchema< TKey extends RecordKey, TValue extends BaseSchema, - TOutput = RecordOutput + TOutput = RecordOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/record/recordAsync.ts b/library/src/schemas/record/recordAsync.ts index 8f58293cb..d40c83517 100644 --- a/library/src/schemas/record/recordAsync.ts +++ b/library/src/schemas/record/recordAsync.ts @@ -40,7 +40,7 @@ export type RecordKeyAsync = export interface RecordSchemaAsync< TKey extends RecordKeyAsync, TValue extends BaseSchema | BaseSchemaAsync, - TOutput = RecordOutput + TOutput = RecordOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. @@ -103,7 +103,7 @@ export function recordAsync( */ export function recordAsync< TKey extends RecordKeyAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( key: TKey, value: TValue, @@ -122,7 +122,7 @@ export function recordAsync< */ export function recordAsync< TKey extends RecordKeyAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( key: TKey, value: TValue, @@ -132,7 +132,7 @@ export function recordAsync< export function recordAsync< TKey extends RecordKeyAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, >( arg1: TValue | TKey, arg2?: PipeAsync> | ErrorMessage | TValue, diff --git a/library/src/schemas/record/types.ts b/library/src/schemas/record/types.ts index 366e6d26f..41f59b473 100644 --- a/library/src/schemas/record/types.ts +++ b/library/src/schemas/record/types.ts @@ -38,7 +38,7 @@ type PartialKeySchema = */ export type RecordInput< TKey extends RecordKey | RecordKeyAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, > = ResolveObject< TKey extends PartialKeySchema ? Partial, Input>> @@ -50,7 +50,7 @@ export type RecordInput< */ export type RecordOutput< TKey extends RecordKey | RecordKeyAsync, - TValue extends BaseSchema | BaseSchemaAsync + TValue extends BaseSchema | BaseSchemaAsync, > = ResolveObject< TKey extends PartialKeySchema ? Partial, Output>> diff --git a/library/src/schemas/record/utils/recordArgs/recordArgs.ts b/library/src/schemas/record/utils/recordArgs/recordArgs.ts index eb90ab576..cefc98fb6 100644 --- a/library/src/schemas/record/utils/recordArgs/recordArgs.ts +++ b/library/src/schemas/record/utils/recordArgs/recordArgs.ts @@ -23,7 +23,7 @@ import type { RecordKeyAsync } from '../../recordAsync.ts'; export function recordArgs< TKey extends RecordKey | RecordKeyAsync, TValue extends BaseSchema | BaseSchemaAsync, - TPipe extends Pipe | PipeAsync + TPipe extends Pipe | PipeAsync, >( arg1: TValue | TKey, arg2: TPipe | ErrorMessage | TValue | undefined, diff --git a/library/src/schemas/set/set.ts b/library/src/schemas/set/set.ts index 4c8bb7018..6397c99f0 100644 --- a/library/src/schemas/set/set.ts +++ b/library/src/schemas/set/set.ts @@ -17,7 +17,7 @@ import type { SetInput, SetOutput, SetPathItem } from './types.ts'; */ export interface SetSchema< TValue extends BaseSchema, - TOutput = SetOutput + TOutput = SetOutput, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/set/setAsync.ts b/library/src/schemas/set/setAsync.ts index 4f1f2214c..f74a28979 100644 --- a/library/src/schemas/set/setAsync.ts +++ b/library/src/schemas/set/setAsync.ts @@ -18,7 +18,7 @@ import type { SetInput, SetOutput, SetPathItem } from './types.ts'; */ export interface SetSchemaAsync< TValue extends BaseSchema | BaseSchemaAsync, - TOutput = SetOutput + TOutput = SetOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/tuple/tuple.ts b/library/src/schemas/tuple/tuple.ts index 4f521362c..04039cf68 100644 --- a/library/src/schemas/tuple/tuple.ts +++ b/library/src/schemas/tuple/tuple.ts @@ -23,7 +23,7 @@ export type TupleItems = [BaseSchema, ...BaseSchema[]]; export interface TupleSchema< TItems extends TupleItems, TRest extends BaseSchema | undefined = undefined, - TOutput = TupleOutput + TOutput = TupleOutput, > extends BaseSchema, TOutput> { /** * The schema type. @@ -86,7 +86,7 @@ export function tuple( */ export function tuple< TItems extends TupleItems, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( items: TItems, rest: TRest, @@ -105,7 +105,7 @@ export function tuple< */ export function tuple< TItems extends TupleItems, - TRest extends BaseSchema | undefined + TRest extends BaseSchema | undefined, >( items: TItems, rest: TRest, @@ -115,7 +115,7 @@ export function tuple< export function tuple< TItems extends TupleItems, - TRest extends BaseSchema | undefined = undefined + TRest extends BaseSchema | undefined = undefined, >( items: TItems, arg2?: Pipe> | ErrorMessage | TRest, diff --git a/library/src/schemas/tuple/tupleAsync.ts b/library/src/schemas/tuple/tupleAsync.ts index ee4addcf4..76475e1ff 100644 --- a/library/src/schemas/tuple/tupleAsync.ts +++ b/library/src/schemas/tuple/tupleAsync.ts @@ -18,7 +18,7 @@ import type { TupleInput, TupleOutput, TuplePathItem } from './types.ts'; */ export type TupleItemsAsync = [ BaseSchema | BaseSchemaAsync, - ...(BaseSchema | BaseSchemaAsync)[] + ...(BaseSchema | BaseSchemaAsync)[], ]; /** @@ -27,7 +27,7 @@ export type TupleItemsAsync = [ export interface TupleSchemaAsync< TItems extends TupleItemsAsync, TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, - TOutput = TupleOutput + TOutput = TupleOutput, > extends BaseSchemaAsync, TOutput> { /** * The schema type. @@ -90,7 +90,7 @@ export function tupleAsync( */ export function tupleAsync< TItems extends TupleItemsAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( items: TItems, rest: TRest, @@ -109,7 +109,7 @@ export function tupleAsync< */ export function tupleAsync< TItems extends TupleItemsAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined, >( items: TItems, rest: TRest, @@ -119,7 +119,7 @@ export function tupleAsync< export function tupleAsync< TItems extends TupleItemsAsync, - TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined + TRest extends BaseSchema | BaseSchemaAsync | undefined = undefined, >( items: TItems, arg2?: PipeAsync> | ErrorMessage | TRest, diff --git a/library/src/schemas/union/union.ts b/library/src/schemas/union/union.ts index 10d36bee0..78925896e 100644 --- a/library/src/schemas/union/union.ts +++ b/library/src/schemas/union/union.ts @@ -21,7 +21,7 @@ export type UnionOptions = MaybeReadonly; */ export interface UnionSchema< TOptions extends UnionOptions, - TOutput = Output + TOutput = Output, > extends BaseSchema, TOutput> { /** * The schema type. diff --git a/library/src/schemas/union/unionAsync.ts b/library/src/schemas/union/unionAsync.ts index 7fb87cebf..1e79f1393 100644 --- a/library/src/schemas/union/unionAsync.ts +++ b/library/src/schemas/union/unionAsync.ts @@ -26,7 +26,7 @@ export type UnionOptionsAsync = MaybeReadonly<(BaseSchema | BaseSchemaAsync)[]>; */ export interface UnionSchemaAsync< TOptions extends UnionOptionsAsync, - TOutput = Output + TOutput = Output, > extends BaseSchemaAsync, TOutput> { /** * The schema type. diff --git a/library/src/schemas/variant/variant.ts b/library/src/schemas/variant/variant.ts index 371a1f693..d1acad300 100644 --- a/library/src/schemas/variant/variant.ts +++ b/library/src/schemas/variant/variant.ts @@ -25,7 +25,7 @@ export type VariantOption = export type VariantOptions = [ VariantOption, VariantOption, - ...VariantOption[] + ...VariantOption[], ]; /** @@ -34,7 +34,7 @@ export type VariantOptions = [ export interface VariantSchema< TKey extends string, TOptions extends VariantOptions, - TOutput = Output + TOutput = Output, > extends BaseSchema, TOutput> { /** * The schema type. @@ -69,7 +69,7 @@ export interface VariantSchema< */ export function variant< TKey extends string, - TOptions extends VariantOptions + TOptions extends VariantOptions, >( key: TKey, options: TOptions, @@ -88,7 +88,7 @@ export function variant< */ export function variant< TKey extends string, - TOptions extends VariantOptions + TOptions extends VariantOptions, >( key: TKey, options: TOptions, @@ -98,7 +98,7 @@ export function variant< export function variant< TKey extends string, - TOptions extends VariantOptions + TOptions extends VariantOptions, >( key: TKey, options: TOptions, diff --git a/library/src/schemas/variant/variantAsync.ts b/library/src/schemas/variant/variantAsync.ts index 9c2b9d14b..dfd94febe 100644 --- a/library/src/schemas/variant/variantAsync.ts +++ b/library/src/schemas/variant/variantAsync.ts @@ -31,7 +31,7 @@ export type VariantOptionAsync = export type VariantOptionsAsync = [ VariantOptionAsync, VariantOptionAsync, - ...VariantOptionAsync[] + ...VariantOptionAsync[], ]; /** @@ -40,7 +40,7 @@ export type VariantOptionsAsync = [ export interface VariantSchemaAsync< TKey extends string, TOptions extends VariantOptionsAsync, - TOutput = Output + TOutput = Output, > extends BaseSchemaAsync, TOutput> { /** * The schema type. @@ -75,7 +75,7 @@ export interface VariantSchemaAsync< */ export function variantAsync< TKey extends string, - TOptions extends VariantOptionsAsync + TOptions extends VariantOptionsAsync, >( key: TKey, options: TOptions, @@ -94,7 +94,7 @@ export function variantAsync< */ export function variantAsync< TKey extends string, - TOptions extends VariantOptionsAsync + TOptions extends VariantOptionsAsync, >( key: TKey, options: TOptions, @@ -104,7 +104,7 @@ export function variantAsync< export function variantAsync< TKey extends string, - TOptions extends VariantOptionsAsync + TOptions extends VariantOptionsAsync, >( key: TKey, options: TOptions, diff --git a/library/src/transformations/toMaxValue/toMaxValue.ts b/library/src/transformations/toMaxValue/toMaxValue.ts index ce883bcb5..671c764e4 100644 --- a/library/src/transformations/toMaxValue/toMaxValue.ts +++ b/library/src/transformations/toMaxValue/toMaxValue.ts @@ -6,7 +6,7 @@ import { actionOutput } from '../../utils/index.ts'; */ export interface ToMaxValueTransformation< TInput extends string | number | bigint | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseTransformation { /** * The transformation type. @@ -28,7 +28,7 @@ export interface ToMaxValueTransformation< */ export function toMaxValue< TInput extends string | number | bigint | Date, - TRequirement extends TInput + TRequirement extends TInput, >(requirement: TRequirement): ToMaxValueTransformation { return { type: 'to_max_value', diff --git a/library/src/transformations/toMinValue/toMinValue.ts b/library/src/transformations/toMinValue/toMinValue.ts index 8a6050df5..f3cca4192 100644 --- a/library/src/transformations/toMinValue/toMinValue.ts +++ b/library/src/transformations/toMinValue/toMinValue.ts @@ -6,7 +6,7 @@ import { actionOutput } from '../../utils/index.ts'; */ export interface ToMinValueTransformation< TInput extends string | number | bigint | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseTransformation { /** * The transformation type. @@ -28,7 +28,7 @@ export interface ToMinValueTransformation< */ export function toMinValue< TInput extends string | number | bigint | Date, - TRequirement extends TInput + TRequirement extends TInput, >(requirement: TRequirement): ToMinValueTransformation { return { type: 'to_min_value', diff --git a/library/src/types/other.ts b/library/src/types/other.ts index 3368d2d6d..453a12b12 100644 --- a/library/src/types/other.ts +++ b/library/src/types/other.ts @@ -4,7 +4,7 @@ import type { ObjectSchema, ObjectSchemaAsync } from '../schemas/index.ts'; * Object keys type. */ export type ObjectKeys< - TSchema extends ObjectSchema | ObjectSchemaAsync + TSchema extends ObjectSchema | ObjectSchemaAsync, > = MaybeReadonly<[keyof TSchema['entries'], ...(keyof TSchema['entries'])[]]>; /** diff --git a/library/src/utils/hasType.ts b/library/src/utils/hasType.ts index 28bba382f..d0585e83e 100644 --- a/library/src/utils/hasType.ts +++ b/library/src/utils/hasType.ts @@ -47,7 +47,7 @@ */ export const hasType = < U extends { type: string }, - const T extends string = string + const T extends string = string, >( val: U, type: T diff --git a/library/src/utils/index.ts b/library/src/utils/index.ts index 87d374a8b..18108da80 100644 --- a/library/src/utils/index.ts +++ b/library/src/utils/index.ts @@ -3,7 +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.ts'; +export * from './hasType.ts'; export * from './pipeResult/index.ts'; export * from './restAndDefaultArgs/index.ts'; export * from './schemaIssue/index.ts'; diff --git a/library/src/utils/restAndDefaultArgs/restAndDefaultArgs.ts b/library/src/utils/restAndDefaultArgs/restAndDefaultArgs.ts index 4a474090e..10fe70da7 100644 --- a/library/src/utils/restAndDefaultArgs/restAndDefaultArgs.ts +++ b/library/src/utils/restAndDefaultArgs/restAndDefaultArgs.ts @@ -18,7 +18,7 @@ import { defaultArgs } from '../defaultArgs/index.ts'; */ export function restAndDefaultArgs< TRest extends BaseSchema | BaseSchemaAsync | undefined, - TPipe extends Pipe | PipeAsync + TPipe extends Pipe | PipeAsync, >( arg1: TPipe | ErrorMessage | TRest | undefined, arg2: TPipe | ErrorMessage | undefined, diff --git a/library/src/utils/stringify/stringify.ts b/library/src/utils/stringify/stringify.ts index 0eeaa1771..2234f8d55 100644 --- a/library/src/utils/stringify/stringify.ts +++ b/library/src/utils/stringify/stringify.ts @@ -13,6 +13,6 @@ export function stringify(input: unknown): string { return type === 'string' ? `"${input}"` : type === 'number' || type === 'bigint' || type === 'boolean' - ? `${input}` - : type; + ? `${input}` + : type; } diff --git a/library/src/validations/bytes/bytes.ts b/library/src/validations/bytes/bytes.ts index 8d86eb050..bec499222 100644 --- a/library/src/validations/bytes/bytes.ts +++ b/library/src/validations/bytes/bytes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface BytesValidation< TInput extends string, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/endsWith/endsWith.ts b/library/src/validations/endsWith/endsWith.ts index 0a818fdc9..d6fd6a626 100644 --- a/library/src/validations/endsWith/endsWith.ts +++ b/library/src/validations/endsWith/endsWith.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface EndsWithValidation< TInput extends string, - TRequirement extends string + TRequirement extends string, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/equal/equal.ts b/library/src/validations/equal/equal.ts index c96cc4203..118fec28d 100644 --- a/library/src/validations/equal/equal.ts +++ b/library/src/validations/equal/equal.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface EqualValidation< TInput extends string | number | bigint | boolean, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseValidation { /** * The validation type. @@ -30,7 +30,7 @@ export interface EqualValidation< */ export function equal< TInput extends string | number | bigint | boolean, - TRequirement extends TInput + TRequirement extends TInput, >( requirement: TRequirement, message?: ErrorMessage diff --git a/library/src/validations/excludes/excludes.ts b/library/src/validations/excludes/excludes.ts index 9840f59c7..53aa4f556 100644 --- a/library/src/validations/excludes/excludes.ts +++ b/library/src/validations/excludes/excludes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface ExcludesValidation< TInput extends string | any[], - TRequirement extends TInput extends any[] ? TInput[number] : TInput + TRequirement extends TInput extends any[] ? TInput[number] : TInput, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/includes/includes.ts b/library/src/validations/includes/includes.ts index 2783b3f0e..49795d6bb 100644 --- a/library/src/validations/includes/includes.ts +++ b/library/src/validations/includes/includes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface IncludesValidation< TInput extends string | any[], - TRequirement extends TInput extends any[] ? TInput[number] : TInput + TRequirement extends TInput extends any[] ? TInput[number] : TInput, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/length/length.ts b/library/src/validations/length/length.ts index 3ff4282e5..08a75d404 100644 --- a/library/src/validations/length/length.ts +++ b/library/src/validations/length/length.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface LengthValidation< TInput extends string | any[], - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/maxBytes/maxBytes.ts b/library/src/validations/maxBytes/maxBytes.ts index 1a9d185fc..f131c3121 100644 --- a/library/src/validations/maxBytes/maxBytes.ts +++ b/library/src/validations/maxBytes/maxBytes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MaxBytesValidation< TInput extends string, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/maxLength/maxLength.ts b/library/src/validations/maxLength/maxLength.ts index 76bb8c9b4..1f36a8892 100644 --- a/library/src/validations/maxLength/maxLength.ts +++ b/library/src/validations/maxLength/maxLength.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MaxLengthValidation< TInput extends string | any[], - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/maxSize/maxSize.ts b/library/src/validations/maxSize/maxSize.ts index 0d3bcc394..26b71b51b 100644 --- a/library/src/validations/maxSize/maxSize.ts +++ b/library/src/validations/maxSize/maxSize.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MaxSizeValidation< TInput extends Map | Set | Blob, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/maxValue/maxValue.ts b/library/src/validations/maxValue/maxValue.ts index 1a3a13774..d0abf3f8c 100644 --- a/library/src/validations/maxValue/maxValue.ts +++ b/library/src/validations/maxValue/maxValue.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface MaxValueValidation< TInput extends string | number | bigint | boolean | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/mimeType/mimeType.ts b/library/src/validations/mimeType/mimeType.ts index b815aca83..8e7278af7 100644 --- a/library/src/validations/mimeType/mimeType.ts +++ b/library/src/validations/mimeType/mimeType.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MimeTypeValidation< TInput extends Blob, - TRequirement extends `${string}/${string}`[] + TRequirement extends `${string}/${string}`[], > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/minBytes/minBytes.ts b/library/src/validations/minBytes/minBytes.ts index da3503e0a..b373e8178 100644 --- a/library/src/validations/minBytes/minBytes.ts +++ b/library/src/validations/minBytes/minBytes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MinBytesValidation< TInput extends string, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/minLength/minLength.ts b/library/src/validations/minLength/minLength.ts index 40d84cb6a..9cfef0f4a 100644 --- a/library/src/validations/minLength/minLength.ts +++ b/library/src/validations/minLength/minLength.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MinLengthValidation< TInput extends string | any[], - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/minSize/minSize.ts b/library/src/validations/minSize/minSize.ts index 156840953..d10c6ebc2 100644 --- a/library/src/validations/minSize/minSize.ts +++ b/library/src/validations/minSize/minSize.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MinSizeValidation< TInput extends Map | Set | Blob, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/minValue/minValue.ts b/library/src/validations/minValue/minValue.ts index 6eabe2a69..4dbdfa6c2 100644 --- a/library/src/validations/minValue/minValue.ts +++ b/library/src/validations/minValue/minValue.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface MinValueValidation< TInput extends string | number | bigint | boolean | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/multipleOf/multipleOf.ts b/library/src/validations/multipleOf/multipleOf.ts index e23554fbb..645a5e267 100644 --- a/library/src/validations/multipleOf/multipleOf.ts +++ b/library/src/validations/multipleOf/multipleOf.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface MultipleOfValidation< TInput extends number, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/notBytes/notBytes.ts b/library/src/validations/notBytes/notBytes.ts index e4e259322..b8e140bc1 100644 --- a/library/src/validations/notBytes/notBytes.ts +++ b/library/src/validations/notBytes/notBytes.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface NotBytesValidation< TInput extends string, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/notLength/notLength.ts b/library/src/validations/notLength/notLength.ts index fc91bc076..d218885f4 100644 --- a/library/src/validations/notLength/notLength.ts +++ b/library/src/validations/notLength/notLength.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface NotLengthValidation< TInput extends string | any[], - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/notSize/notSize.ts b/library/src/validations/notSize/notSize.ts index 1339c6f3f..542113a5e 100644 --- a/library/src/validations/notSize/notSize.ts +++ b/library/src/validations/notSize/notSize.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface NotSizeValidation< TInput extends Map | Set | Blob, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/notValue/notValue.ts b/library/src/validations/notValue/notValue.ts index 7322dd759..5dc35a87e 100644 --- a/library/src/validations/notValue/notValue.ts +++ b/library/src/validations/notValue/notValue.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface NotValueValidation< TInput extends string | number | bigint | boolean | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/size/size.ts b/library/src/validations/size/size.ts index 2c7cc1c94..31a9aa738 100644 --- a/library/src/validations/size/size.ts +++ b/library/src/validations/size/size.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface SizeValidation< TInput extends Map | Set | Blob, - TRequirement extends number + TRequirement extends number, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/startsWith/startsWith.ts b/library/src/validations/startsWith/startsWith.ts index 322f7de99..fa75e234b 100644 --- a/library/src/validations/startsWith/startsWith.ts +++ b/library/src/validations/startsWith/startsWith.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput } from '../../utils/index.ts'; */ export interface StartsWithValidation< TInput extends string, - TRequirement extends string + TRequirement extends string, > extends BaseValidation { /** * The validation type. diff --git a/library/src/validations/value/value.ts b/library/src/validations/value/value.ts index c5266b2d1..d17d8ed39 100644 --- a/library/src/validations/value/value.ts +++ b/library/src/validations/value/value.ts @@ -6,7 +6,7 @@ import { actionIssue, actionOutput, stringify } from '../../utils/index.ts'; */ export interface ValueValidation< TInput extends string | number | bigint | boolean | Date, - TRequirement extends TInput + TRequirement extends TInput, > extends BaseValidation { /** * The validation type. From 2cefacc170ec5451467852db95bfb22b42a59541 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Tue, 5 Mar 2024 19:13:05 -0500 Subject: [PATCH 15/21] Add Default and DefaultAsync type and refactor codebase --- library/CHANGELOG.md | 1 + library/src/methods/getDefault/getDefault.ts | 16 ++++++++- .../src/methods/getDefault/getDefaultAsync.ts | 21 +++++++++--- library/src/methods/getDefault/types.ts | 34 ++++--------------- library/src/schemas/nullable/nullable.ts | 17 +++------- library/src/schemas/nullable/nullableAsync.ts | 16 +++------ library/src/schemas/nullish/nullish.ts | 17 +++------- library/src/schemas/nullish/nullishAsync.ts | 16 +++------ library/src/schemas/optional/optional.ts | 17 +++------- library/src/schemas/optional/optionalAsync.ts | 16 +++------ library/src/types/other.ts | 17 ++++++++++ 11 files changed, 79 insertions(+), 109 deletions(-) diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index 8b9a7aeb4..7edc62a22 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the library will be documented in this file. - Remove deprecated properties of `safeParse` and `safeParseAsync` method - Fix `NestedPath` type of `flatten` for async schemas (issue #456) +- Add `Default` and `DefaultAsync` type and refactor codebase ## v0.29.0 (February 19, 2024) diff --git a/library/src/methods/getDefault/getDefault.ts b/library/src/methods/getDefault/getDefault.ts index aa9d2e1e9..14ccf4fee 100644 --- a/library/src/methods/getDefault/getDefault.ts +++ b/library/src/methods/getDefault/getDefault.ts @@ -1,4 +1,18 @@ -import type { DefaultValue, SchemaWithMaybeDefault } from './types.ts'; +import type { BaseSchema, Default } from '../../types/index.ts'; +import type { DefaultValue } from './types.ts'; + +/** + * Schema with maybe default type. + */ +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 2f3dce61b..19ba6d2d8 100644 --- a/library/src/methods/getDefault/getDefaultAsync.ts +++ b/library/src/methods/getDefault/getDefaultAsync.ts @@ -1,8 +1,19 @@ -import type { - DefaultValue, - SchemaWithMaybeDefault, - SchemaWithMaybeDefaultAsync, -} from './types.ts'; +import type { BaseSchemaAsync, DefaultAsync } from '../../types/index.ts'; +import type { SchemaWithMaybeDefault } from './getDefault.ts'; +import type { DefaultValue } from './types.ts'; + +/** + * Schema with maybe default async type. + */ +export type SchemaWithMaybeDefaultAsync< + TSchema extends BaseSchemaAsync = BaseSchemaAsync, + TDefault extends DefaultAsync = DefaultAsync, +> = TSchema & { + /** + * The optional default value. + */ + default?: TDefault; +}; /** * Returns the default value of the schema. diff --git a/library/src/methods/getDefault/types.ts b/library/src/methods/getDefault/types.ts index a82e9bafb..c92e828f9 100644 --- a/library/src/methods/getDefault/types.ts +++ b/library/src/methods/getDefault/types.ts @@ -1,38 +1,16 @@ -import type { BaseSchema, BaseSchemaAsync, Output } from '../../types/index.ts'; - -/** - * Schema with maybe default type. - */ -export interface SchemaWithMaybeDefault - extends BaseSchema { - /** - * The optional default value. - */ - default?: TOutput | (() => TOutput | undefined); -} - -/** - * Schema with maybe default async type. - */ -export interface SchemaWithMaybeDefaultAsync - extends BaseSchemaAsync { - /** - * The optional default value. - */ - default?: - | TOutput - | (() => TOutput | Promise | undefined); -} +import type { Input } from '../../types/index.ts'; +import type { SchemaWithMaybeDefault } from './getDefault.ts'; +import type { SchemaWithMaybeDefaultAsync } from './getDefaultAsync.ts'; /** * Default value inference type. */ 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/schemas/nullable/nullable.ts b/library/src/schemas/nullable/nullable.ts index f4037fb62..da1977285 100644 --- a/library/src/schemas/nullable/nullable.ts +++ b/library/src/schemas/nullable/nullable.ts @@ -1,5 +1,5 @@ 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'; /** @@ -7,10 +7,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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, @@ -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 f7c018fdf..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'; @@ -12,10 +13,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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>) @@ -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 ac9adf81d..31c162a65 100644 --- a/library/src/schemas/nullish/nullish.ts +++ b/library/src/schemas/nullish/nullish.ts @@ -1,5 +1,5 @@ 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'; /** @@ -7,10 +7,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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, @@ -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 1375e504c..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'; @@ -12,10 +13,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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>) @@ -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/optional/optional.ts b/library/src/schemas/optional/optional.ts index a596be6dd..ef59b3591 100644 --- a/library/src/schemas/optional/optional.ts +++ b/library/src/schemas/optional/optional.ts @@ -1,5 +1,5 @@ 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'; /** @@ -7,10 +7,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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, @@ -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 d17dc6cc0..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'; @@ -12,10 +13,7 @@ import { schemaResult } from '../../utils/index.ts'; */ 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>) @@ -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/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. From 114b1f846dc3f66589e7cdc95ad7dd06ad831a9a Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Tue, 5 Mar 2024 19:14:26 -0500 Subject: [PATCH 16/21] Add Fallback and FallbackAsync type and refactor codebase --- library/CHANGELOG.md | 1 + library/src/methods/fallback/fallback.ts | 20 +++++++++----- library/src/methods/fallback/fallbackAsync.ts | 21 ++++++++++----- .../src/methods/getFallback/getFallback.ts | 17 +++++++++++- .../methods/getFallback/getFallbackAsync.ts | 22 +++++++++++---- library/src/methods/getFallback/types.ts | 27 +++---------------- 6 files changed, 64 insertions(+), 44 deletions(-) diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index 7edc62a22..c4804a1b2 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to the library will be documented in this file. - Remove deprecated properties of `safeParse` and `safeParseAsync` method - Fix `NestedPath` type of `flatten` for async schemas (issue #456) - Add `Default` and `DefaultAsync` type and refactor codebase +- Add `Fallback` and `FallbackAsync` type and refactor codebase ## v0.29.0 (February 19, 2024) diff --git a/library/src/methods/fallback/fallback.ts b/library/src/methods/fallback/fallback.ts index e69592fb8..e875a665b 100644 --- a/library/src/methods/fallback/fallback.ts +++ b/library/src/methods/fallback/fallback.ts @@ -3,18 +3,25 @@ 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 interface SchemaWithFallback - extends BaseSchema { +export type SchemaWithFallback< + TSchema extends BaseSchema = BaseSchema, + TFallback extends Fallback = Fallback, +> = TSchema & { /** * The fallback value. */ - fallback: TOutput | ((info?: FallbackInfo) => TOutput); -} + fallback: TFallback; +}; /** * Returns a fallback output value when validating the passed schema failed. @@ -26,8 +33,7 @@ export interface 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 0cc590e23..2ef288258 100644 --- a/library/src/methods/fallback/fallbackAsync.ts +++ b/library/src/methods/fallback/fallbackAsync.ts @@ -3,16 +3,25 @@ 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 interface SchemaWithFallbackAsync - extends BaseSchemaAsync { +export type SchemaWithFallbackAsync< + TSchema extends BaseSchemaAsync = BaseSchemaAsync, + TFallback extends FallbackAsync = FallbackAsync, +> = TSchema & { /** * The fallback value. */ - fallback: TOutput | ((info?: FallbackInfo) => TOutput | Promise); -} + fallback: TFallback; +}; /** * Returns a fallback output value when validating the passed schema failed. @@ -24,9 +33,7 @@ export interface 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/getFallback/getFallback.ts b/library/src/methods/getFallback/getFallback.ts index bfa07ddbc..d81fa894d 100644 --- a/library/src/methods/getFallback/getFallback.ts +++ b/library/src/methods/getFallback/getFallback.ts @@ -1,5 +1,20 @@ +import type { BaseSchema } from '../../types/index.ts'; +import type { Fallback } from '../fallback/index.ts'; import type { FallbackInfo } from '../fallback/types.ts'; -import type { FallbackValue, SchemaWithMaybeFallback } from './types.ts'; +import type { FallbackValue } from './types.ts'; + +/** + * Schema with maybe fallback type. + */ +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 3ca93ce4e..832a696da 100644 --- a/library/src/methods/getFallback/getFallbackAsync.ts +++ b/library/src/methods/getFallback/getFallbackAsync.ts @@ -1,9 +1,21 @@ +import type { BaseSchemaAsync } from '../../types/index.ts'; +import type { FallbackAsync } from '../fallback/index.ts'; import type { FallbackInfo } from '../fallback/types.ts'; -import type { - FallbackValue, - SchemaWithMaybeFallback, - SchemaWithMaybeFallbackAsync, -} from './types.ts'; +import type { SchemaWithMaybeFallback } from './getFallback.ts'; +import type { FallbackValue } from './types.ts'; + +/** + * Schema with maybe fallback async type. + */ +export type SchemaWithMaybeFallbackAsync< + TSchema extends BaseSchemaAsync = BaseSchemaAsync, + TFallback extends FallbackAsync = FallbackAsync, +> = TSchema & { + /** + * The optional fallback value. + */ + fallback?: TFallback; +}; /** * Returns the fallback value of the schema. diff --git a/library/src/methods/getFallback/types.ts b/library/src/methods/getFallback/types.ts index bd4844ad3..467d21293 100644 --- a/library/src/methods/getFallback/types.ts +++ b/library/src/methods/getFallback/types.ts @@ -1,27 +1,6 @@ -import type { BaseSchema, BaseSchemaAsync, Output } from '../../types/index.ts'; -import type { FallbackInfo } from '../fallback/types.ts'; - -/** - * Schema with maybe fallback type. - */ -export interface SchemaWithMaybeFallback - extends BaseSchema { - /** - * The optional fallback value. - */ - fallback?: TOutput | ((info?: FallbackInfo) => TOutput); -} - -/** - * Schema with maybe fallback async type. - */ -export interface SchemaWithMaybeFallbackAsync - extends BaseSchemaAsync { - /** - * The optional fallback value. - */ - fallback?: TOutput | ((info?: FallbackInfo) => TOutput | Promise); -} +import type { Output } from '../../types/index.ts'; +import type { SchemaWithMaybeFallback } from './getFallback.ts'; +import type { SchemaWithMaybeFallbackAsync } from './getFallbackAsync.ts'; /** * Fallback value inference type. From e08af7f07decfb6953db394207e88bfe0482647e Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Tue, 5 Mar 2024 19:18:22 -0500 Subject: [PATCH 17/21] Refactor getDefaults and getFallbacks method --- library/CHANGELOG.md | 6 ++-- .../src/methods/getDefaults/getDefaults.ts | 17 ++++++---- .../methods/getDefaults/getDefaultsAsync.ts | 32 +++++++++++-------- .../src/methods/getFallbacks/getFallbacks.ts | 26 +++++++++------ .../methods/getFallbacks/getFallbacksAsync.ts | 32 +++++++++++-------- 5 files changed, 69 insertions(+), 44 deletions(-) diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index c4804a1b2..94f017b3d 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -4,10 +4,12 @@ All notable changes to the library will be documented in this file. ## vX.X.X (Month DD, YYYY) -- Remove deprecated properties of `safeParse` and `safeParseAsync` method -- Fix `NestedPath` type of `flatten` for async schemas (issue #456) - Add `Default` and `DefaultAsync` type and refactor codebase - Add `Fallback` and `FallbackAsync` type and refactor codebase +- Refactor `getDefaults` and `getDefaultsAsync` method (pull request #259) +- Refactor `getFallbacks` and `getFallbacksAsync` method (pull request #259) +- Remove deprecated properties of `safeParse` and `safeParseAsync` method +- Fix `NestedPath` type of `flatten` for async schemas (issue #456) ## v0.29.0 (February 19, 2024) diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index ea2d5e79e..4020b9a27 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -24,15 +24,16 @@ import type { DefaultValues } from './types.ts'; * @returns The default values. */ export function getDefaults< - TSchema extends SchemaWithMaybeDefault & - (BaseSchema | ObjectSchema | TupleSchema), + TSchema extends SchemaWithMaybeDefault< + BaseSchema | ObjectSchema | TupleSchema + >, >(schema: TSchema): DefaultValues | undefined { - // If schema contains a default function, set its default value + // If schema has default, return its value if (schema.default !== undefined) { return getDefault(schema); } - // Otherwise, check if schema is of kind object or tuple - // If it is an object schema, set object with default value of each entry + + // If it is an object schema, return default of each entry if (hasType(schema, 'object')) { return Object.fromEntries( Object.entries(schema.entries).map(([key, value]) => [ @@ -41,8 +42,12 @@ export function getDefaults< ]) ) as DefaultValues; } - // If it is a tuple schema, set array with default value of each item + + // If it is a tuple schema, return default of each item if (hasType(schema, 'tuple')) { return schema.items.map(getDefaults) as DefaultValues; } + + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index e60759aa3..d80f30e58 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -30,21 +30,23 @@ import type { DefaultValues } from './types.ts'; */ export async function getDefaultsAsync< TSchema extends - | (SchemaWithMaybeDefault & - (BaseSchema | ObjectSchema | TupleSchema)) - | (SchemaWithMaybeDefaultAsync & - ( - | BaseSchemaAsync - | ObjectSchemaAsync - | TupleSchemaAsync - )), + | SchemaWithMaybeDefault< + | BaseSchema + | ObjectSchema + | TupleSchema + > + | SchemaWithMaybeDefaultAsync< + | BaseSchemaAsync + | ObjectSchemaAsync + | TupleSchemaAsync + >, >(schema: TSchema): Promise | undefined> { - // If schema contains a default function, set its default value + // If schema contains default, return its value if (schema.default !== undefined) { return getDefaultAsync(schema); } - // Otherwise, check if schema is of kind object or tuple - // If it is an object schema, set object with default value of each entry + + // If it is an object schema, return default of each entry if (hasType(schema, 'object')) { return Object.fromEntries( await Promise.all( @@ -53,12 +55,16 @@ export async function getDefaultsAsync< await getDefaultsAsync(value), ]) ) - ); + ) as DefaultValues; } - // If it is a tuple schema, set array with default value of each item + + // If it is a tuple schema, return default of each item if (hasType(schema, 'tuple')) { return Promise.all( schema.items.map(getDefaultsAsync) ) as DefaultValues; } + + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index a602981c3..98e3cbe5a 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -24,24 +24,30 @@ import type { FallbackValues } from './types.ts'; * @returns The fallback values. */ export function getFallbacks< - TSchema extends SchemaWithMaybeFallback & - (BaseSchema | ObjectSchema | TupleSchema), + TSchema extends SchemaWithMaybeFallback< + BaseSchema | ObjectSchema | TupleSchema + >, >(schema: TSchema): FallbackValues | undefined { - // If schema has a fallback, set its value + // If schema has fallback, return its value if (schema.fallback !== undefined) { return getFallback(schema); } - // Otherwise, check if schema is of kind object or tuple - // If it is an object schema, set object with fallback value of each entry + + // If it is an object schema, return fallback of each entry if (hasType(schema, 'object')) { - return Object.entries(schema.entries).reduce( - (hash, [key, value]) => - Object.assign(hash, { [key]: getFallbacks(value) }), - {} + 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 + + // If it is a tuple schema, return fallback of each item if (hasType(schema, 'tuple')) { return schema.items.map(getFallbacks) as FallbackValues; } + + // Otherwise, return undefined + return undefined; } diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 09097c754..4833b4ffc 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -30,21 +30,23 @@ import type { FallbackValues } from './types.ts'; */ export async function getFallbacksAsync< TSchema extends - | (SchemaWithMaybeFallback & - (BaseSchema | ObjectSchema | TupleSchema)) - | (SchemaWithMaybeFallbackAsync & - ( - | BaseSchemaAsync - | ObjectSchemaAsync - | TupleSchemaAsync - )), + | SchemaWithMaybeFallback< + | BaseSchema + | ObjectSchema + | TupleSchema + > + | SchemaWithMaybeFallbackAsync< + | BaseSchemaAsync + | ObjectSchemaAsync + | TupleSchemaAsync + >, >(schema: TSchema): Promise | undefined> { - // If schema has a fallback, set its value + // If schema has fallback, return its value if (schema.fallback !== undefined) { return getFallbackAsync(schema); } - // Otherwise, check if schema is of kind object or tuple - // If it is an object schema, set object with fallback value of each entry + + // If it is an object schema, return fallback of each entry if (hasType(schema, 'object')) { return Object.fromEntries( await Promise.all( @@ -53,12 +55,16 @@ export async function getFallbacksAsync< await getFallbacksAsync(value), ]) ) - ); + ) as FallbackValues; } - // If it is a tuple schema, set array with fallback value of each item + + // If it is a tuple schema, return fallback of each item if (hasType(schema, 'tuple')) { return Promise.all( schema.items.map(getFallbacksAsync) ) as FallbackValues; } + + // Otherwise, return undefined + return undefined; } From 03e95e36e655bd731680a877c0f1e23ca78da390 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Tue, 5 Mar 2024 19:31:02 -0500 Subject: [PATCH 18/21] Undo changes of NestedPath type in flatten --- library/src/error/flatten/flatten.ts | 107 +++++++++++++++------------ 1 file changed, 59 insertions(+), 48 deletions(-) diff --git a/library/src/error/flatten/flatten.ts b/library/src/error/flatten/flatten.ts index e614a6019..5dd8aa14f 100644 --- a/library/src/error/flatten/flatten.ts +++ b/library/src/error/flatten/flatten.ts @@ -70,56 +70,67 @@ type NestedPath = > ? DotPath : // Map - TSchema extends - | MapSchema - | MapSchemaAsync + TSchema extends MapSchema ? DotPath, TValue> - : // Object - TSchema extends - | ObjectSchema - | ObjectSchemaAsync - ? TRest extends NonNullable - ? ObjectPath | DotPath - : ObjectPath - : // Record - TSchema extends - | RecordSchema - | RecordSchemaAsync - ? DotPath, TValue> - : // Lazy - TSchema extends LazySchema< - infer TSchemaGetter extends () => BaseSchema - > - ? NestedPath> - : TSchema extends LazySchemaAsync< - infer TSchemaGetter extends () => - | BaseSchema - | BaseSchemaAsync - > - ? NestedPath> - : // Set - TSchema extends - | SetSchema - | SetSchemaAsync - ? DotPath - : // Tuple - TSchema extends - | TupleSchema - | TupleSchemaAsync - ? TRest extends NonNullable - ? TuplePath | DotPath - : TuplePath - : // Union - TSchema extends UnionSchema< - infer TUnionOptions extends UnionOptions + : TSchema extends MapSchemaAsync + ? DotPath, TValue> + : // Object + TSchema extends ObjectSchema + ? TRest extends BaseSchema + ? ObjectPath | DotPath + : ObjectPath + : TSchema extends ObjectSchemaAsync + ? TRest extends BaseSchema | BaseSchemaAsync + ? ObjectPath | DotPath + : ObjectPath + : // Record + TSchema extends RecordSchema + ? DotPath, TValue> + : TSchema extends RecordSchemaAsync + ? DotPath, TValue> + : // Lazy + TSchema extends LazySchema< + infer TSchemaGetter extends () => BaseSchema + > + ? NestedPath> + : TSchema extends LazySchemaAsync< + infer TSchemaGetter extends () => + | BaseSchema + | BaseSchemaAsync > - ? NestedPath - : TSchema extends UnionSchemaAsync< - infer TUnionOptions extends UnionOptionsAsync - > - ? NestedPath - : // Otherwise - never; + ? NestedPath> + : // Set + TSchema extends SetSchema + ? DotPath + : TSchema extends SetSchemaAsync + ? DotPath + : // Tuple + TSchema extends TupleSchema< + infer TItems, + infer TRest + > + ? TRest extends BaseSchema + ? TuplePath | DotPath + : TuplePath + : TSchema extends TupleSchemaAsync< + infer TItems, + infer TRest + > + ? TRest extends BaseSchema | BaseSchemaAsync + ? TuplePath | DotPath + : TuplePath + : // Union + TSchema extends UnionSchema< + infer TUnionOptions extends UnionOptions + > + ? NestedPath + : TSchema extends UnionSchemaAsync< + infer TUnionOptions extends + UnionOptionsAsync + > + ? NestedPath + : // Otherwise + never; /** * Flat errors type. From 7e7935222323a79194dc7ce585d6cdad47354de2 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Wed, 6 Mar 2024 00:19:45 -0500 Subject: [PATCH 19/21] Rename hasType to isOfType and refactor codebase --- library/CHANGELOG.md | 1 + .../src/methods/getDefaults/getDefaults.ts | 6 +-- .../methods/getDefaults/getDefaultsAsync.ts | 6 +-- .../src/methods/getFallbacks/getFallbacks.ts | 6 +-- .../methods/getFallbacks/getFallbacksAsync.ts | 6 +-- library/src/utils/hasType.ts | 54 ------------------- library/src/utils/index.ts | 2 +- library/src/utils/isOfType/index.ts | 1 + library/src/utils/isOfType/isOfType.test.ts | 26 +++++++++ library/src/utils/isOfType/isOfType.ts | 14 +++++ 10 files changed, 55 insertions(+), 67 deletions(-) delete mode 100644 library/src/utils/hasType.ts create mode 100644 library/src/utils/isOfType/index.ts create mode 100644 library/src/utils/isOfType/isOfType.test.ts create mode 100644 library/src/utils/isOfType/isOfType.ts diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index 94f017b3d..20f1e29e7 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to the library will be documented in this file. - 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) - Remove deprecated properties of `safeParse` and `safeParseAsync` method diff --git a/library/src/methods/getDefaults/getDefaults.ts b/library/src/methods/getDefaults/getDefaults.ts index 4020b9a27..e4adb95ce 100644 --- a/library/src/methods/getDefaults/getDefaults.ts +++ b/library/src/methods/getDefaults/getDefaults.ts @@ -5,7 +5,7 @@ import type { TupleSchema, } from '../../schemas/index.ts'; import type { BaseSchema } from '../../types/schema.ts'; -import { hasType } from '../../utils/index.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefault, type SchemaWithMaybeDefault, @@ -34,7 +34,7 @@ export function getDefaults< } // If it is an object schema, return default of each entry - if (hasType(schema, 'object')) { + if (isOfType('object', schema)) { return Object.fromEntries( Object.entries(schema.entries).map(([key, value]) => [ key, @@ -44,7 +44,7 @@ export function getDefaults< } // If it is a tuple schema, return default of each item - if (hasType(schema, 'tuple')) { + if (isOfType('tuple', schema)) { return schema.items.map(getDefaults) as DefaultValues; } diff --git a/library/src/methods/getDefaults/getDefaultsAsync.ts b/library/src/methods/getDefaults/getDefaultsAsync.ts index d80f30e58..057ae6eb3 100644 --- a/library/src/methods/getDefaults/getDefaultsAsync.ts +++ b/library/src/methods/getDefaults/getDefaultsAsync.ts @@ -9,7 +9,7 @@ import type { TupleSchemaAsync, } from '../../schemas/index.ts'; import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; -import { hasType } from '../../utils/index.ts'; +import { isOfType } from '../../utils/index.ts'; import { getDefaultAsync, type SchemaWithMaybeDefault, @@ -47,7 +47,7 @@ export async function getDefaultsAsync< } // If it is an object schema, return default of each entry - if (hasType(schema, 'object')) { + if (isOfType('object', schema)) { return Object.fromEntries( await Promise.all( Object.entries(schema.entries).map(async ([key, value]) => [ @@ -59,7 +59,7 @@ export async function getDefaultsAsync< } // If it is a tuple schema, return default of each item - if (hasType(schema, 'tuple')) { + if (isOfType('tuple', schema)) { return Promise.all( schema.items.map(getDefaultsAsync) ) as DefaultValues; diff --git a/library/src/methods/getFallbacks/getFallbacks.ts b/library/src/methods/getFallbacks/getFallbacks.ts index 98e3cbe5a..e36133ba0 100644 --- a/library/src/methods/getFallbacks/getFallbacks.ts +++ b/library/src/methods/getFallbacks/getFallbacks.ts @@ -5,7 +5,7 @@ import type { TupleSchema, } from '../../schemas/index.ts'; import type { BaseSchema } from '../../types/schema.ts'; -import { hasType } from '../../utils/index.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallback, type SchemaWithMaybeFallback, @@ -34,7 +34,7 @@ export function getFallbacks< } // If it is an object schema, return fallback of each entry - if (hasType(schema, 'object')) { + if (isOfType('object', schema)) { return Object.fromEntries( Object.entries(schema.entries).map(([key, value]) => [ key, @@ -44,7 +44,7 @@ export function getFallbacks< } // If it is a tuple schema, return fallback of each item - if (hasType(schema, 'tuple')) { + if (isOfType('tuple', schema)) { return schema.items.map(getFallbacks) as FallbackValues; } diff --git a/library/src/methods/getFallbacks/getFallbacksAsync.ts b/library/src/methods/getFallbacks/getFallbacksAsync.ts index 4833b4ffc..de70ee79b 100644 --- a/library/src/methods/getFallbacks/getFallbacksAsync.ts +++ b/library/src/methods/getFallbacks/getFallbacksAsync.ts @@ -9,7 +9,7 @@ import type { TupleSchemaAsync, } from '../../schemas/index.ts'; import type { BaseSchema, BaseSchemaAsync } from '../../types/schema.ts'; -import { hasType } from '../../utils/index.ts'; +import { isOfType } from '../../utils/index.ts'; import { getFallbackAsync, type SchemaWithMaybeFallback, @@ -47,7 +47,7 @@ export async function getFallbacksAsync< } // If it is an object schema, return fallback of each entry - if (hasType(schema, 'object')) { + if (isOfType('object', schema)) { return Object.fromEntries( await Promise.all( Object.entries(schema.entries).map(async ([key, value]) => [ @@ -59,7 +59,7 @@ export async function getFallbacksAsync< } // If it is a tuple schema, return fallback of each item - if (hasType(schema, 'tuple')) { + if (isOfType('tuple', schema)) { return Promise.all( schema.items.map(getFallbacksAsync) ) as FallbackValues; diff --git a/library/src/utils/hasType.ts b/library/src/utils/hasType.ts deleted file mode 100644 index d0585e83e..000000000 --- a/library/src/utils/hasType.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * A generic [type predicate guard](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates) used to filter Schemas, Transformations, and Validations in control flow at runtime, and to narrow unions of such types at authoring time. - * - * @param val The Schema, Transformation, or Validation to compare against - * @param type The required type value we expect `val` to have - * - * @returns A boolean predicated on whether `val` has the given `type` - * - * When the type of `val` is a union, `hasType` will discriminate based on the proided `type` string. This is better understood with an example: - * - * ```ts - * import * as v from 'valibot'; - * - * type Schema = - * | v.BaseSchema - * | v.ObjectSchema - * | v.ArraySchema; - * - * function schemaToJson(schema: S) { - * if (hasType(schema, "string")) { - * // narrows schema to StringSchema - * return { type: 'string' }; - * } - * if (hasType(schema, 'object')) { - * // narrows schema to ObjectSchema - * return { - * type: 'object', - * entries: Object.fromEntries( - * Object.entries(schema.entries).map(([key, value]) => [ - * key, - * schemaToJson(value), - * ]) - * ), - * }; - * } - * if (hasType(schema, 'array')) { - * // narrows schema to ArraySchema - * return { - * type: 'array', - * item: schemaToJson(schema.item), - * }; - * } - * // schema extends BaseSchema, but it is not a StringSchema, ObjectSchema, or ArraySchema - * throw new Error('Not implemented'); - * } - * ``` - */ -export const hasType = < - U extends { type: string }, - const T extends string = string, ->( - val: U, - type: T -): val is Extract => val?.type === type; diff --git a/library/src/utils/index.ts b/library/src/utils/index.ts index 18108da80..3c7bdd49f 100644 --- a/library/src/utils/index.ts +++ b/library/src/utils/index.ts @@ -3,7 +3,7 @@ export * from './actionOutput/index.ts'; export * from './defaultArgs/index.ts'; export * from './i18n/index.ts'; export * from './isLuhnAlgo/index.ts'; -export * from './hasType.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; +} From 2f77fc2f929b5be74a5af41f7b40c6e363df3d03 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Wed, 6 Mar 2024 13:58:23 -0500 Subject: [PATCH 20/21] Add Default and Fallback to API reference of website --- .../api/(methods)/fallback/properties.ts | 42 +------ .../api/(schemas)/nullable/properties.ts | 37 +----- .../api/(schemas)/nullish/properties.ts | 37 +----- .../api/(schemas)/optional/properties.ts | 37 +----- .../src/routes/api/(types)/Default/index.mdx | 21 ++++ .../routes/api/(types)/Default/properties.ts | 53 +++++++++ .../routes/api/(types)/DefaultAsync/index.mdx | 21 ++++ .../api/(types)/DefaultAsync/properties.ts | 76 +++++++++++++ .../src/routes/api/(types)/Fallback/index.mdx | 21 ++++ .../routes/api/(types)/Fallback/properties.ts | 56 +++++++++ .../api/(types)/FallbackAsync/index.mdx | 21 ++++ .../api/(types)/FallbackAsync/properties.ts | 78 +++++++++++++ .../api/(types)/NullableSchema/properties.ts | 37 +----- .../(types)/NullableSchemaAsync/properties.ts | 55 +-------- .../api/(types)/NullishSchema/properties.ts | 37 +----- .../(types)/NullishSchemaAsync/properties.ts | 55 +-------- .../api/(types)/OptionalSchema/properties.ts | 37 +----- .../(types)/OptionalSchemaAsync/properties.ts | 55 +-------- .../(types)/SchemaWithFallback/properties.ts | 48 ++------ .../(types)/SchemaWithMaybeFallback/index.mdx | 4 +- .../SchemaWithMaybeFallback/properties.ts | 84 ++++++-------- .../SchemaWithMaybeFallbackAsync/index.mdx | 4 +- .../properties.ts | 106 ++++++------------ website/src/routes/api/menu.md | 4 + 24 files changed, 483 insertions(+), 543 deletions(-) create mode 100644 website/src/routes/api/(types)/Default/index.mdx create mode 100644 website/src/routes/api/(types)/Default/properties.ts create mode 100644 website/src/routes/api/(types)/DefaultAsync/index.mdx create mode 100644 website/src/routes/api/(types)/DefaultAsync/properties.ts create mode 100644 website/src/routes/api/(types)/Fallback/index.mdx create mode 100644 website/src/routes/api/(types)/Fallback/properties.ts create mode 100644 website/src/routes/api/(types)/FallbackAsync/index.mdx create mode 100644 website/src/routes/api/(types)/FallbackAsync/properties.ts 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/) From de1d85788b9b781719a22d03b0dfcfede7f01e68 Mon Sep 17 00:00:00 2001 From: Fabian Hiller Date: Wed, 6 Mar 2024 14:35:16 -0500 Subject: [PATCH 21/21] Update changelog of library --- library/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/CHANGELOG.md b/library/CHANGELOG.md index 20f1e29e7..4ef5bbda8 100644 --- a/library/CHANGELOG.md +++ b/library/CHANGELOG.md @@ -9,8 +9,10 @@ All notable changes to the library will be documented in this file. - 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)