type RetryCondition = (response: Response | null) => boolean | Promise; type LinearRetry = { type: "linear"; attempts: number; delay: number; shouldRetry?: RetryCondition; }; type ExponentialRetry = { type: "exponential"; attempts: number; baseDelay: number; maxDelay: number; shouldRetry?: RetryCondition; }; type RetryOptions = LinearRetry | ExponentialRetry | number; interface RetryStrategy { shouldAttemptRetry(attempt: number, response: Response | null): Promise; getDelay(attempt: number): number; } declare function createRetryStrategy(options: RetryOptions): RetryStrategy; /** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result | Promise>; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ type Result = SuccessResult | FailureResult; /** The result interface if validation succeeds. */ interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ type InferOutput = NonNullable["output"]; } type StringLiteralUnion = T | (string & {}); type Prettify = { [key in keyof T]: T[key]; } & {}; type FetchSchema = { input?: StandardSchemaV1; output?: StandardSchemaV1; query?: StandardSchemaV1; params?: StandardSchemaV1> | undefined; method?: Methods; }; type Methods = "get" | "post" | "put" | "patch" | "delete"; declare const methods: string[]; type RouteKey = StringLiteralUnion<`@${Methods}/`>; type FetchSchemaRoutes = { [key in RouteKey]?: FetchSchema; }; declare const createSchema: (schema: F, config?: S) => { schema: F; config: S; }; type SchemaConfig = { strict?: boolean; /** * A prefix that will be prepended when it's * calling the schema. * * NOTE: Make sure to handle converting * the prefix to the baseURL in the init * function if you you are defining for a * plugin. */ prefix?: "" | (string & Record); /** * The base url of the schema. By default it's the baseURL of the fetch instance. */ baseURL?: "" | (string & Record); }; type Schema = { schema: FetchSchemaRoutes; config: SchemaConfig; }; type CreateFetchOption = BetterFetchOption & { schema?: Schema; /** * Catch all error including non api errors. Like schema validation, etc. * @default false */ catchAllError?: boolean; defaultOutput?: StandardSchemaV1; defaultError?: StandardSchemaV1; }; type WithRequired = T & { [P in K]-?: T[P]; }; type InferBody = T extends StandardSchemaV1 ? StandardSchemaV1.InferInput : any; type RemoveEmptyString = T extends string ? "" extends T ? never : T : T; type InferParamPath = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath as RemoveEmptyString]: string; } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string; } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath : {}; type InferParam = Param extends StandardSchemaV1 ? StandardSchemaV1.InferInput : InferParamPath; type InferOptions = WithRequired, InferQuery, InferParam, Res>, RequiredOptionKeys extends keyof BetterFetchOption ? RequiredOptionKeys : never>; type InferQuery = Q extends StandardSchemaV1 ? StandardSchemaV1.InferInput : any; type IsFieldOptional = T extends StandardSchemaV1 ? undefined extends T ? true : false : true; type IsParamOptional = IsFieldOptional extends false ? false : IsEmptyObject> extends false ? false : true; type IsOptionRequired = IsFieldOptional extends false ? true : IsFieldOptional extends false ? true : IsParamOptional extends false ? true : false; type RequiredOptionKeys = (IsFieldOptional extends false ? "body" : never) | (IsFieldOptional extends false ? "query" : never) | (IsParamOptional extends false ? "params" : never); type InferKey = S extends Schema ? S["config"]["strict"] extends true ? S["config"]["prefix"] extends string ? `${S["config"]["prefix"]}${keyof S["schema"] extends string ? keyof S["schema"] : never}` : S["config"]["baseURL"] extends string ? `${S["config"]["baseURL"]}${keyof S["schema"] extends string ? keyof S["schema"] : never}` : keyof S["schema"] extends string ? keyof S["schema"] : never : S["config"]["prefix"] extends string ? StringLiteralUnion<`${S["config"]["prefix"]}${keyof S["schema"] extends string ? keyof S["schema"] : never}`> : S["config"]["baseURL"] extends string ? StringLiteralUnion<`${S["config"]["baseURL"]}${keyof S["schema"] extends string ? keyof S["schema"] : never}`> : StringLiteralUnion : string; type GetKey = S extends Schema ? S["config"]["baseURL"] extends string ? K extends `${S["config"]["baseURL"]}${infer AK}` ? AK extends string ? AK : string : S["config"]["prefix"] extends string ? K extends `${S["config"]["prefix"]}${infer AP}` ? AP : string : string : S["config"]["prefix"] extends string ? K extends `${S["config"]["prefix"]}${infer AP}` ? AP : K : K : K; type UnionToIntersection = (U extends any ? (x: U) => void : never) extends (x: infer I) => void ? I : never; type PluginSchema

= P extends BetterFetchPlugin ? P["schema"] extends Schema ? P["schema"] : {} : {}; type MergeSchema = Options["plugins"] extends Array ? PluginSchema

