lacspace-http 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.d.cts ADDED
@@ -0,0 +1,290 @@
1
+ /**
2
+ * A tiny, hand-written JSON-path evaluator used for response capture and
3
+ * assertions. It understands a deliberately small, predictable dialect — no
4
+ * `eval`, no regex-of-doom, no wildcards:
5
+ *
6
+ * $ the root value
7
+ * $.data.items object keys via dots
8
+ * data.items a leading `$` is optional
9
+ * $.items[0].id array indices via brackets
10
+ * $.items[-1] negative indices count from the end
11
+ * $['odd key'].x bracketed / quoted keys (dots, spaces, etc.)
12
+ *
13
+ * Missing paths resolve to `undefined` rather than throwing, so an assertion
14
+ * like `body.$.error exists` can be tested cleanly.
15
+ */
16
+ /** One resolved step of a JSON path. */
17
+ type JsonPathSegment = {
18
+ type: "key";
19
+ key: string;
20
+ } | {
21
+ type: "index";
22
+ index: number;
23
+ };
24
+ /** Parse a path string into an ordered list of segments. Throws on syntax errors. */
25
+ declare function parseJsonPath(path: string): JsonPathSegment[];
26
+ /**
27
+ * Resolve `path` against `root`. Returns the value at the path, or `undefined`
28
+ * if any step does not exist. `$` alone returns `root` itself.
29
+ */
30
+ declare function evalPath(root: unknown, path: string): unknown;
31
+
32
+ /** A flat name→value map used to resolve `{{var}}` references. */
33
+ type VarScope = Map<string, string>;
34
+ /** Build a scope from any number of plain objects (later objects win). */
35
+ declare function makeScope(...sources: Array<Record<string, string> | undefined>): VarScope;
36
+ /** Result of {@link resolveVars}: the substituted text plus any unresolved names. */
37
+ interface ResolveResult {
38
+ text: string;
39
+ missing: string[];
40
+ }
41
+ /**
42
+ * Replace every `{{name}}` in `text` with its value from `scope` (or a built-in
43
+ * system variable). Unknown references are left verbatim and reported in
44
+ * `missing`, so callers can decide whether that's fatal.
45
+ */
46
+ declare function resolveVars(text: string, scope: VarScope): ResolveResult;
47
+ /**
48
+ * Parse a REST-client `http-client.env.json` document and return the merged
49
+ * variables for `envName`. A top-level `$shared` block (if present) is merged
50
+ * first, then the named environment overrides it.
51
+ */
52
+ declare function parseEnvJson(json: string, envName: string): Record<string, string>;
53
+ /** Parse a `.env`-style document (KEY=VALUE lines, `#` comments, optional quotes). */
54
+ declare function parseDotenv(text: string): Record<string, string>;
55
+ /** Parse `k=v` CLI pairs (repeatable `--var`) into a plain object. */
56
+ declare function parseKvPairs(pairs: string[]): Record<string, string>;
57
+
58
+ /**
59
+ * A hand-written parser for the well-known `.http` / `.rest` file format (the
60
+ * one VS Code's REST Client and JetBrains HTTP Client use). Requests are
61
+ * separated by `###`, may carry a `# @name` tag, and can declare `# @capture`
62
+ * and `# @assert` directives that turn a file into a runnable API test suite.
63
+ *
64
+ * The parser is intentionally forgiving and does no network work — it only
65
+ * turns text into structured {@link HttpFileRequest} objects.
66
+ */
67
+ /** A `# @capture <name> = <source>` directive. `source` is an assertion LHS. */
68
+ interface CaptureDirective {
69
+ name: string;
70
+ source: string;
71
+ }
72
+ /** A `# @assert <expr>` directive. `expr` is parsed later by the assert engine. */
73
+ interface AssertDirective {
74
+ expr: string;
75
+ }
76
+ /** One request block parsed out of a `.http` file. */
77
+ interface HttpFileRequest {
78
+ /** `# @name <id>` if present. */
79
+ name?: string;
80
+ method: string;
81
+ url: string;
82
+ /** Header pairs in source order (values may still contain `{{vars}}`). */
83
+ headers: Array<[string, string]>;
84
+ /** Raw request body (may contain `{{vars}}`), or undefined if none. */
85
+ body?: string;
86
+ captures: CaptureDirective[];
87
+ assertions: AssertDirective[];
88
+ /** 1-based line number of the request line, for diagnostics. */
89
+ line: number;
90
+ }
91
+ /**
92
+ * Parse a whole `.http` document into an ordered list of requests. Directive
93
+ * comments (`# @name`, `# @capture`, `# @assert`) are extracted; plain comments
94
+ * are ignored.
95
+ */
96
+ declare function parseHttpFile(source: string): HttpFileRequest[];
97
+
98
+ /**
99
+ * The request engine: assemble a {@link RequestSpec} from friendly options,
100
+ * send it with the global `fetch` (with manual redirect handling, a timeout, a
101
+ * response-size cap and precise timing), and render the equivalent `curl`
102
+ * command. The `fetch` implementation is injectable so tests never touch the
103
+ * network.
104
+ */
105
+ /** A concrete, ready-to-send HTTP request. */
106
+ interface RequestSpec {
107
+ method: string;
108
+ url: string;
109
+ /** Header pairs in order. */
110
+ headers: Array<[string, string]>;
111
+ body?: string;
112
+ }
113
+ /** Friendly inputs used to build a {@link RequestSpec}. */
114
+ interface AssembleOptions {
115
+ method?: string;
116
+ /** Raw `"Key: Value"` header strings (repeatable `-H`). */
117
+ headers?: string[];
118
+ /** `"k=v"` query params (repeatable `-q`). */
119
+ query?: string[];
120
+ /** Raw request body (`-d`). */
121
+ data?: string;
122
+ /** A raw JSON object/array string (`--json '{...}'`). */
123
+ json?: string;
124
+ /** `"k=v"` (string) or `"k:=v"` (raw JSON) JSON-body shorthands (`-j`). */
125
+ jsonKv?: string[];
126
+ /** `"k=v"` urlencoded form fields (`--form`). */
127
+ form?: string[];
128
+ /** Bearer token → `Authorization: Bearer <token>` (`-b`). */
129
+ bearer?: string;
130
+ /** `"user:pass"` → HTTP Basic `Authorization` header (`-u`). */
131
+ user?: string;
132
+ }
133
+ /** Assemble a concrete request from friendly options. Pure — no I/O. */
134
+ declare function assembleRequest(url: string, o?: AssembleOptions): RequestSpec;
135
+ /** Options controlling how a request is sent. */
136
+ interface SendOptions {
137
+ /** Abort after this many ms (default 30000). */
138
+ timeoutMs?: number;
139
+ /** Cap the response body read at this many bytes (default 10MB). */
140
+ maxSize?: number;
141
+ /** Follow up to this many redirects (default 5). */
142
+ maxRedirects?: number;
143
+ /** Whether to follow redirects at all (default true). */
144
+ followRedirects?: boolean;
145
+ /** Inject a `fetch` implementation (defaults to the global). */
146
+ fetchImpl?: typeof fetch;
147
+ }
148
+ /** A structured, serialisable record of an HTTP response. */
149
+ interface ResponseRecord {
150
+ status: number;
151
+ statusText: string;
152
+ /** Lower-cased header name → value. */
153
+ headers: Record<string, string>;
154
+ /** Total wall-clock time for the request (ms), including redirects. */
155
+ timeMs: number;
156
+ /** Bytes of body actually read (after any cap). */
157
+ size: number;
158
+ /** Response body as text (possibly truncated to `maxSize`). */
159
+ body: string;
160
+ /** Parsed JSON body, if the response looked like JSON. */
161
+ json?: unknown;
162
+ /** Final URL after any redirects. */
163
+ url: string;
164
+ /** Whether any redirect was followed. */
165
+ redirected: boolean;
166
+ /** The chain of URLs visited before the final one. */
167
+ redirectChain: string[];
168
+ ok: boolean;
169
+ /** True if the body was cut off at `maxSize`. */
170
+ truncated: boolean;
171
+ /** True if a followed redirect crossed to a different host. */
172
+ crossHostRedirect: boolean;
173
+ }
174
+ /**
175
+ * Send a {@link RequestSpec}. Redirects are followed manually so the hop count
176
+ * is enforced (`maxRedirects`) and cross-host hops are recorded rather than
177
+ * followed silently. Times out after `timeoutMs`; the body is read up to
178
+ * `maxSize` bytes.
179
+ */
180
+ declare function sendRequest(spec: RequestSpec, opts?: SendOptions): Promise<ResponseRecord>;
181
+ /** Options for {@link toCurl}. */
182
+ interface CurlOptions {
183
+ /** Show real credential values instead of masking them (default false). */
184
+ showSecrets?: boolean;
185
+ maxRedirects?: number;
186
+ followRedirects?: boolean;
187
+ }
188
+ /**
189
+ * Render the equivalent `curl` command for a request. Credentials in an
190
+ * `Authorization` header are masked (`Bearer ***` / `Basic ***`) unless
191
+ * `showSecrets` is set.
192
+ */
193
+ declare function toCurl(spec: RequestSpec, opts?: CurlOptions): string;
194
+
195
+ /** The comparison operators an assertion may use. */
196
+ type AssertOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "contains" | "matches" | "exists" | "empty";
197
+ /** A parsed assertion: an LHS, an operator, and (for binary ops) an RHS. */
198
+ interface Assertion {
199
+ lhs: string;
200
+ op: AssertOp;
201
+ rhs?: string;
202
+ raw: string;
203
+ }
204
+ /** Parse an assertion expression like `body.$.ok == true`. Throws on malformed input. */
205
+ declare function parseAssertion(expr: string): Assertion;
206
+ /** Resolve an LHS expression to a concrete value from the response. */
207
+ declare function resolveLhs(lhs: string, rec: ResponseRecord): unknown;
208
+ /** The outcome of evaluating one assertion. */
209
+ interface AssertResult {
210
+ ok: boolean;
211
+ assertion: Assertion;
212
+ actual: unknown;
213
+ expected?: unknown;
214
+ message: string;
215
+ }
216
+ /** Evaluate a parsed assertion against a response. */
217
+ declare function evalAssertion(assertion: Assertion, rec: ResponseRecord): AssertResult;
218
+ /** Parse + evaluate in one step. */
219
+ declare function runAssertion(expr: string, rec: ResponseRecord): AssertResult;
220
+ /** Resolve a capture source (same grammar as an LHS) to a string value. */
221
+ declare function captureValue(source: string, rec: ResponseRecord): string | undefined;
222
+
223
+ /** Options for {@link runHttpFile}. */
224
+ interface RunOptions extends SendOptions {
225
+ /** Variables from an env block (`http-client.env.json` / `.env`). */
226
+ env?: Record<string, string>;
227
+ /** CLI `--var k=v` overrides (highest precedence at start). */
228
+ vars?: Record<string, string>;
229
+ /** Run only the request whose `# @name` matches this. */
230
+ name?: string;
231
+ /** Called after each request completes (for streaming CLI output). */
232
+ onResult?: (result: RequestRunResult) => void;
233
+ }
234
+ /** The result of running one request from the file. */
235
+ interface RequestRunResult {
236
+ name?: string;
237
+ method: string;
238
+ url: string;
239
+ line: number;
240
+ /** Unresolved `{{vars}}` encountered while building the request. */
241
+ missingVars: string[];
242
+ /** Set when the request could not be sent at all. */
243
+ error?: string;
244
+ response?: ResponseRecord;
245
+ assertions: AssertResult[];
246
+ /** Values captured from this response (name → value). */
247
+ captured: Record<string, string>;
248
+ /** True if it was sent, all assertions passed and no error occurred. */
249
+ ok: boolean;
250
+ }
251
+ /** The overall result of a run. */
252
+ interface RunResult {
253
+ results: RequestRunResult[];
254
+ passed: number;
255
+ failed: number;
256
+ ok: boolean;
257
+ }
258
+ /** Parse and run a `.http` document. */
259
+ declare function runHttpFile(source: string, opts?: RunOptions): Promise<RunResult>;
260
+
261
+ /**
262
+ * Presentation helpers: a byte-size formatter, a status-code colour picker, and
263
+ * a JSON pretty-printer with optional ANSI syntax highlighting. With `color`
264
+ * off, {@link prettyJson} is byte-for-byte `JSON.stringify(value, null, 2)`, so
265
+ * it stays trivially testable and pipe-safe.
266
+ */
267
+ declare const ANSI: {
268
+ reset: string;
269
+ dim: string;
270
+ green: string;
271
+ red: string;
272
+ yellow: string;
273
+ cyan: string;
274
+ magenta: string;
275
+ blue: string;
276
+ };
277
+ /** Human-readable byte size: `950 B`, `1.2 KB`, `3.4 MB`. */
278
+ declare function humanSize(bytes: number): string;
279
+ /** The ANSI colour name appropriate for a status code (green/cyan/yellow/red). */
280
+ declare function statusColor(status: number): keyof typeof ANSI;
281
+ /**
282
+ * Pretty-print a JSON value. When `color` is false the output equals
283
+ * `JSON.stringify(value, null, 2)`; when true, keys/strings/numbers/booleans are
284
+ * syntax-highlighted with ANSI colours.
285
+ */
286
+ declare function prettyJson(value: unknown, color?: boolean): string;
287
+ /** True if the given content-type looks like JSON. */
288
+ declare function isJsonContentType(ct: string | undefined): boolean;
289
+
290
+ export { type AssembleOptions, type AssertDirective, type AssertOp, type AssertResult, type Assertion, type CaptureDirective, type CurlOptions, type HttpFileRequest, type JsonPathSegment, type RequestRunResult, type RequestSpec, type ResolveResult, type ResponseRecord, type RunOptions, type RunResult, type SendOptions, type VarScope, assembleRequest, captureValue, evalAssertion, evalPath, humanSize, isJsonContentType, makeScope, parseAssertion, parseDotenv, parseEnvJson, parseHttpFile, parseJsonPath, parseKvPairs, prettyJson, resolveLhs, resolveVars, runAssertion, runHttpFile, sendRequest, statusColor, toCurl };
package/dist/lib.d.ts ADDED
@@ -0,0 +1,290 @@
1
+ /**
2
+ * A tiny, hand-written JSON-path evaluator used for response capture and
3
+ * assertions. It understands a deliberately small, predictable dialect — no
4
+ * `eval`, no regex-of-doom, no wildcards:
5
+ *
6
+ * $ the root value
7
+ * $.data.items object keys via dots
8
+ * data.items a leading `$` is optional
9
+ * $.items[0].id array indices via brackets
10
+ * $.items[-1] negative indices count from the end
11
+ * $['odd key'].x bracketed / quoted keys (dots, spaces, etc.)
12
+ *
13
+ * Missing paths resolve to `undefined` rather than throwing, so an assertion
14
+ * like `body.$.error exists` can be tested cleanly.
15
+ */
16
+ /** One resolved step of a JSON path. */
17
+ type JsonPathSegment = {
18
+ type: "key";
19
+ key: string;
20
+ } | {
21
+ type: "index";
22
+ index: number;
23
+ };
24
+ /** Parse a path string into an ordered list of segments. Throws on syntax errors. */
25
+ declare function parseJsonPath(path: string): JsonPathSegment[];
26
+ /**
27
+ * Resolve `path` against `root`. Returns the value at the path, or `undefined`
28
+ * if any step does not exist. `$` alone returns `root` itself.
29
+ */
30
+ declare function evalPath(root: unknown, path: string): unknown;
31
+
32
+ /** A flat name→value map used to resolve `{{var}}` references. */
33
+ type VarScope = Map<string, string>;
34
+ /** Build a scope from any number of plain objects (later objects win). */
35
+ declare function makeScope(...sources: Array<Record<string, string> | undefined>): VarScope;
36
+ /** Result of {@link resolveVars}: the substituted text plus any unresolved names. */
37
+ interface ResolveResult {
38
+ text: string;
39
+ missing: string[];
40
+ }
41
+ /**
42
+ * Replace every `{{name}}` in `text` with its value from `scope` (or a built-in
43
+ * system variable). Unknown references are left verbatim and reported in
44
+ * `missing`, so callers can decide whether that's fatal.
45
+ */
46
+ declare function resolveVars(text: string, scope: VarScope): ResolveResult;
47
+ /**
48
+ * Parse a REST-client `http-client.env.json` document and return the merged
49
+ * variables for `envName`. A top-level `$shared` block (if present) is merged
50
+ * first, then the named environment overrides it.
51
+ */
52
+ declare function parseEnvJson(json: string, envName: string): Record<string, string>;
53
+ /** Parse a `.env`-style document (KEY=VALUE lines, `#` comments, optional quotes). */
54
+ declare function parseDotenv(text: string): Record<string, string>;
55
+ /** Parse `k=v` CLI pairs (repeatable `--var`) into a plain object. */
56
+ declare function parseKvPairs(pairs: string[]): Record<string, string>;
57
+
58
+ /**
59
+ * A hand-written parser for the well-known `.http` / `.rest` file format (the
60
+ * one VS Code's REST Client and JetBrains HTTP Client use). Requests are
61
+ * separated by `###`, may carry a `# @name` tag, and can declare `# @capture`
62
+ * and `# @assert` directives that turn a file into a runnable API test suite.
63
+ *
64
+ * The parser is intentionally forgiving and does no network work — it only
65
+ * turns text into structured {@link HttpFileRequest} objects.
66
+ */
67
+ /** A `# @capture <name> = <source>` directive. `source` is an assertion LHS. */
68
+ interface CaptureDirective {
69
+ name: string;
70
+ source: string;
71
+ }
72
+ /** A `# @assert <expr>` directive. `expr` is parsed later by the assert engine. */
73
+ interface AssertDirective {
74
+ expr: string;
75
+ }
76
+ /** One request block parsed out of a `.http` file. */
77
+ interface HttpFileRequest {
78
+ /** `# @name <id>` if present. */
79
+ name?: string;
80
+ method: string;
81
+ url: string;
82
+ /** Header pairs in source order (values may still contain `{{vars}}`). */
83
+ headers: Array<[string, string]>;
84
+ /** Raw request body (may contain `{{vars}}`), or undefined if none. */
85
+ body?: string;
86
+ captures: CaptureDirective[];
87
+ assertions: AssertDirective[];
88
+ /** 1-based line number of the request line, for diagnostics. */
89
+ line: number;
90
+ }
91
+ /**
92
+ * Parse a whole `.http` document into an ordered list of requests. Directive
93
+ * comments (`# @name`, `# @capture`, `# @assert`) are extracted; plain comments
94
+ * are ignored.
95
+ */
96
+ declare function parseHttpFile(source: string): HttpFileRequest[];
97
+
98
+ /**
99
+ * The request engine: assemble a {@link RequestSpec} from friendly options,
100
+ * send it with the global `fetch` (with manual redirect handling, a timeout, a
101
+ * response-size cap and precise timing), and render the equivalent `curl`
102
+ * command. The `fetch` implementation is injectable so tests never touch the
103
+ * network.
104
+ */
105
+ /** A concrete, ready-to-send HTTP request. */
106
+ interface RequestSpec {
107
+ method: string;
108
+ url: string;
109
+ /** Header pairs in order. */
110
+ headers: Array<[string, string]>;
111
+ body?: string;
112
+ }
113
+ /** Friendly inputs used to build a {@link RequestSpec}. */
114
+ interface AssembleOptions {
115
+ method?: string;
116
+ /** Raw `"Key: Value"` header strings (repeatable `-H`). */
117
+ headers?: string[];
118
+ /** `"k=v"` query params (repeatable `-q`). */
119
+ query?: string[];
120
+ /** Raw request body (`-d`). */
121
+ data?: string;
122
+ /** A raw JSON object/array string (`--json '{...}'`). */
123
+ json?: string;
124
+ /** `"k=v"` (string) or `"k:=v"` (raw JSON) JSON-body shorthands (`-j`). */
125
+ jsonKv?: string[];
126
+ /** `"k=v"` urlencoded form fields (`--form`). */
127
+ form?: string[];
128
+ /** Bearer token → `Authorization: Bearer <token>` (`-b`). */
129
+ bearer?: string;
130
+ /** `"user:pass"` → HTTP Basic `Authorization` header (`-u`). */
131
+ user?: string;
132
+ }
133
+ /** Assemble a concrete request from friendly options. Pure — no I/O. */
134
+ declare function assembleRequest(url: string, o?: AssembleOptions): RequestSpec;
135
+ /** Options controlling how a request is sent. */
136
+ interface SendOptions {
137
+ /** Abort after this many ms (default 30000). */
138
+ timeoutMs?: number;
139
+ /** Cap the response body read at this many bytes (default 10MB). */
140
+ maxSize?: number;
141
+ /** Follow up to this many redirects (default 5). */
142
+ maxRedirects?: number;
143
+ /** Whether to follow redirects at all (default true). */
144
+ followRedirects?: boolean;
145
+ /** Inject a `fetch` implementation (defaults to the global). */
146
+ fetchImpl?: typeof fetch;
147
+ }
148
+ /** A structured, serialisable record of an HTTP response. */
149
+ interface ResponseRecord {
150
+ status: number;
151
+ statusText: string;
152
+ /** Lower-cased header name → value. */
153
+ headers: Record<string, string>;
154
+ /** Total wall-clock time for the request (ms), including redirects. */
155
+ timeMs: number;
156
+ /** Bytes of body actually read (after any cap). */
157
+ size: number;
158
+ /** Response body as text (possibly truncated to `maxSize`). */
159
+ body: string;
160
+ /** Parsed JSON body, if the response looked like JSON. */
161
+ json?: unknown;
162
+ /** Final URL after any redirects. */
163
+ url: string;
164
+ /** Whether any redirect was followed. */
165
+ redirected: boolean;
166
+ /** The chain of URLs visited before the final one. */
167
+ redirectChain: string[];
168
+ ok: boolean;
169
+ /** True if the body was cut off at `maxSize`. */
170
+ truncated: boolean;
171
+ /** True if a followed redirect crossed to a different host. */
172
+ crossHostRedirect: boolean;
173
+ }
174
+ /**
175
+ * Send a {@link RequestSpec}. Redirects are followed manually so the hop count
176
+ * is enforced (`maxRedirects`) and cross-host hops are recorded rather than
177
+ * followed silently. Times out after `timeoutMs`; the body is read up to
178
+ * `maxSize` bytes.
179
+ */
180
+ declare function sendRequest(spec: RequestSpec, opts?: SendOptions): Promise<ResponseRecord>;
181
+ /** Options for {@link toCurl}. */
182
+ interface CurlOptions {
183
+ /** Show real credential values instead of masking them (default false). */
184
+ showSecrets?: boolean;
185
+ maxRedirects?: number;
186
+ followRedirects?: boolean;
187
+ }
188
+ /**
189
+ * Render the equivalent `curl` command for a request. Credentials in an
190
+ * `Authorization` header are masked (`Bearer ***` / `Basic ***`) unless
191
+ * `showSecrets` is set.
192
+ */
193
+ declare function toCurl(spec: RequestSpec, opts?: CurlOptions): string;
194
+
195
+ /** The comparison operators an assertion may use. */
196
+ type AssertOp = "==" | "!=" | "<" | "<=" | ">" | ">=" | "contains" | "matches" | "exists" | "empty";
197
+ /** A parsed assertion: an LHS, an operator, and (for binary ops) an RHS. */
198
+ interface Assertion {
199
+ lhs: string;
200
+ op: AssertOp;
201
+ rhs?: string;
202
+ raw: string;
203
+ }
204
+ /** Parse an assertion expression like `body.$.ok == true`. Throws on malformed input. */
205
+ declare function parseAssertion(expr: string): Assertion;
206
+ /** Resolve an LHS expression to a concrete value from the response. */
207
+ declare function resolveLhs(lhs: string, rec: ResponseRecord): unknown;
208
+ /** The outcome of evaluating one assertion. */
209
+ interface AssertResult {
210
+ ok: boolean;
211
+ assertion: Assertion;
212
+ actual: unknown;
213
+ expected?: unknown;
214
+ message: string;
215
+ }
216
+ /** Evaluate a parsed assertion against a response. */
217
+ declare function evalAssertion(assertion: Assertion, rec: ResponseRecord): AssertResult;
218
+ /** Parse + evaluate in one step. */
219
+ declare function runAssertion(expr: string, rec: ResponseRecord): AssertResult;
220
+ /** Resolve a capture source (same grammar as an LHS) to a string value. */
221
+ declare function captureValue(source: string, rec: ResponseRecord): string | undefined;
222
+
223
+ /** Options for {@link runHttpFile}. */
224
+ interface RunOptions extends SendOptions {
225
+ /** Variables from an env block (`http-client.env.json` / `.env`). */
226
+ env?: Record<string, string>;
227
+ /** CLI `--var k=v` overrides (highest precedence at start). */
228
+ vars?: Record<string, string>;
229
+ /** Run only the request whose `# @name` matches this. */
230
+ name?: string;
231
+ /** Called after each request completes (for streaming CLI output). */
232
+ onResult?: (result: RequestRunResult) => void;
233
+ }
234
+ /** The result of running one request from the file. */
235
+ interface RequestRunResult {
236
+ name?: string;
237
+ method: string;
238
+ url: string;
239
+ line: number;
240
+ /** Unresolved `{{vars}}` encountered while building the request. */
241
+ missingVars: string[];
242
+ /** Set when the request could not be sent at all. */
243
+ error?: string;
244
+ response?: ResponseRecord;
245
+ assertions: AssertResult[];
246
+ /** Values captured from this response (name → value). */
247
+ captured: Record<string, string>;
248
+ /** True if it was sent, all assertions passed and no error occurred. */
249
+ ok: boolean;
250
+ }
251
+ /** The overall result of a run. */
252
+ interface RunResult {
253
+ results: RequestRunResult[];
254
+ passed: number;
255
+ failed: number;
256
+ ok: boolean;
257
+ }
258
+ /** Parse and run a `.http` document. */
259
+ declare function runHttpFile(source: string, opts?: RunOptions): Promise<RunResult>;
260
+
261
+ /**
262
+ * Presentation helpers: a byte-size formatter, a status-code colour picker, and
263
+ * a JSON pretty-printer with optional ANSI syntax highlighting. With `color`
264
+ * off, {@link prettyJson} is byte-for-byte `JSON.stringify(value, null, 2)`, so
265
+ * it stays trivially testable and pipe-safe.
266
+ */
267
+ declare const ANSI: {
268
+ reset: string;
269
+ dim: string;
270
+ green: string;
271
+ red: string;
272
+ yellow: string;
273
+ cyan: string;
274
+ magenta: string;
275
+ blue: string;
276
+ };
277
+ /** Human-readable byte size: `950 B`, `1.2 KB`, `3.4 MB`. */
278
+ declare function humanSize(bytes: number): string;
279
+ /** The ANSI colour name appropriate for a status code (green/cyan/yellow/red). */
280
+ declare function statusColor(status: number): keyof typeof ANSI;
281
+ /**
282
+ * Pretty-print a JSON value. When `color` is false the output equals
283
+ * `JSON.stringify(value, null, 2)`; when true, keys/strings/numbers/booleans are
284
+ * syntax-highlighted with ANSI colours.
285
+ */
286
+ declare function prettyJson(value: unknown, color?: boolean): string;
287
+ /** True if the given content-type looks like JSON. */
288
+ declare function isJsonContentType(ct: string | undefined): boolean;
289
+
290
+ export { type AssembleOptions, type AssertDirective, type AssertOp, type AssertResult, type Assertion, type CaptureDirective, type CurlOptions, type HttpFileRequest, type JsonPathSegment, type RequestRunResult, type RequestSpec, type ResolveResult, type ResponseRecord, type RunOptions, type RunResult, type SendOptions, type VarScope, assembleRequest, captureValue, evalAssertion, evalPath, humanSize, isJsonContentType, makeScope, parseAssertion, parseDotenv, parseEnvJson, parseHttpFile, parseJsonPath, parseKvPairs, prettyJson, resolveLhs, resolveVars, runAssertion, runHttpFile, sendRequest, statusColor, toCurl };