Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
colinhacks committed Aug 16, 2024
1 parent 5a3b5f3 commit 8bf2cc1
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions rfcs/v4-issue-formats/formats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
type ZodParsedType = string;
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
class ZodError {}

export enum ZodIssueCode {
invalid_type = "invalid_type",
custom = "custom",
invalid_union = "invalid_union",
invalid_date = "invalid_date",
invalid_string = "invalid_string",
invalid_array = "invalid_array",
invalid_number = "invalid_number",
invalid_set = "invalid_set",
invalid_object = "invalid_object",
invalid_bigint = "invalid_bigint",
invalid_file = "invalid_file",
}

export type ZodIssueBase = {
path: (string | number)[];
message?: string;
input?: unknown;
code: ZodIssueCode;
level: "warn" | "error" | "abort";
};

export interface ZodInvalidTypeIssue extends ZodIssueBase {
code: typeof ZodIssueCode.invalid_type;
expected: ZodParsedType;
received: ZodParsedType;
}

export interface ZodInvalidUnionIssue extends ZodIssueBase {
code: typeof ZodIssueCode.invalid_union;
unionErrors: ZodError[];
}

export interface ZodInvalidDateIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_date;
subcode: "too_big" | "too_small";
minimum?: number;
maximum?: number;
exclusive?: boolean;
}

type $StringFormats =
| "email"
| "url"
| "jwt"
| "json"
| "emoji"
| "uuid"
| "nanoid"
| "guid"
| "regex"
| "cuid"
| "cuid2"
| "ulid"
| "xid"
| "ksuid"
| "datetime"
| "date"
| "time"
| "duration"
| "ip"
| "base64"
| "e164";

export interface ZodInvalidStringIssue extends ZodIssueBase {
code: typeof ZodIssueCode.invalid_string;
subcode: "too_small" | "too_big" | "invalid_format";
format?: $StringFormats;
pattern?: string;
startsWith?: string;
endsWith?: string;
includes?: string;
}

export interface ZodInvalidObjectIssue extends ZodIssueBase {
code: typeof ZodIssueCode.invalid_object;
subcode: "unrecognized_keys" | "missing_keys";
unrecognizedKeys?: string[];
missingKeys?: string[];
}

export interface ZodInvalidArrayIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_array;
subcode: "too_big" | "too_small" | "not_unique";
minimum?: number;
maximum?: number;
}

export interface ZodInvalidNumberIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_number;
subcode: "too_big" | "too_small" | "not_integer" | "not_multiple_of";
minimum?: number;
maximum?: number;
exclusive?: boolean;
multipleOf?: number;
}

export interface ZodInvalidSetIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_set;
subcode: "too_big" | "too_small" | "not_unique";
minimum?: number;
maximum?: number;
}

export interface ZodInvalidBigIntIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_bigint;
subcode: "too_big" | "too_small";
minimum?: number;
maximum?: number;
exclusive?: boolean;
}

export interface ZodInvalidFileIssue extends ZodIssueBase {
code: ZodIssueCode.invalid_file;
subcode: "too_big" | "too_small" | "invalid_mime" | "invalid_name";
minimum?: number;
maximum?: number;
acceptedTypes?: string[];
name?: string;
}

export interface ZodCustomIssue extends ZodIssueBase {
code: typeof ZodIssueCode.custom;
params?: { [k: string]: any };
}

export type ZodIssue =
| ZodInvalidTypeIssue
| ZodInvalidUnionIssue
| ZodInvalidStringIssue
| ZodInvalidArrayIssue
| ZodInvalidNumberIssue
| ZodInvalidSetIssue
| ZodInvalidObjectIssue
| ZodInvalidBigIntIssue
| ZodInvalidFileIssue
| ZodCustomIssue;
Empty file added rfcs/v4-issue-formats/index.md
Empty file.

0 comments on commit 8bf2cc1

Please sign in to comment.