& Options["schema"] : Options["schema"]; type InferPluginOptions = Options["plugins"] extends Array ? P extends BetterFetchPlugin ? O extends Record ? UnionToIntersection : {} : {} : {}; type BetterFetch : unknown, DefaultErr = CreateOptions["defaultError"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : unknown, S extends MergeSchema = MergeSchema> = = InferKey, K extends GetKey = GetKey, F extends S extends Schema ? S["schema"][K] : unknown = S extends Schema ? S["schema"][K] : unknown, O extends Omit = Omit, "params">, PluginOptions extends Partial> = Partial>, Result = BetterFetchResponse : F extends FetchSchema ? F["output"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput : Res : Res, Err, O["throw"] extends boolean ? O["throw"] : CreateOptions["throw"] extends true ? true : Err extends false ? true : false>>(url: U, ...options: F extends FetchSchema ? IsOptionRequired extends true ? [ Prettify : any> & PluginOptions> ] : [ Prettify : any> & PluginOptions>? ] : [ Prettify; }>? ]) => Promise; declare const emptyObjectSymbol: unique symbol; type EmptyObject = { [emptyObjectSymbol]?: never; }; type IsEmptyObject = T extends EmptyObject ? true : false; declare const applySchemaPlugin: (config: CreateFetchOption) => { id: string; name: string; version: string; init(url: string, options: ({ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; })) | undefined; integrity?: string | undefined; keepalive?: boolean | undefined; method?: string | undefined; mode?: RequestMode | undefined; priority?: RequestPriority | undefined; redirect?: RequestRedirect | undefined; referrer?: string | undefined; referrerPolicy?: ReferrerPolicy | undefined; signal?: (AbortSignal | null) | undefined; window?: null | undefined; onRequest?: (>(context: RequestContext) => Promise | RequestContext | void) | undefined; onResponse?: ((context: ResponseContext) => Promise | Response | ResponseContext | void) | undefined; onSuccess?: ((context: SuccessContext) => Promise | void) | undefined; onError?: ((context: ErrorContext) => Promise | void) | undefined; onRetry?: ((response: ResponseContext) => Promise | void) | undefined; hookOptions?: { cloneResponse?: boolean; } | undefined; timeout?: number | undefined; customFetchImpl?: FetchEsque | undefined; plugins?: BetterFetchPlugin[] | undefined; baseURL?: string | undefined; throw?: boolean | undefined; auth?: Auth | undefined; body?: any; query?: any; params?: any; duplex?: ("full" | "half") | undefined; jsonParser?: ((text: string) => Promise | any) | undefined; retry?: RetryOptions | undefined; retryAttempt?: number | undefined; output?: (StandardSchemaV1 | typeof Blob | typeof File) | undefined; errorSchema?: StandardSchemaV1 | undefined; disableValidation?: boolean | undefined; } & Record) | undefined): Promise<{ url: string; options: { method: Methods | undefined; output: StandardSchemaV1 | undefined; cache?: RequestCache; credentials?: RequestCredentials; headers?: (HeadersInit & (HeadersInit | { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; })) | undefined; integrity?: string; keepalive?: boolean; mode?: RequestMode; priority?: RequestPriority; redirect?: RequestRedirect; referrer?: string; referrerPolicy?: ReferrerPolicy; signal?: AbortSignal | null; window?: null; onRequest?: >(context: RequestContext) => Promise | RequestContext | void; onResponse?: (context: ResponseContext) => Promise | Response | ResponseContext | void; onSuccess?: ((context: SuccessContext) => Promise | void) | undefined; onError?: (context: ErrorContext) => Promise | void; onRetry?: (response: ResponseContext) => Promise | void; hookOptions?: { cloneResponse?: boolean; }; timeout?: number; customFetchImpl?: FetchEsque; plugins?: BetterFetchPlugin[]; baseURL?: string; throw?: boolean; auth?: Auth; body?: any; query?: any; params?: any; duplex?: "full" | "half"; jsonParser?: (text: string) => Promise | any; retry?: RetryOptions; retryAttempt?: number; errorSchema?: StandardSchemaV1; disableValidation?: boolean; }; } | { url: string; options: ({ cache?: RequestCache | undefined; credentials?: RequestCredentials | undefined; headers?: (HeadersInit & (HeadersInit | { accept: "application/json" | "text/plain" | "application/octet-stream"; "content-type": "application/json" | "text/plain" | "application/x-www-form-urlencoded" | "multipart/form-data" | "application/octet-stream"; authorization: "Bearer" | "Basic"; })) | undefined; integrity?: string | undefined; keepalive?: boolean | undefined; method?: string | undefined; mode?: RequestMode | undefined; priority?: RequestPriority | undefined; redirect?: RequestRedirect | undefined; referrer?: string | undefined; referrerPolicy?: ReferrerPolicy | undefined; signal?: (AbortSignal | null) | undefined; window?: null | undefined; onRequest?: (>(context: RequestContext) => Promise | RequestContext | void) | undefined; onResponse?: ((context: ResponseContext) => Promise | Response | ResponseContext | void) | undefined; onSuccess?: ((context: SuccessContext) => Promise | void) | undefined; onError?: ((context: ErrorContext) => Promise | void) | undefined; onRetry?: ((response: ResponseContext) => Promise | void) | undefined; hookOptions?: { cloneResponse?: boolean; } | undefined; timeout?: number | undefined; customFetchImpl?: FetchEsque | undefined; plugins?: BetterFetchPlugin[] | undefined; baseURL?: string | undefined; throw?: boolean | undefined; auth?: Auth | undefined; body?: any; query?: any; params?: any; duplex?: ("full" | "half") | undefined; jsonParser?: ((text: string) => Promise | any) | undefined; retry?: RetryOptions | undefined; retryAttempt?: number | undefined; output?: (StandardSchemaV1 | typeof Blob | typeof File) | undefined; errorSchema?: StandardSchemaV1 | undefined; disableValidation?: boolean | undefined; } & Record) | undefined; }>; }; declare const createFetch: