@xpadev-net/niconicomments
Version:
NiconiComments is a comment drawing library that is somewhat compatible with the official Nico Nico Douga player.
1,656 lines (1,619 loc) • 125 kB
TypeScript
type ButtonList = {
left: ButtonPartLeft;
middle: ButtonPartMiddle[];
right: ButtonPartRight;
};
type ButtonPartLeft = {
type: "left";
left: number;
top: number;
width: number;
height: number;
};
type ButtonPartMiddle = {
type: "middle";
left: number;
top: number;
width: number;
height: number;
};
type ButtonPartRight = {
type: "right";
right: number;
top: number;
height: number;
};
type Canvas = HTMLCanvasElement;
type Context2D = CanvasRenderingContext2D;
type DefaultCommand = {
color?: string;
size?: CommentSize;
font?: CommentFont;
loc?: CommentLoc;
};
declare class BaseComment implements IComment {
protected readonly renderer: IRenderer;
protected cacheKey: string;
comment: FormattedCommentWithSize;
pos: {
x: number;
y: number;
};
posY: number;
readonly pluginName: string;
image?: IRenderer | null;
buttonImage?: IRenderer | null;
index: number;
constructor(comment: FormattedComment, renderer: IRenderer, index: number);
get invisible(): boolean;
get loc(): "ue" | "naka" | "shita";
get long(): number;
get vpos(): number;
get width(): number;
get height(): number;
get flash(): boolean;
get layer(): number;
get owner(): boolean;
get mail(): string[];
get content(): string;
set content(_: string);
protected getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
protected parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
protected parseContent(comment: string): ParseContentResult;
protected measureText(comment: MeasureTextInput): MeasureTextResult;
protected convertComment(comment: FormattedComment): FormattedCommentWithSize;
draw(vpos: number, showCollision: boolean, cursor?: Position): void;
protected _draw(posX: number, posY: number, cursor?: Position): void;
protected _drawRectColor(posX: number, posY: number): void;
protected _drawBackgroundColor(posX: number, posY: number): void;
protected _drawDebugInfo(posX: number, posY: number): void;
protected _drawCollision(posX: number, posY: number, showCollision: boolean): void;
protected getTextImage(): IRenderer | null;
protected _generateTextImage(): IRenderer;
protected _cacheImage(image: IRenderer): void;
protected getButtonImage(posX: number, posY: number, cursor?: Position): IRenderer | undefined;
isHovered(cursor?: Position, posX?: number, posY?: number): boolean;
protected getCacheKey(): string;
}
declare class FlashComment extends BaseComment {
private _globalScale;
readonly pluginName: string;
buttonImage: IRenderer;
constructor(comment: FormattedComment, renderer: IRenderer, index: number);
get content(): string;
set content(input: string);
convertComment(comment: FormattedComment): FormattedCommentWithSize;
getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
parseContent(input: string, button?: ButtonParams): {
content: ({
type: "spacer";
char: string;
charWidth: number;
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
count: number;
} | {
type: "text";
content: string;
slicedContent: string[];
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
width?: number[] | undefined;
})[];
lineCount: number;
lineOffset: number;
};
measureText(comment: MeasureTextInput): MeasureTextResult;
private _isDoubleResize;
private _measureContent;
_drawCollision(posX: number, posY: number, showCollision: boolean): void;
_generateTextImage(): IRenderer;
getButtonImage(posX: number, posY: number, cursor?: Position): IRenderer | undefined;
isHovered(_cursor?: Position, _posX?: number, _posY?: number): boolean;
protected _setupCanvas(renderer: IRenderer): {
renderer: IRenderer;
};
}
declare class HTML5Comment extends BaseComment {
readonly pluginName: string;
constructor(comment: FormattedComment, context: IRenderer, index: number);
get content(): string;
set content(input: string);
convertComment(comment: FormattedComment): FormattedCommentWithSize;
getCommentSize(parsedData: FormattedCommentWithFont): FormattedCommentWithSize;
parseCommandAndNicoscript(comment: FormattedComment): FormattedCommentWithFont;
parseContent(input: string, font?: HTML5Fonts): {
content: {
type: "text";
content: string;
slicedContent: string[];
isButton?: boolean | undefined;
font?: "defont" | "gulim" | "simsun" | undefined;
width?: number[] | undefined;
}[];
lineCount: number;
lineOffset: number;
};
measureText(comment: MeasureTextInput): MeasureTextResult;
private _measureComment;
private _processResizeX;
_drawCollision(posX: number, posY: number, showCollision: boolean): void;
_generateTextImage(): IRenderer;
getButtonImage(): undefined;
isHovered(): boolean;
}
type index_d$4_BaseComment = BaseComment;
declare const index_d$4_BaseComment: typeof BaseComment;
type index_d$4_FlashComment = FlashComment;
declare const index_d$4_FlashComment: typeof FlashComment;
type index_d$4_HTML5Comment = HTML5Comment;
declare const index_d$4_HTML5Comment: typeof HTML5Comment;
declare namespace index_d$4 {
export {
index_d$4_BaseComment as BaseComment,
index_d$4_FlashComment as FlashComment,
index_d$4_HTML5Comment as HTML5Comment,
};
}
type ConfigItem<T> = T | MultiConfigItem<T>;
type MultiConfigItem<T> = {
html5: T;
flash: T;
};
type ConfigSizeItem<T> = {
big: T;
medium: T;
small: T;
};
type ConfigResizedItem<T> = {
default: T;
resized: T;
};
type ConfigFlashFontItem<T> = {
gulim: T;
simsun: T;
defont: T;
};
type ConfigHTML5FontItem<T> = {
gothic: T;
mincho: T;
defont: T;
};
type CommentStageSize = {
width: number;
fullWidth: number;
height: number;
};
type FlashCharList = {
[key in "simsunStrong" | "simsunWeak" | "gulim" | "gothic"]: string;
};
type FlashMode = "xp" | "vista";
type FlashScriptChar = {
[key in "super" | "sub"]: string;
};
type FontList = {
[key in "gulim" | "simsun"]: string;
};
type LineCounts = {
[key in "default" | "resized" | "doubleResized"]: ConfigSizeItem<number>;
};
type BaseConfig = {
cacheAge: number;
canvasHeight: number;
canvasWidth: number;
collisionRange: {
[key in "left" | "right"]: number;
};
collisionPadding: number;
colors: {
[key: string]: string;
};
commentDrawPadding: number;
commentDrawRange: number;
commentScale: ConfigItem<number>;
commentStageSize: ConfigItem<CommentStageSize>;
flashCommentYOffset: ConfigSizeItem<ConfigResizedItem<number>>;
flashCommentYPaddingTop: ConfigResizedItem<number>;
contextFillLiveOpacity: number;
contextLineWidth: ConfigItem<number>;
contextStrokeColor: string;
contextStrokeInversionColor: string;
contextStrokeOpacity: number;
flashChar: FlashCharList;
flashMode: FlashMode;
flashScriptChar: FlashScriptChar;
flashThreshold: number;
fonts: {
flash: FontList;
html5: PlatformFont;
};
fontSize: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
fpsInterval: number;
html5HiResCommentCorrection: number;
html5LineCounts: ConfigItem<LineCounts>;
lineHeight: ConfigItem<ConfigSizeItem<ConfigResizedItem<number>>>;
html5MinFontSize: number;
sameCAGap: number;
sameCAMinScore: number;
sameCARange: number;
sameCATimestampRange: number;
flashLetterSpacing: number;
flashScriptCharOffset: number;
plugins: IPluginConstructor[];
commentPlugins: {
class: typeof BaseComment;
condition: (comment: FormattedComment) => boolean;
}[];
commentLimit: number | undefined;
hideCommentOrder: "asc" | "desc";
lineBreakCount: {
[key in CommentSize]: number;
};
nakaCommentSpeedOffset: number;
atButtonPadding: number;
atButtonRadius: number;
flashDoubleResizeHeights: Partial<ConfigSizeItem<{
[key: number]: number;
}>>;
flashLineBreakScale: ConfigSizeItem<number>;
compatSpacer: {
flash: {
[key: string]: Partial<ConfigFlashFontItem<number>>;
};
html5: {
[key: string]: Partial<ConfigHTML5FontItem<number>>;
};
};
};
type Config$1 = Partial<BaseConfig>;
type Position = {
x: number;
y: number;
};
interface CommentEventBase {
type: CommentEventName;
timeStamp: number;
vpos: number;
}
interface SeekDisableEvent extends CommentEventBase {
type: "seekDisable";
}
type SeekDisableEventHandler = (event: SeekDisableEvent) => unknown;
interface SeekEnableEvent extends CommentEventBase {
type: "seekEnable";
}
type SeekEnableEventHandler = (event: SeekEnableEvent) => unknown;
interface CommentDisableEvent extends CommentEventBase {
type: "commentDisable";
}
type CommentDisableEventHandler = (event: CommentDisableEvent) => unknown;
interface CommentEnableEvent extends CommentEventBase {
type: "commentEnable";
}
type CommentEnableEventHandler = (event: CommentEnableEvent) => unknown;
interface JumpEvent extends CommentEventBase {
type: "jump";
to: string;
message?: string;
}
type JumpEventHandler = (event: JumpEvent) => unknown;
type CommentEventName = "seekDisable" | "seekEnable" | "commentDisable" | "commentEnable" | "jump";
type CommentEventHandler = SeekDisableEventHandler | SeekEnableEventHandler | CommentDisableEventHandler | CommentEnableEventHandler | JumpEventHandler;
interface CommentEventHandlerMap {
seekDisable: SeekDisableEventHandler;
seekEnable: SeekEnableEventHandler;
commentDisable: CommentDisableEventHandler;
commentEnable: CommentEnableEventHandler;
jump: JumpEventHandler;
}
interface CommentEventMap {
seekDisable: SeekDisableEvent;
seekEnable: SeekEnableEvent;
commentDisable: CommentDisableEvent;
commentEnable: CommentEnableEvent;
jump: JumpEvent;
}
/**
* Fallback type.
*/
type Fallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybeReadonly<InferOutput<TSchema>>);
/**
* Schema with fallback type.
*/
type SchemaWithFallback<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TFallback extends Fallback<TSchema>> = TSchema & {
/**
* The fallback value.
*/
readonly fallback: TFallback;
};
/**
* Fallback async type.
*/
type FallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>> = MaybeReadonly<InferOutput<TSchema>> | ((dataset?: OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>, config?: Config<InferIssue<TSchema>>) => MaybePromise<MaybeReadonly<InferOutput<TSchema>>>);
/**
* Schema with fallback async type.
*/
type SchemaWithFallbackAsync<TSchema extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TFallback extends FallbackAsync<TSchema>> = Omit<TSchema, 'async' | '~standard' | '~run'> & {
/**
* The fallback value.
*/
readonly fallback: TFallback;
/**
* Whether it's async.
*/
readonly async: true;
/**
* The Standard Schema properties.
*
* @internal
*/
readonly '~standard': StandardProps<InferInput<TSchema>, InferOutput<TSchema>>;
/**
* Parses unknown input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<TSchema>, InferIssue<TSchema>>>;
};
/**
* Schema with pipe type.
*/
type SchemaWithPipe<TPipe extends readonly [
BaseSchema<unknown, unknown, BaseIssue<unknown>>,
...PipeItem<any, unknown, BaseIssue<unknown>>[]
]> = Omit<FirstTupleItem<TPipe>, 'pipe' | '~standard' | '~run' | '~types'> & {
/**
* The pipe items.
*/
readonly pipe: TPipe;
/**
* The Standard Schema properties.
*
* @internal
*/
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
/**
* Parses unknown input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: InferInput<FirstTupleItem<TPipe>>;
readonly output: InferOutput<LastTupleItem<TPipe>>;
readonly issue: InferIssue<TPipe[number]>;
} | undefined;
};
/**
* Schema with pipe async type.
*/
type SchemaWithPipeAsync<TPipe extends readonly [
(BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>),
...(PipeItem<any, unknown, BaseIssue<unknown>> | PipeItemAsync<any, unknown, BaseIssue<unknown>>)[]
]> = Omit<FirstTupleItem<TPipe>, 'async' | 'pipe' | '~standard' | '~run' | '~types'> & {
/**
* The pipe items.
*/
readonly pipe: TPipe;
/**
* Whether it's async.
*/
readonly async: true;
/**
* The Standard Schema properties.
*
* @internal
*/
readonly '~standard': StandardProps<InferInput<FirstTupleItem<TPipe>>, InferOutput<LastTupleItem<TPipe>>>;
/**
* Parses unknown input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<InferOutput<LastTupleItem<TPipe>>, InferIssue<TPipe[number]>>>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: InferInput<FirstTupleItem<TPipe>>;
readonly output: InferOutput<LastTupleItem<TPipe>>;
readonly issue: InferIssue<TPipe[number]>;
} | undefined;
};
/**
* Base metadata interface.
*/
interface BaseMetadata<TInput> {
/**
* The object kind.
*/
readonly kind: 'metadata';
/**
* The metadata type.
*/
readonly type: string;
/**
* The metadata reference.
*/
readonly reference: (...args: any[]) => BaseMetadata<any>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: TInput;
readonly output: TInput;
readonly issue: never;
} | undefined;
}
/**
* Unknown dataset interface.
*/
interface UnknownDataset {
/**
* Whether is's typed.
*/
typed?: false;
/**
* The dataset value.
*/
value: unknown;
/**
* The dataset issues.
*/
issues?: undefined;
}
/**
* Success dataset interface.
*/
interface SuccessDataset<TValue> {
/**
* Whether is's typed.
*/
typed: true;
/**
* The dataset value.
*/
value: TValue;
/**
* The dataset issues.
*/
issues?: undefined;
}
/**
* Partial dataset interface.
*/
interface PartialDataset<TValue, TIssue extends BaseIssue<unknown>> {
/**
* Whether is's typed.
*/
typed: true;
/**
* The dataset value.
*/
value: TValue;
/**
* The dataset issues.
*/
issues: [TIssue, ...TIssue[]];
}
/**
* Failure dataset interface.
*/
interface FailureDataset<TIssue extends BaseIssue<unknown>> {
/**
* Whether is's typed.
*/
typed: false;
/**
* The dataset value.
*/
value: unknown;
/**
* The dataset issues.
*/
issues: [TIssue, ...TIssue[]];
}
/**
* Output dataset type.
*/
type OutputDataset<TValue, TIssue extends BaseIssue<unknown>> = SuccessDataset<TValue> | PartialDataset<TValue, TIssue> | FailureDataset<TIssue>;
/**
* The Standard Schema properties interface.
*/
interface StandardProps<TInput, TOutput> {
/**
* The version number of the standard.
*/
readonly version: 1;
/**
* The vendor name of the schema library.
*/
readonly vendor: 'valibot';
/**
* Validates unknown input values.
*/
readonly validate: (value: unknown) => StandardResult<TOutput> | Promise<StandardResult<TOutput>>;
/**
* Inferred types associated with the schema.
*/
readonly types?: StandardTypes<TInput, TOutput> | undefined;
}
/**
* The result interface of the validate function.
*/
type StandardResult<TOutput> = StandardSuccessResult<TOutput> | StandardFailureResult;
/**
* The result interface if validation succeeds.
*/
interface StandardSuccessResult<TOutput> {
/**
* The typed output value.
*/
readonly value: TOutput;
/**
* The non-existent issues.
*/
readonly issues?: undefined;
}
/**
* The result interface if validation fails.
*/
interface StandardFailureResult {
/**
* The issues of failed validation.
*/
readonly issues: readonly StandardIssue[];
}
/**
* The issue interface of the failure output.
*/
interface StandardIssue {
/**
* The error message of the issue.
*/
readonly message: string;
/**
* The path of the issue, if any.
*/
readonly path?: readonly (PropertyKey | StandardPathItem)[] | undefined;
}
/**
* The path item interface of the issue.
*/
interface StandardPathItem {
/**
* The key of the path item.
*/
readonly key: PropertyKey;
}
/**
* The Standard Schema types interface.
*/
interface StandardTypes<TInput, TOutput> {
/**
* The input type of the schema.
*/
readonly input: TInput;
/**
* The output type of the schema.
*/
readonly output: TOutput;
}
/**
* Base schema interface.
*/
interface BaseSchema<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
/**
* The object kind.
*/
readonly kind: 'schema';
/**
* The schema type.
*/
readonly type: string;
/**
* The schema reference.
*/
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>>;
/**
* The expected property.
*/
readonly expects: string;
/**
* Whether it's async.
*/
readonly async: false;
/**
* The Standard Schema properties.
*
* @internal
*/
readonly '~standard': StandardProps<TInput, TOutput>;
/**
* Parses unknown input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, TIssue>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: TInput;
readonly output: TOutput;
readonly issue: TIssue;
} | undefined;
}
/**
* Base schema async interface.
*/
interface BaseSchemaAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseSchema<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
/**
* The schema reference.
*/
readonly reference: (...args: any[]) => BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>;
/**
* Whether it's async.
*/
readonly async: true;
/**
* Parses unknown input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: UnknownDataset, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, TIssue>>;
}
/**
* Base transformation interface.
*/
interface BaseTransformation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
/**
* The object kind.
*/
readonly kind: 'transformation';
/**
* The transformation type.
*/
readonly type: string;
/**
* The transformation reference.
*/
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>>;
/**
* Whether it's async.
*/
readonly async: false;
/**
* Transforms known input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: TInput;
readonly output: TOutput;
readonly issue: TIssue;
} | undefined;
}
/**
* Base transformation async interface.
*/
interface BaseTransformationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseTransformation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
/**
* The transformation reference.
*/
readonly reference: (...args: any[]) => BaseTransformation<any, any, BaseIssue<unknown>> | BaseTransformationAsync<any, any, BaseIssue<unknown>>;
/**
* Whether it's async.
*/
readonly async: true;
/**
* Transforms known input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: SuccessDataset<TInput>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
}
/**
* Base validation interface.
*/
interface BaseValidation<TInput, TOutput, TIssue extends BaseIssue<unknown>> {
/**
* The object kind.
*/
readonly kind: 'validation';
/**
* The validation type.
*/
readonly type: string;
/**
* The validation reference.
*/
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>>;
/**
* The expected property.
*/
readonly expects: string | null;
/**
* Whether it's async.
*/
readonly async: false;
/**
* Validates known input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => OutputDataset<TOutput, BaseIssue<unknown> | TIssue>;
/**
* The input, output and issue type.
*
* @internal
*/
readonly '~types'?: {
readonly input: TInput;
readonly output: TOutput;
readonly issue: TIssue;
} | undefined;
}
/**
* Base validation async interface.
*/
interface BaseValidationAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> extends Omit<BaseValidation<TInput, TOutput, TIssue>, 'reference' | 'async' | '~run'> {
/**
* The validation reference.
*/
readonly reference: (...args: any[]) => BaseValidation<any, any, BaseIssue<unknown>> | BaseValidationAsync<any, any, BaseIssue<unknown>>;
/**
* Whether it's async.
*/
readonly async: true;
/**
* Validates known input values.
*
* @param dataset The input dataset.
* @param config The configuration.
*
* @returns The output dataset.
*
* @internal
*/
readonly '~run': (dataset: OutputDataset<TInput, BaseIssue<unknown>>, config: Config<BaseIssue<unknown>>) => Promise<OutputDataset<TOutput, BaseIssue<unknown> | TIssue>>;
}
/**
* Infer input type.
*/
type InferInput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['input'];
/**
* Infer output type.
*/
type InferOutput<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['output'];
/**
* Infer issue type.
*/
type InferIssue<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | BaseValidation<any, unknown, BaseIssue<unknown>> | BaseValidationAsync<any, unknown, BaseIssue<unknown>> | BaseTransformation<any, unknown, BaseIssue<unknown>> | BaseTransformationAsync<any, unknown, BaseIssue<unknown>> | BaseMetadata<any>> = NonNullable<TItem['~types']>['issue'];
/**
* Constructs a type that is maybe readonly.
*/
type MaybeReadonly<TValue> = TValue | Readonly<TValue>;
/**
* Constructs a type that is maybe a promise.
*/
type MaybePromise<TValue> = TValue | Promise<TValue>;
/**
* Prettifies a type for better readability.
*
* Hint: This type has no effect and is only used so that TypeScript displays
* the final type in the preview instead of the utility types used.
*/
type Prettify<TObject> = {
[TKey in keyof TObject]: TObject[TKey];
} & {};
/**
* Marks specific keys as optional.
*/
type MarkOptional<TObject, TKeys extends keyof TObject> = {
[TKey in keyof TObject]?: unknown;
} & Omit<TObject, TKeys> & Partial<Pick<TObject, TKeys>>;
/**
* Extracts first tuple item.
*/
type FirstTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[0];
/**
* Extracts last tuple item.
*/
type LastTupleItem<TTuple extends readonly [unknown, ...unknown[]]> = TTuple[TTuple extends readonly [unknown, ...infer TRest] ? TRest['length'] : never];
/**
* Error message type.
*/
type ErrorMessage<TIssue extends BaseIssue<unknown>> = ((issue: TIssue) => string) | string;
/**
* Default type.
*/
type Default<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybeReadonly<InferInput<TWrapped> | TInput>) | undefined;
/**
* Default async type.
*/
type DefaultAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TInput extends null | undefined> = MaybeReadonly<InferInput<TWrapped> | TInput> | ((dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<MaybeReadonly<InferInput<TWrapped> | TInput>>) | undefined;
/**
* Default value type.
*/
type DefaultValue<TDefault extends Default<BaseSchema<unknown, unknown, BaseIssue<unknown>>, null | undefined> | DefaultAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, null | undefined>> = TDefault extends DefaultAsync<infer TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, infer TInput> ? TDefault extends (dataset?: UnknownDataset, config?: Config<InferIssue<TWrapped>>) => MaybePromise<InferInput<TWrapped> | TInput> ? Awaited<ReturnType<TDefault>> : TDefault : never;
/**
* Optional entry schema type.
*/
type OptionalEntrySchema = ExactOptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchema<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown>;
/**
* Optional entry schema async type.
*/
type OptionalEntrySchemaAsync = ExactOptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | NullishSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalSchemaAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown>;
/**
* Object entries interface.
*/
interface ObjectEntries {
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema;
}
/**
* Object entries async interface.
*/
interface ObjectEntriesAsync {
[key: string]: BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>> | SchemaWithFallback<BaseSchema<unknown, unknown, BaseIssue<unknown>>, unknown> | SchemaWithFallbackAsync<BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, unknown> | OptionalEntrySchema | OptionalEntrySchemaAsync;
}
/**
* Infer entries input type.
*/
type InferEntriesInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
-readonly [TKey in keyof TEntries]: InferInput<TEntries[TKey]>;
};
/**
* Infer entries output type.
*/
type InferEntriesOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
-readonly [TKey in keyof TEntries]: InferOutput<TEntries[TKey]>;
};
/**
* Optional input keys type.
*/
type OptionalInputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? TKey : never;
}[keyof TEntries];
/**
* Optional output keys type.
*/
type OptionalOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TEntries]: TEntries[TKey] extends OptionalEntrySchema | OptionalEntrySchemaAsync ? undefined extends TEntries[TKey]['default'] ? TKey : never : never;
}[keyof TEntries];
/**
* Input with question marks type.
*/
type InputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesInput<TEntries>> = MarkOptional<TObject, OptionalInputKeys<TEntries>>;
/**
* Output with question marks type.
*/
type OutputWithQuestionMarks<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends InferEntriesOutput<TEntries>> = MarkOptional<TObject, OptionalOutputKeys<TEntries>>;
/**
* Readonly output keys type.
*/
type ReadonlyOutputKeys<TEntries extends ObjectEntries | ObjectEntriesAsync> = {
[TKey in keyof TEntries]: TEntries[TKey] extends SchemaWithPipe<infer TPipe> | SchemaWithPipeAsync<infer TPipe> ? ReadonlyAction<any> extends TPipe[number] ? TKey : never : never;
}[keyof TEntries];
/**
* Output with readonly type.
*/
type OutputWithReadonly<TEntries extends ObjectEntries | ObjectEntriesAsync, TObject extends OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>> = Readonly<TObject> & Pick<TObject, Exclude<keyof TObject, ReadonlyOutputKeys<TEntries>>>;
/**
* Infer object input type.
*/
type InferObjectInput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<InputWithQuestionMarks<TEntries, InferEntriesInput<TEntries>>>;
/**
* Infer object output type.
*/
type InferObjectOutput<TEntries extends ObjectEntries | ObjectEntriesAsync> = Prettify<OutputWithReadonly<TEntries, OutputWithQuestionMarks<TEntries, InferEntriesOutput<TEntries>>>>;
/**
* Infer object issue type.
*/
type InferObjectIssue<TEntries extends ObjectEntries | ObjectEntriesAsync> = InferIssue<TEntries[keyof TEntries]>;
/**
* Array path item interface.
*/
interface ArrayPathItem {
/**
* The path item type.
*/
readonly type: 'array';
/**
* The path item origin.
*/
readonly origin: 'value';
/**
* The path item input.
*/
readonly input: MaybeReadonly<unknown[]>;
/**
* The path item key.
*/
readonly key: number;
/**
* The path item value.
*/
readonly value: unknown;
}
/**
* Map path item interface.
*/
interface MapPathItem {
/**
* The path item type.
*/
readonly type: 'map';
/**
* The path item origin.
*/
readonly origin: 'key' | 'value';
/**
* The path item input.
*/
readonly input: Map<unknown, unknown>;
/**
* The path item key.
*/
readonly key: unknown;
/**
* The path item value.
*/
readonly value: unknown;
}
/**
* Object path item interface.
*/
interface ObjectPathItem {
/**
* The path item type.
*/
readonly type: 'object';
/**
* The path item origin.
*/
readonly origin: 'key' | 'value';
/**
* The path item input.
*/
readonly input: Record<string, unknown>;
/**
* The path item key.
*/
readonly key: string;
/**
* The path item value.
*/
readonly value: unknown;
}
/**
* Set path item interface.
*/
interface SetPathItem {
/**
* The path item type.
*/
readonly type: 'set';
/**
* The path item origin.
*/
readonly origin: 'value';
/**
* The path item input.
*/
readonly input: Set<unknown>;
/**
* The path item key.
*/
readonly key: null;
/**
* The path item key.
*/
readonly value: unknown;
}
/**
* Unknown path item interface.
*/
interface UnknownPathItem {
/**
* The path item type.
*/
readonly type: 'unknown';
/**
* The path item origin.
*/
readonly origin: 'key' | 'value';
/**
* The path item input.
*/
readonly input: unknown;
/**
* The path item key.
*/
readonly key: unknown;
/**
* The path item value.
*/
readonly value: unknown;
}
/**
* Issue path item type.
*/
type IssuePathItem = ArrayPathItem | MapPathItem | ObjectPathItem | SetPathItem | UnknownPathItem;
/**
* Base issue interface.
*/
interface BaseIssue<TInput> extends Config<BaseIssue<TInput>> {
/**
* The issue kind.
*/
readonly kind: 'schema' | 'validation' | 'transformation';
/**
* The issue type.
*/
readonly type: string;
/**
* The raw input data.
*/
readonly input: TInput;
/**
* The expected property.
*/
readonly expected: string | null;
/**
* The received property.
*/
readonly received: string;
/**
* The error message.
*/
readonly message: string;
/**
* The input requirement.
*/
readonly requirement?: unknown | undefined;
/**
* The issue path.
*/
readonly path?: [IssuePathItem, ...IssuePathItem[]] | undefined;
/**
* The sub issues.
*/
readonly issues?: [BaseIssue<TInput>, ...BaseIssue<TInput>[]] | undefined;
}
/**
* Config interface.
*/
interface Config<TIssue extends BaseIssue<unknown>> {
/**
* The selected language.
*/
readonly lang?: string | undefined;
/**
* The error message.
*/
readonly message?: ErrorMessage<TIssue> | undefined;
/**
* Whether it should be aborted early.
*/
readonly abortEarly?: boolean | undefined;
/**
* Whether a pipe should be aborted early.
*/
readonly abortPipeEarly?: boolean | undefined;
}
/**
* Pipe action type.
*/
type PipeAction<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidation<TInput, TOutput, TIssue> | BaseTransformation<TInput, TOutput, TIssue> | BaseMetadata<TInput>;
/**
* Pipe action async type.
*/
type PipeActionAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseValidationAsync<TInput, TOutput, TIssue> | BaseTransformationAsync<TInput, TOutput, TIssue>;
/**
* Pipe item type.
*/
type PipeItem<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchema<TInput, TOutput, TIssue> | PipeAction<TInput, TOutput, TIssue>;
/**
* Pipe item async type.
*/
type PipeItemAsync<TInput, TOutput, TIssue extends BaseIssue<unknown>> = BaseSchemaAsync<TInput, TOutput, TIssue> | PipeActionAsync<TInput, TOutput, TIssue>;
/**
* Array issue interface.
*/
interface ArrayIssue extends BaseIssue<unknown> {
/**
* The issue kind.
*/
readonly kind: 'schema';
/**
* The issue type.
*/
readonly type: 'array';
/**
* The expected property.
*/
readonly expected: 'Array';
}
/**
* Array schema interface.
*/
interface ArraySchema<TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TMessage extends ErrorMessage<ArrayIssue> | undefined> extends BaseSchema<InferInput<TItem>[], InferOutput<TItem>[], ArrayIssue | InferIssue<TItem>> {
/**
* The schema type.
*/
readonly type: 'array';
/**
* The schema reference.
*/
readonly reference: typeof array;
/**
* The expected property.
*/
readonly expects: 'Array';
/**
* The array item schema.
*/
readonly item: TItem;
/**
* The error message.
*/
readonly message: TMessage;
}
/**
* Creates an array schema.
*
* @param item The item schema.
*
* @returns An array schema.
*/
declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(item: TItem): ArraySchema<TItem, undefined>;
/**
* Creates an array schema.
*
* @param item The item schema.
* @param message The error message.
*
* @returns An array schema.
*/
declare function array<const TItem extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TMessage extends ErrorMessage<ArrayIssue> | undefined>(item: TItem, message: TMessage): ArraySchema<TItem, TMessage>;
/**
* Boolean issue interface.
*/
interface BooleanIssue extends BaseIssue<unknown> {
/**
* The issue kind.
*/
readonly kind: 'schema';
/**
* The issue type.
*/
readonly type: 'boolean';
/**
* The expected property.
*/
readonly expected: 'boolean';
}
/**
* Boolean schema interface.
*/
interface BooleanSchema<TMessage extends ErrorMessage<BooleanIssue> | undefined> extends BaseSchema<boolean, boolean, BooleanIssue> {
/**
* The schema type.
*/
readonly type: 'boolean';
/**
* The schema reference.
*/
readonly reference: typeof boolean;
/**
* The expected property.
*/
readonly expects: 'boolean';
/**
* The error message.
*/
readonly message: TMessage;
}
/**
* Creates a boolean schema.
*
* @returns A boolean schema.
*/
declare function boolean(): BooleanSchema<undefined>;
/**
* Creates a boolean schema.
*
* @param message The error message.
*
* @returns A boolean schema.
*/
declare function boolean<const TMessage extends ErrorMessage<BooleanIssue> | undefined>(message: TMessage): BooleanSchema<TMessage>;
/**
* Exact optional schema interface.
*/
interface ExactOptionalSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, never>> extends BaseSchema<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
/**
* The schema type.
*/
readonly type: 'exact_optional';
/**
* The schema reference.
*/
readonly reference: typeof exactOptional;
/**
* The expected property.
*/
readonly expects: TWrapped['expects'];
/**
* The wrapped schema.
*/
readonly wrapped: TWrapped;
/**
* The default value.
*/
readonly default: TDefault;
}
/**
* Creates an exact optional schema.
*
* @param wrapped The wrapped schema.
*
* @returns An exact optional schema.
*/
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchema<TWrapped, undefined>;
/**
* Creates an exact optional schema.
*
* @param wrapped The wrapped schema.
* @param default_ The default value.
*
* @returns An exact optional schema.
*/
declare function exactOptional<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, const TDefault extends Default<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchema<TWrapped, TDefault>;
/**
* Exact optional schema async interface.
*/
interface ExactOptionalSchemaAsync<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, never>> extends BaseSchemaAsync<InferInput<TWrapped>, InferOutput<TWrapped>, InferIssue<TWrapped>> {
/**
* The schema type.
*/
readonly type: 'exact_optional';
/**
* The schema reference.
*/
readonly reference: typeof exactOptional | typeof exactOptionalAsync;
/**
* The expected property.
*/
readonly expects: TWrapped['expects'];
/**
* The wrapped schema.
*/
readonly wrapped: TWrapped;
/**
* The default value.
*/
readonly default: TDefault;
}
/**
* Creates an exact optional schema.
*
* @param wrapped The wrapped schema.
*
* @returns An exact optional schema.
*/
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>>(wrapped: TWrapped): ExactOptionalSchemaAsync<TWrapped, undefined>;
/**
* Creates an exact optional schema.
*
* @param wrapped The wrapped schema.
* @param default_ The default value.
*
* @returns An exact optional schema.
*/
declare function exactOptionalAsync<const TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, const TDefault extends DefaultAsync<TWrapped, never>>(wrapped: TWrapped, default_: TDefault): ExactOptionalSchemaAsync<TWrapped, TDefault>;
/**
* Intersect issue interface.
*/
interface IntersectIssue extends BaseIssue<unknown> {
/**
* The issue kind.
*/
readonly kind: 'schema';
/**
* The issue type.
*/
readonly type: 'intersect';
/**
* The expected property.
*/
readonly expected: string;
}
/**
* Intersect options type.
*/
type IntersectOptions = MaybeReadonly<BaseSchema<unknown, unknown, BaseIssue<unknown>>[]>;
/**
* Intersect options async type.
*/
type IntersectOptionsAsync = MaybeReadonly<(BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>)[]>;
/**
* Infer option type.
*/
type InferOption<TInput, TOutput> = BaseSchema<TInput, TOutput, BaseIssue<unknown>> | BaseSchemaAsync<TInput, TOutput, BaseIssue<unknown>>;
/**
* Infer intersect input type.
*/
type InferIntersectInput<TOptions extends IntersectOptions | IntersectOptionsAsync> = TOptions extends readonly [
InferOption<infer TInput, unknown>,
...infer TRest
] ? TRest extends readonly [
InferOption<unknown, unknown>,
...InferOption<unknown, unknown>[]
] ? TInput & InferIntersectInput<TRest> : TInput : never;
/**
* Infer intersect output type.
*/
type InferIntersectOutput<TOptions extends IntersectOptions | IntersectOptionsAsync> = TOptions extends readonly [
InferOption<unknown, infer TOutput>,
...infer TRest
] ? TRest extends readonly [
InferOption<unknown, unknown>,
...InferOption<unknown, unknown>[]
] ? TOutput & InferIntersectOutput<TRest> : TOutput : never;
/**
* Intersect schema interface.
*/
interface IntersectSchema<TOptions extends IntersectOptions, TMessage extends ErrorMessage<IntersectIssue> | undefined> extends BaseSchema<InferIntersectInput<TOptions>, InferIntersectOutput<TOptions>, IntersectIssue | InferIssue<TOptions[number]>> {
/**
* The schema type.
*/
readonly type: 'intersect';
/**
* The schema reference.
*/
readonly reference: typeof intersect;
/**
* The intersect options.
*/
readonly options: TOptions;
/**
* The error message.
*/
readonly message: TMessage;
}
/**
* Creates an intersect schema.
*
* @param options The intersect options.
*
* @returns An intersect schema.
*/
declare function intersect<const TOptions extends IntersectOptions>(options: TOptions): IntersectSchema<TOptions, undefined>;
/**
* Creates an intersect schema.
*
* @param options The intersect options.
* @param message The error message.
*
* @returns An intersect schema.
*/
declare function intersect<const TOptions extends IntersectOptions, const TMessage extends ErrorMessage<IntersectIssue> | undefined>(options: TOptions, message: TMessage): IntersectSchema<TOptions, TMessage>;
/**
* Literal type.
*/
type Literal = bigint | boolean | number | string | symbol;
/**
* Literal issue interface.
*/
interface LiteralIssue extends BaseIssue<unknown> {
/**
* The issue kind.
*/
readonly kind: 'schema';
/**
* The issue type.
*/
readonly type: 'literal';
/**
* The expected property.
*/
readonly expected: string;
}
/**
* Literal schema interface.
*/
interface LiteralSchema<TLiteral extends Literal, TMessage extends ErrorMessage<LiteralIssue> | undefined> extends BaseSchema<TLiteral, TLiteral, LiteralIssue> {
/**
* The schema type.
*/
readonly type: 'literal';
/**
* The schema reference.
*/
readonly reference: typeof literal;
/**
* The literal value.
*/
readonly literal: TLiteral;
/**
* The error message.
*/
readonly message: TMessage;
}
/**
* Creates a literal schema.
*
* @param literal_ The literal value.
*
* @returns A literal schema.
*/
declare function literal<const TLiteral extends Literal>(literal_: TLiteral): LiteralSchema<TLiteral, undefined>;
/**
* Creates a literal schema.
*
* @param literal_ The literal value.
* @param message The error message.
*
* @returns A literal schema.
*/
declare function literal<const TLiteral extends Literal, const TMessage extends ErrorMessage<LiteralIssue> | undefined>(literal_: TLiteral, message: TMessage): LiteralSchema<TLiteral, TMessage>;
/**
* Union issue interface.
*/
interface UnionIssue<TSubIssue extends BaseIssue<unknown>> extends BaseIssue<unknown> {
/**
* The issue kind.
*/
readonly kind: 'schema';
/**
* The issue type.
*/
readonly type: 'union';
/**
* The expected property.
*/
readonly expected: string;
/**
* The sub issues.
*/
readonly issues?: [TSubIssue, ...TSubIssue[]];
}
/**
* Union options type.
*/
type UnionOptions = MaybeReadonly<BaseSchema<unknown, unknown, BaseIssue<unknown>>[]>;
/**
* Union schema interface.
*/
interface UnionSchema<TOptions extends UnionOptions, TMessage extends ErrorMessage<UnionIssue<InferIssue<TOptions[number]>>> | undefined> extends BaseSchema<InferInput<TOptions[number]>, InferOutput<TOptions[number]>, UnionIssue<InferIssue<TOptions[number]>> | InferIssue<TOptions[number]>> {
/**
* The schema type.
*/
readonly type: 'union';
/**
* The schema reference.
*/
readonly reference: typeof union;
/**
* The union options.
*/
readonly options: TOptions;
/**
* The error message.
*/
readonly message: TMessage;
}
/**
* Creates an union schema.
*
* @param options The union options.
*
* @returns An union schema.
*/
declare function union<const TOptions extends UnionOptions>(options: TOptions): UnionSchema<TOptions, undefined>;
/**
* Creates an union schema.
*
* @param options The union options.
* @param message The error message.
*
* @returns An union schema.
*/
declare function union<const TOptions extends UnionOptions, const TMessage extends ErrorMessage<UnionIssue<InferIssue<TOptions[number]>>> | undefined>(options: TOptions, message: TMessage): UnionSchema<TOptions, TMessage>;
/**
* Infer nullable output type.
*/
type InferNullableOutput<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>> | BaseSchemaAsync<unknown, unknown, BaseIssue<unknown>>, TDefault extends DefaultAsync<TWrapped, null>> = undefined extends TDefault ? InferOutput<TWrapped> | null : InferOutput<TWrapped> | Extract<DefaultValue<TDefault>, null>;
/**
* Nullable schema interface.
*/
interface NullableSchema<TWrapped extends BaseSchema<unknown, unknown, BaseIssue<unknown>>, TDefault extends Default<TWrapped, null>> extends BaseSchema<InferInput<TWrapped> | null, InferNullableOutput<TWrapped, TDefault>, InferIssue<TWrapped>> {
/**
* The schema type.
*/
readonly type: 'nullable';
/**
* The schema reference.
*/
readonly reference: typeof nullable;
/**
* The expected property.
*/
readonly expects: `(${TWrapped['expects']} | null)`;
/**
* The wrapped schema.
*/
readonly wrapped: TWrapped;
/**
* The default value.
*/
readonly default: TDefault;
}
/**
* Creates a nullable schema.
*
* @param wrapped The wrapped schema.
*
* @returns A nullable schema.
*/
declare function nullable<const TWrapped extends BaseSchema<unkn