Elysia Type â
Elysia.t
is based on TypeBox with pre-configuration for usage on the server while providing additional types commonly found on server-side validation.
You can find all of the source code of Elysia type in elysia/type-system
.
The following are types provided by Elysia:
Numeric â
Numeric accepts a numeric string or number and then transforms the value into a number.
t.Numeric()
t.Numeric()
This is useful when an incoming value is a numeric string for example path parameter or query string.
Numeric accepts the same attribute as Numeric Instance
File â
A singular file. Often useful for file upload validation.
t.File()
t.File()
File extends attribute of base schema, with additional property as follows:
type â
A format of the file like image, video, audio.
If an array is provided, will attempt to validate if any of the format is valid.
type?: MaybeArray<string>
type?: MaybeArray<string>
minSize â
Minimum size of the file.
Accept number in byte or suffix of file unit:
minSize?: number | `${number}${'k' | 'm'}`
minSize?: number | `${number}${'k' | 'm'}`
maxSize â
Maximum size of the file.
Accept number in byte or suffix of file unit:
maxSize?: number | `${number}${'k' | 'm'}`
maxSize?: number | `${number}${'k' | 'm'}`
File Unit Suffix: â
The following are the specifications of the file unit: m: MegaByte (1048576 byte) k: KiloByte (1024 byte)
Files â
Extends from File, but adds support for an array of files in a single field.
t.Files()
t.Files()
File extends attributes of base schema, array, and File.
Cookie â
Object-like representation of a Cookie Jar extended from Object type.
t.Cookie({
name: t.String()
})
t.Cookie({
name: t.String()
})
Cookie extends attributes of Object and Cookie with additional properties follows:
secrets â
The secret key for signing cookies.
Accepts a string or an array of string
secrets?: string | string[]
secrets?: string | string[]
If an array is provided, Key Rotation will be used, the newly signed value will use the first secret as the key.
Nullable â
Allow the value to be null but not undefined.
t.Nullable(t.String())
t.Nullable(t.String())
MaybeEmpty â
Allow the value to be null and undefined.
t.MaybeEmpty(t.String())
t.MaybeEmpty(t.String())
For additional information, you can find the full source code of the type system in elysia/type-system
.