Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

parseUtil.d.ts 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
  2. import type { ZodParsedType } from "./util";
  3. export declare const makeIssue: (params: {
  4. data: any;
  5. path: (string | number)[];
  6. errorMaps: ZodErrorMap[];
  7. issueData: IssueData;
  8. }) => ZodIssue;
  9. export declare type ParseParams = {
  10. path: (string | number)[];
  11. errorMap: ZodErrorMap;
  12. async: boolean;
  13. };
  14. export declare type ParsePathComponent = string | number;
  15. export declare type ParsePath = ParsePathComponent[];
  16. export declare const EMPTY_PATH: ParsePath;
  17. export interface ParseContext {
  18. readonly common: {
  19. readonly issues: ZodIssue[];
  20. readonly contextualErrorMap?: ZodErrorMap;
  21. readonly async: boolean;
  22. };
  23. readonly path: ParsePath;
  24. readonly schemaErrorMap?: ZodErrorMap;
  25. readonly parent: ParseContext | null;
  26. readonly data: any;
  27. readonly parsedType: ZodParsedType;
  28. }
  29. export declare type ParseInput = {
  30. data: any;
  31. path: (string | number)[];
  32. parent: ParseContext;
  33. };
  34. export declare function addIssueToContext(ctx: ParseContext, issueData: IssueData): void;
  35. export declare type ObjectPair = {
  36. key: SyncParseReturnType<any>;
  37. value: SyncParseReturnType<any>;
  38. };
  39. export declare class ParseStatus {
  40. value: "aborted" | "dirty" | "valid";
  41. dirty(): void;
  42. abort(): void;
  43. static mergeArray(status: ParseStatus, results: SyncParseReturnType<any>[]): SyncParseReturnType;
  44. static mergeObjectAsync(status: ParseStatus, pairs: {
  45. key: ParseReturnType<any>;
  46. value: ParseReturnType<any>;
  47. }[]): Promise<SyncParseReturnType<any>>;
  48. static mergeObjectSync(status: ParseStatus, pairs: {
  49. key: SyncParseReturnType<any>;
  50. value: SyncParseReturnType<any>;
  51. alwaysSet?: boolean;
  52. }[]): SyncParseReturnType;
  53. }
  54. export interface ParseResult {
  55. status: "aborted" | "dirty" | "valid";
  56. data: any;
  57. }
  58. export declare type INVALID = {
  59. status: "aborted";
  60. };
  61. export declare const INVALID: INVALID;
  62. export declare type DIRTY<T> = {
  63. status: "dirty";
  64. value: T;
  65. };
  66. export declare const DIRTY: <T>(value: T) => DIRTY<T>;
  67. export declare type OK<T> = {
  68. status: "valid";
  69. value: T;
  70. };
  71. export declare const OK: <T>(value: T) => OK<T>;
  72. export declare type SyncParseReturnType<T = any> = OK<T> | DIRTY<T> | INVALID;
  73. export declare type AsyncParseReturnType<T> = Promise<SyncParseReturnType<T>>;
  74. export declare type ParseReturnType<T> = SyncParseReturnType<T> | AsyncParseReturnType<T>;
  75. export declare const isAborted: (x: ParseReturnType<any>) => x is INVALID;
  76. export declare const isDirty: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
  77. export declare const isValid: <T>(x: ParseReturnType<T>) => x is OK<T> | DIRTY<T>;
  78. export declare const isAsync: <T>(x: ParseReturnType<T>) => x is AsyncParseReturnType<T>;