Files
SnowLuma/.pnpm-store/v11/files/23/0d785498023427c5176544c1eaa1ba32da9386fd493622ad803e19b9c59c6a41d8c005cea88cdb909d9002665c45c6403ea757ca8ee30fdcf0e42703532e3b
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Canceled after 0s
Dev Build / typecheck (push) Canceled after 0s
Dev Build / build (linux-arm64, ubuntu-24.04-arm, linux-arm64) (push) Canceled after 0s
Dev Build / build (linux-x64, ubuntu-latest, linux-x64) (push) Canceled after 0s
Dev Build / build (win-x64, windows-latest, win32-x64) (push) Canceled after 0s
Dev Build / dispatch-dev-docker (push) Canceled after 0s
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

84 lines
3.2 KiB
Plaintext

import type * as z3 from 'zod/v3';
import type * as z4 from 'zod/v4/core';
export type AnySchema = z3.ZodTypeAny | z4.$ZodType;
export type AnyObjectSchema = z3.AnyZodObject | z4.$ZodObject | AnySchema;
export type ZodRawShapeCompat = Record<string, AnySchema>;
export interface ZodV3Internal {
_def?: {
typeName?: string;
value?: unknown;
values?: unknown[];
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
description?: string;
};
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
value?: unknown;
}
export interface ZodV4Internal {
_zod?: {
def?: {
type?: string;
value?: unknown;
values?: unknown[];
shape?: Record<string, AnySchema> | (() => Record<string, AnySchema>);
};
};
value?: unknown;
}
export type SchemaOutput<S> = S extends z3.ZodTypeAny ? z3.infer<S> : S extends z4.$ZodType ? z4.output<S> : never;
export type SchemaInput<S> = S extends z3.ZodTypeAny ? z3.input<S> : S extends z4.$ZodType ? z4.input<S> : never;
/**
* Infers the output type from a ZodRawShapeCompat (raw shape object).
* Maps over each key in the shape and infers the output type from each schema.
*/
export type ShapeOutput<Shape extends ZodRawShapeCompat> = {
[K in keyof Shape]: SchemaOutput<Shape[K]>;
};
export declare function isZ4Schema(s: AnySchema): s is z4.$ZodType;
export declare function objectFromShape(shape: ZodRawShapeCompat): AnyObjectSchema;
export declare function safeParse<S extends AnySchema>(schema: S, data: unknown): {
success: true;
data: SchemaOutput<S>;
} | {
success: false;
error: unknown;
};
export declare function safeParseAsync<S extends AnySchema>(schema: S, data: unknown): Promise<{
success: true;
data: SchemaOutput<S>;
} | {
success: false;
error: unknown;
}>;
export declare function getObjectShape(schema: AnyObjectSchema | undefined): Record<string, AnySchema> | undefined;
/**
* Normalizes a schema to an object schema. Handles both:
* - Already-constructed object schemas (v3 or v4)
* - Raw shapes that need to be wrapped into object schemas
*/
export declare function normalizeObjectSchema(schema: AnySchema | ZodRawShapeCompat | undefined): AnyObjectSchema | undefined;
/**
* Safely extracts an error message from a parse result error.
* Zod errors can have different structures, so we handle various cases.
*/
export declare function getParseErrorMessage(error: unknown): string;
/**
* Gets the description from a schema, if available.
* Works with both Zod v3 and v4.
*
* Both versions expose a `.description` getter that returns the description
* from their respective internal storage (v3: _def, v4: globalRegistry).
*/
export declare function getSchemaDescription(schema: AnySchema): string | undefined;
/**
* Checks if a schema is optional.
* Works with both Zod v3 and v4.
*/
export declare function isSchemaOptional(schema: AnySchema): boolean;
/**
* Gets the literal value from a schema, if it's a literal schema.
* Works with both Zod v3 and v4.
* Returns undefined if the schema is not a literal or the value cannot be determined.
*/
export declare function getLiteralValue(schema: AnySchema): unknown;
//# sourceMappingURL=zod-compat.d.ts.map