//#region src/items.d.ts type Item = /** `Name:value` -- a request header. `value: null` unsets a default header. */ { kind: 'header'; name: string; value: string | null; } | /** `name==value` -- a URL query parameter. */ { kind: 'query'; name: string; value: string; } | /** `name=value` -- a body field with a string value. */ { kind: 'field'; name: string; value: string; } | /** `name:=value` -- a body field with a raw JSON value. */ { kind: 'raw'; name: string; value: unknown; } | /** `name@path` -- a file upload; forces multipart. */ { kind: 'file'; name: string; path: string; } | /** `name=@path` -- a body field whose string value is read from a file. */ { kind: 'fieldFile'; name: string; path: string; } | /** `name:=@path` -- a body field whose JSON value is parsed from a file. */ { kind: 'rawFile'; name: string; path: string; }; type ItemKind = Item['kind']; /** Parse a single request-item token. Throws `CliError(EXIT.USAGE)` on anything malformed. */ declare function parseItem(token: string): Item; declare function parseItems(tokens: readonly string[]): Item[]; /** True for items that contribute to the request body (as opposed to headers or the query string). */ declare function isBodyItem(item: Item): boolean; //#endregion //#region src/args.d.ts type PrettyMode = 'all' | 'colors' | 'format' | 'none'; interface PrintSet { reqHeaders: boolean; reqBody: boolean; resHeaders: boolean; resBody: boolean; meta: boolean; } interface ResolvedFlags { json: boolean; form: boolean; multipart: boolean; raw: string | undefined; file: string | undefined; auth: string | undefined; bearer: string | undefined; print: PrintSet; output: string | undefined; download: boolean; pretty: PrettyMode | undefined; follow: boolean; maxRedirects: number; timeout: number | undefined; insecure: boolean; checkStatus: boolean; offline: boolean; verbose: boolean; } interface Options { method: string; url: URL; items: Item[]; flags: ResolvedFlags; /** The bin name the user actually typed, used to prefix error messages. */ invokedAs: string; /** Set when the deprecated `-u/--url` form was used. */ deprecation: string | undefined; } interface ParseContext { invokedAs: string; /** Set for the per-method shortcut bins; undefined for the `httpc` umbrella. */ fixedMethod?: string | undefined; stdoutIsTTY: boolean; stdinIsTTY: boolean; /** * Whether piped stdin actually carries bytes. Used only to infer the method for the * `httpc` umbrella -- "stdin is not a TTY" is far too broad on its own, since that is * true of every script, cron job, and CI step regardless of whether anything was piped in. */ stdinHasData?: boolean; } interface HelpRequest { kind: 'help' | 'version'; invokedAs: string; fixedMethod: string | undefined; } type ParseResult = { kind: 'run'; options: Options; } | HelpRequest; /** Safe methods, for which redirects need no method rewriting on 307/308. */ declare const SAFE_METHODS: Set; /** * Accept the shorthands people actually type: a bare host, and a leading colon for * localhost. Everything else must already be a URL. */ declare function resolveUrl(raw: string): URL; declare function parseArgv(argv: readonly string[], context: ParseContext): ParseResult; /** Exposed so help output can list the same methods the bins cover. */ declare const SHORTCUT_METHODS: readonly ['get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'query']; /** Shortcuts that are not installed by default because they would shadow real commands. */ declare const OPTIONAL_SHORTCUTS: readonly ['head', 'patch']; //#endregion //#region src/request.d.ts /** The body shapes we ever construct. Narrower than `BodyInit`, which Node does not declare globally. */ type RequestBody = string | Buffer | Blob | FormData | URLSearchParams; interface Prepared { method: string; url: URL; headers: Headers; body: RequestBody | null; /** A short textual rendering of the body for `--verbose` / `--offline`. */ bodyPreview: string | null; /** False when the body could not survive being sent a second time (it never is, today). */ replayable: boolean; } interface BuildDeps { /** Lazy so that a piped stdin is only drained when it is actually the body source. */ readStdin: () => Promise; promptPassword: (user: string) => Promise; stdinIsTTY: boolean; } interface Hop { status: number; from: string; to: string; method: string; droppedBody: boolean; droppedAuth: boolean; } interface Timing { startedAt: number; headersMs: number; } /** * A `--timeout` that spans the whole exchange. The caller clears it only after the * response body has been consumed, so a slow download counts against the same budget. */ interface Deadline { signal: AbortSignal | undefined; expired: () => boolean; clear: () => void; seconds: number | undefined; } declare function createDeadline(seconds: number | undefined): Deadline; /** Rethrow a transport error as a timeout when our own deadline is what killed it. */ declare function classifyAbort(err: unknown, deadline: Deadline): unknown; declare function buildRequest(options: Options, deps: BuildDeps): Promise; interface SendResult { response: Response; hops: Hop[]; timing: Timing; finalUrl: URL; } declare function send(prepared: Prepared, options: Options, deadline: Deadline): Promise; //#endregion //#region src/mime.d.ts declare function guessMime(filePath: string): string; /** Strip parameters: `application/json; charset=utf-8` -> `application/json`. */ declare function baseType(contentType: string | null | undefined): string; /** * Matches `application/json`, `text/json`, and every `+json` structured suffix * (`application/problem+json`, `application/vnd.api+json`, ...). The 0.0.x code compared * the whole header for equality, so anything with a charset fell through to the text path. */ declare function isJsonType(contentType: string | null | undefined): boolean; declare function isTextType(contentType: string | null | undefined): boolean; //#endregion //#region src/color.d.ts type Style = (text: string) => string; interface Styles { bold: Style; dim: Style; red: Style; green: Style; yellow: Style; blue: Style; magenta: Style; cyan: Style; } declare function createStyles(enabled: boolean): Styles; interface ColorEnvironment { isTTY: boolean; env: Record; } /** * `--pretty` wins, then the NO_COLOR / FORCE_COLOR conventions, then TTY detection. * https://no-color.org treats any non-empty value as "disable". */ declare function supportsColor(pretty: PrettyMode | undefined, { isTTY, env }: ColorEnvironment): boolean; /** Whether structured bodies (JSON) should be re-indented. Orthogonal to colour. */ declare function supportsFormatting(pretty: PrettyMode | undefined): boolean; declare function stripAnsi(text: string): string; //#endregion //#region src/json.d.ts /** * Pretty-print parsed JSON, optionally coloured. * * This walks the *parsed value* rather than running a regex over `JSON.stringify` * output: a regex cannot tell a brace inside a string value from a structural one, * so it mis-colours any payload containing JSON-ish text. * * With `styles === null` the output is byte-identical to `JSON.stringify(value, null, indent)`. */ declare function formatJson(value: unknown, styles: Styles | null, indent?: number): string; /** * Parse for display. Returns `undefined` when the text is not JSON after all, so the * caller can fall back to showing it verbatim instead of swallowing a malformed body. */ declare function tryParseJson(text: string): { value: unknown; } | undefined; //#endregion //#region src/render.d.ts declare function formatBytes(bytes: number): string; /** * Decode `Content-Disposition`, preferring the RFC 5987 `filename*` form, and fall back * to the final URL's last path segment. */ declare function deriveDownloadFilename(headers: Headers, url: URL): string; declare function sanitizeFilename(name: string): string; //#endregion //#region src/errors.d.ts declare const EXIT: { readonly OK: 0; readonly ERROR: 1; readonly USAGE: 2; readonly TIMEOUT: 3; readonly TOO_MANY_REDIRECTS: 4; readonly STATUS_4XX: 5; readonly STATUS_5XX: 6; readonly STATUS_3XX: 7; }; type ExitCode = (typeof EXIT)[keyof typeof EXIT]; declare class CliError extends Error { readonly code: ExitCode; readonly hint: string | undefined; constructor(code: ExitCode, message: string, hint?: string); } interface FormattedError { message: string; hint: string | undefined; code: ExitCode; } /** Turn anything thrown during a run into a one-line message plus an exit code. */ declare function formatError(err: unknown): FormattedError; //#endregion //#region src/cli.d.ts interface RunContext { invokedAs: string; fixedMethod: string | undefined; } declare function run(argv: readonly string[], context: RunContext): Promise; /** * Entry point shared by every bin. Never calls `process.exit` on the success path so * that stdout is flushed before the process ends. */ declare function main(fixedMethod?: string): Promise; //#endregion //#region src/version.d.ts declare const NAME: string; declare const VERSION: string; declare const USER_AGENT: string; //#endregion export { type BuildDeps, CliError, type Deadline, EXIT, type ExitCode, type Hop, type Item, type ItemKind, NAME, OPTIONAL_SHORTCUTS, type Options, type ParseContext, type ParseResult, type Prepared, type PrettyMode, type PrintSet, type RequestBody, type ResolvedFlags, type RunContext, SAFE_METHODS, SHORTCUT_METHODS, type SendResult, type Styles, type Timing, USER_AGENT, VERSION, baseType, buildRequest, classifyAbort, createDeadline, createStyles, deriveDownloadFilename, formatBytes, formatError, formatJson, guessMime, isBodyItem, isJsonType, isTextType, main, parseArgv, parseItem, parseItems, resolveUrl, run, sanitizeFilename, send, stripAnsi, supportsColor, supportsFormatting, tryParseJson }; //# sourceMappingURL=index.d.ts.map