|
| 1 | +/** |
| 2 | + * Copied from https://github.com/standard-schema/standard-schema/blob/70ca676f26e98cb1ebd24ae21330dfbcaca69f57/packages/spec/README.md |
| 3 | + * |
| 4 | + * MIT License |
| 5 | + * |
| 6 | + * Copyright (c) 2024 Colin McDonnell |
| 7 | + */ |
| 8 | + |
| 9 | +// ######################### |
| 10 | +// ### Standard Typed ### |
| 11 | +// ######################### |
| 12 | + |
| 13 | +/** The Standard Typed interface. This is a base type extended by other specs. */ |
| 14 | +export interface StandardTypedV1<Input = unknown, Output = Input> { |
| 15 | + /** The Standard properties. */ |
| 16 | + readonly '~standard': StandardTypedV1.Props<Input, Output> |
| 17 | +} |
| 18 | + |
| 19 | +export declare namespace StandardTypedV1 { |
| 20 | + /** The Standard Typed properties interface. */ |
| 21 | + export interface Props<Input = unknown, Output = Input> { |
| 22 | + /** The version number of the standard. */ |
| 23 | + readonly version: 1 |
| 24 | + /** The vendor name of the schema library. */ |
| 25 | + readonly vendor: string |
| 26 | + /** Inferred types associated with the schema. */ |
| 27 | + readonly types?: Types<Input, Output> | undefined |
| 28 | + } |
| 29 | + |
| 30 | + /** The Standard Typed types interface. */ |
| 31 | + export interface Types<Input = unknown, Output = Input> { |
| 32 | + /** The input type of the schema. */ |
| 33 | + readonly input: Input |
| 34 | + /** The output type of the schema. */ |
| 35 | + readonly output: Output |
| 36 | + } |
| 37 | + |
| 38 | + /** Infers the input type of a Standard Typed. */ |
| 39 | + export type InferInput<Schema extends StandardTypedV1> = NonNullable< |
| 40 | + Schema['~standard']['types'] |
| 41 | + >['input'] |
| 42 | + |
| 43 | + /** Infers the output type of a Standard Typed. */ |
| 44 | + export type InferOutput<Schema extends StandardTypedV1> = NonNullable< |
| 45 | + Schema['~standard']['types'] |
| 46 | + >['output'] |
| 47 | +} |
| 48 | + |
| 49 | +// ########################## |
| 50 | +// ### Standard Schema ### |
| 51 | +// ########################## |
| 52 | + |
| 53 | +/** The Standard Schema interface. */ |
| 54 | +export interface StandardSchemaV1<Input = unknown, Output = Input> { |
| 55 | + /** The Standard Schema properties. */ |
| 56 | + readonly '~standard': StandardSchemaV1.Props<Input, Output> |
| 57 | +} |
| 58 | + |
| 59 | +export declare namespace StandardSchemaV1 { |
| 60 | + /** The Standard Schema properties interface. */ |
| 61 | + export interface Props< |
| 62 | + Input = unknown, |
| 63 | + Output = Input, |
| 64 | + > extends StandardTypedV1.Props<Input, Output> { |
| 65 | + /** Validates unknown input values. */ |
| 66 | + readonly validate: ( |
| 67 | + value: unknown, |
| 68 | + options?: StandardSchemaV1.Options | undefined, |
| 69 | + ) => Result<Output> | Promise<Result<Output>> |
| 70 | + } |
| 71 | + |
| 72 | + /** The result interface of the validate function. */ |
| 73 | + export type Result<Output> = SuccessResult<Output> | FailureResult |
| 74 | + |
| 75 | + /** The result interface if validation succeeds. */ |
| 76 | + export interface SuccessResult<Output> { |
| 77 | + /** The typed output value. */ |
| 78 | + readonly value: Output |
| 79 | + /** A falsy value for `issues` indicates success. */ |
| 80 | + readonly issues?: undefined |
| 81 | + } |
| 82 | + |
| 83 | + export interface Options { |
| 84 | + /** Explicit support for additional vendor-specific parameters, if needed. */ |
| 85 | + readonly libraryOptions?: Record<string, unknown> | undefined |
| 86 | + } |
| 87 | + |
| 88 | + /** The result interface if validation fails. */ |
| 89 | + export interface FailureResult { |
| 90 | + /** The issues of failed validation. */ |
| 91 | + readonly issues: ReadonlyArray<Issue> |
| 92 | + } |
| 93 | + |
| 94 | + /** The issue interface of the failure output. */ |
| 95 | + export interface Issue { |
| 96 | + /** The error message of the issue. */ |
| 97 | + readonly message: string |
| 98 | + /** The path of the issue, if any. */ |
| 99 | + readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined |
| 100 | + } |
| 101 | + |
| 102 | + /** The path segment interface of the issue. */ |
| 103 | + export interface PathSegment { |
| 104 | + /** The key representing a path segment. */ |
| 105 | + readonly key: PropertyKey |
| 106 | + } |
| 107 | + |
| 108 | + /** The Standard types interface. */ |
| 109 | + export interface Types< |
| 110 | + Input = unknown, |
| 111 | + Output = Input, |
| 112 | + > extends StandardTypedV1.Types<Input, Output> {} |
| 113 | + |
| 114 | + /** Infers the input type of a Standard. */ |
| 115 | + export type InferInput<Schema extends StandardTypedV1> = |
| 116 | + StandardTypedV1.InferInput<Schema> |
| 117 | + |
| 118 | + /** Infers the output type of a Standard. */ |
| 119 | + export type InferOutput<Schema extends StandardTypedV1> = |
| 120 | + StandardTypedV1.InferOutput<Schema> |
| 121 | +} |
0 commit comments