|
| 1 | +/** The Standard Schema interface. */ |
| 2 | +export interface StandardSchemaV1<Input = unknown, Output = Input> { |
| 3 | + /** The Standard Schema properties. */ |
| 4 | + readonly '~standard': StandardSchemaV1.Props<Input, Output> |
| 5 | +} |
| 6 | + |
| 7 | +// eslint-disable-next-line ts/no-namespace |
| 8 | +export declare namespace StandardSchemaV1 { |
| 9 | + /** The Standard Schema properties interface. */ |
| 10 | + export interface Props<Input = unknown, Output = Input> { |
| 11 | + /** The version number of the standard. */ |
| 12 | + readonly version: 1 |
| 13 | + /** The vendor name of the schema library. */ |
| 14 | + readonly vendor: string |
| 15 | + /** Validates unknown input values. */ |
| 16 | + readonly validate: ( |
| 17 | + value: unknown, |
| 18 | + ) => Result<Output> | Promise<Result<Output>> |
| 19 | + /** Inferred types associated with the schema. */ |
| 20 | + readonly types?: Types<Input, Output> | undefined |
| 21 | + } |
| 22 | + |
| 23 | + /** The result interface of the validate function. */ |
| 24 | + export type Result<Output> = SuccessResult<Output> | FailureResult |
| 25 | + |
| 26 | + /** The result interface if validation succeeds. */ |
| 27 | + export interface SuccessResult<Output> { |
| 28 | + /** The typed output value. */ |
| 29 | + readonly value: Output |
| 30 | + /** The non-existent issues. */ |
| 31 | + readonly issues?: undefined |
| 32 | + } |
| 33 | + |
| 34 | + /** The result interface if validation fails. */ |
| 35 | + export interface FailureResult { |
| 36 | + /** The issues of failed validation. */ |
| 37 | + readonly issues: ReadonlyArray<Issue> |
| 38 | + } |
| 39 | + |
| 40 | + /** The issue interface of the failure output. */ |
| 41 | + export interface Issue { |
| 42 | + /** The error message of the issue. */ |
| 43 | + readonly message: string |
| 44 | + /** The path of the issue, if any. */ |
| 45 | + readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined |
| 46 | + } |
| 47 | + |
| 48 | + /** The path segment interface of the issue. */ |
| 49 | + export interface PathSegment { |
| 50 | + /** The key representing a path segment. */ |
| 51 | + readonly key: PropertyKey |
| 52 | + } |
| 53 | + |
| 54 | + /** The Standard Schema types interface. */ |
| 55 | + export interface Types<Input = unknown, Output = Input> { |
| 56 | + /** The input type of the schema. */ |
| 57 | + readonly input: Input |
| 58 | + /** The output type of the schema. */ |
| 59 | + readonly output: Output |
| 60 | + } |
| 61 | + |
| 62 | + /** Infers the input type of a Standard Schema. */ |
| 63 | + export type InferInput<Schema extends StandardSchemaV1> = NonNullable< |
| 64 | + Schema['~standard']['types'] |
| 65 | + >['input'] |
| 66 | + |
| 67 | + /** Infers the output type of a Standard Schema. */ |
| 68 | + export type InferOutput<Schema extends StandardSchemaV1> = NonNullable< |
| 69 | + Schema['~standard']['types'] |
| 70 | + >['output'] |
| 71 | + |
| 72 | + // biome-ignore lint/complexity/noUselessEmptyExport: needed for granular visibility control of TS namespace |
| 73 | + export {} |
| 74 | +} |
0 commit comments