@typia/interface 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310
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/lib/http/IHttpLlmController.d.ts +5 -5
- package/lib/schema/IJsonParseResult.d.ts +1 -3
- package/lib/schema/ILlmApplication.d.ts +1 -1
- package/lib/schema/ILlmController.d.ts +2 -5
- package/lib/schema/ILlmFunction.d.ts +35 -9
- package/package.json +1 -1
- package/src/http/IHttpConnection.ts +200 -200
- package/src/http/IHttpLlmApplication.ts +72 -72
- package/src/http/IHttpLlmController.ts +96 -96
- package/src/http/IHttpLlmFunction.ts +34 -34
- package/src/http/IHttpMigrateApplication.ts +48 -48
- package/src/http/IHttpMigrateRoute.ts +165 -165
- package/src/http/IHttpResponse.ts +42 -42
- package/src/http/index.ts +7 -7
- package/src/index.ts +9 -9
- package/src/metadata/IJsDocTagInfo.ts +25 -25
- package/src/metadata/IMetadataComponents.ts +24 -24
- package/src/metadata/IMetadataSchema.ts +293 -293
- package/src/metadata/IMetadataSchemaCollection.ts +20 -20
- package/src/metadata/IMetadataSchemaUnit.ts +20 -20
- package/src/metadata/IMetadataTypeTag.ts +39 -39
- package/src/metadata/index.ts +6 -6
- package/src/openapi/OpenApi.ts +643 -643
- package/src/openapi/OpenApiV3.ts +655 -655
- package/src/openapi/OpenApiV3_1.ts +735 -735
- package/src/openapi/SwaggerV2.ts +559 -559
- package/src/openapi/index.ts +4 -4
- package/src/protobuf/ProtobufWire.ts +51 -51
- package/src/protobuf/index.ts +1 -1
- package/src/schema/IJsonParseResult.ts +134 -136
- package/src/schema/IJsonSchemaApplication.ts +274 -274
- package/src/schema/IJsonSchemaAttribute.ts +158 -158
- package/src/schema/IJsonSchemaCollection.ts +123 -123
- package/src/schema/IJsonSchemaTransformError.ts +86 -86
- package/src/schema/IJsonSchemaUnit.ts +120 -120
- package/src/schema/ILlmApplication.ts +99 -99
- package/src/schema/ILlmController.ts +54 -57
- package/src/schema/ILlmFunction.ts +145 -118
- package/src/schema/ILlmSchema.ts +484 -484
- package/src/schema/IResult.ts +84 -84
- package/src/schema/IValidation.ts +134 -134
- package/src/schema/index.ts +14 -14
- package/src/tags/Constant.ts +49 -49
- package/src/tags/ContentMediaType.ts +40 -40
- package/src/tags/Default.ts +50 -50
- package/src/tags/Example.ts +48 -48
- package/src/tags/Examples.ts +50 -50
- package/src/tags/ExclusiveMaximum.ts +46 -46
- package/src/tags/ExclusiveMinimum.ts +46 -46
- package/src/tags/Format.ts +76 -76
- package/src/tags/JsonSchemaPlugin.ts +45 -45
- package/src/tags/MaxItems.ts +39 -39
- package/src/tags/MaxLength.ts +37 -37
- package/src/tags/Maximum.ts +44 -44
- package/src/tags/MinItems.ts +39 -39
- package/src/tags/MinLength.ts +37 -37
- package/src/tags/Minimum.ts +44 -44
- package/src/tags/MultipleOf.ts +54 -54
- package/src/tags/Pattern.ts +59 -59
- package/src/tags/Sequence.ts +43 -43
- package/src/tags/TagBase.ts +131 -131
- package/src/tags/Type.ts +70 -70
- package/src/tags/UniqueItems.ts +44 -44
- package/src/tags/index.ts +21 -21
- package/src/typings/AssertionGuard.ts +12 -12
- package/src/typings/Atomic.ts +21 -21
- package/src/typings/CamelCase.ts +75 -75
- package/src/typings/ClassProperties.ts +15 -15
- package/src/typings/DeepPartial.ts +39 -39
- package/src/typings/OmitNever.ts +12 -12
- package/src/typings/PascalCase.ts +71 -71
- package/src/typings/Primitive.ts +71 -71
- package/src/typings/ProtobufAtomic.ts +30 -30
- package/src/typings/Resolved.ts +58 -58
- package/src/typings/SnakeCase.ts +126 -126
- package/src/typings/SpecialFields.ts +13 -13
- package/src/typings/ValidationPipe.ts +20 -20
- package/src/typings/index.ts +14 -14
- package/src/typings/internal/Equal.ts +14 -14
- package/src/typings/internal/IsTuple.ts +17 -17
- package/src/typings/internal/NativeClass.ts +31 -31
- package/src/typings/internal/ValueOf.ts +29 -29
- package/src/utils/IRandomGenerator.ts +105 -105
- package/src/utils/IReadableURLSearchParams.ts +25 -25
- package/src/utils/index.ts +2 -2
|
@@ -7,16 +7,16 @@ import { IHttpResponse } from "./IHttpResponse";
|
|
|
7
7
|
*
|
|
8
8
|
* `IHttpLlmController` is a controller for registering OpenAPI operations as
|
|
9
9
|
* LLM function calling tools. It contains {@link IHttpLlmApplication} with
|
|
10
|
-
* {@link IHttpLlmFunction function calling schemas}, {@link name identifier},
|
|
11
|
-
*
|
|
10
|
+
* {@link IHttpLlmFunction function calling schemas}, {@link name identifier}, and
|
|
11
|
+
* {@link connection} to the API server.
|
|
12
12
|
*
|
|
13
|
-
* You can create this controller with {@link HttpLlm.controller} function,
|
|
14
|
-
*
|
|
13
|
+
* You can create this controller with {@link HttpLlm.controller} function, and
|
|
14
|
+
* register it to MCP server with {@link registerMcpControllers}:
|
|
15
15
|
*
|
|
16
16
|
* ```typescript
|
|
17
17
|
* import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
-
* import { HttpLlm } from "@typia/utils";
|
|
19
18
|
* import { registerMcpControllers } from "@typia/mcp";
|
|
19
|
+
* import { HttpLlm } from "@typia/utils";
|
|
20
20
|
*
|
|
21
21
|
* const server = new McpServer({ name: "my-server", version: "1.0.0" });
|
|
22
22
|
* registerMcpControllers({
|
|
@@ -78,9 +78,7 @@ export declare namespace IJsonParseResult {
|
|
|
78
78
|
*/
|
|
79
79
|
errors: IError[];
|
|
80
80
|
}
|
|
81
|
-
/**
|
|
82
|
-
* Detailed information about a parsing error.
|
|
83
|
-
*/
|
|
81
|
+
/** Detailed information about a parsing error. */
|
|
84
82
|
interface IError {
|
|
85
83
|
/**
|
|
86
84
|
* Property path to the error location.
|
|
@@ -83,6 +83,6 @@ export declare namespace ILlmApplication {
|
|
|
83
83
|
* @ignore
|
|
84
84
|
*/
|
|
85
85
|
interface __IPrimitive<Class extends object = any> extends Omit<ILlmApplication<Class>, "config" | "functions"> {
|
|
86
|
-
functions: Omit<ILlmFunction, "parse">[];
|
|
86
|
+
functions: Omit<ILlmFunction, "parse" | "coerce">[];
|
|
87
87
|
}
|
|
88
88
|
}
|
|
@@ -12,8 +12,8 @@ import { ILlmApplication } from "./ILlmApplication";
|
|
|
12
12
|
*
|
|
13
13
|
* ```typescript
|
|
14
14
|
* import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
15
|
-
* import typia from "typia";
|
|
16
15
|
* import { registerMcpControllers } from "@typia/mcp";
|
|
16
|
+
* import typia from "typia";
|
|
17
17
|
*
|
|
18
18
|
* class Calculator {
|
|
19
19
|
* add(input: { a: number; b: number }): number {
|
|
@@ -28,10 +28,7 @@ import { ILlmApplication } from "./ILlmApplication";
|
|
|
28
28
|
* registerMcpControllers({
|
|
29
29
|
* server,
|
|
30
30
|
* controllers: [
|
|
31
|
-
* typia.llm.controller<Calculator>(
|
|
32
|
-
* "calculator",
|
|
33
|
-
* new Calculator(),
|
|
34
|
-
* ),
|
|
31
|
+
* typia.llm.controller<Calculator>("calculator", new Calculator()),
|
|
35
32
|
* ],
|
|
36
33
|
* });
|
|
37
34
|
* ```
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { tags } from "..";
|
|
1
2
|
import { IJsonParseResult } from "./IJsonParseResult";
|
|
2
3
|
import { ILlmSchema } from "./ILlmSchema";
|
|
3
4
|
import { IValidation } from "./IValidation";
|
|
@@ -20,11 +21,11 @@ export interface ILlmFunction {
|
|
|
20
21
|
* Function name for LLM invocation.
|
|
21
22
|
*
|
|
22
23
|
* The identifier used by the LLM to call this function. Must be unique within
|
|
23
|
-
* the application.
|
|
24
|
+
* the application.
|
|
24
25
|
*
|
|
25
|
-
*
|
|
26
|
+
* OpenAI limits function names to 64 characters.
|
|
26
27
|
*/
|
|
27
|
-
name: string
|
|
28
|
+
name: string & tags.MaxLength<64>;
|
|
28
29
|
/**
|
|
29
30
|
* Schema for function parameters.
|
|
30
31
|
*
|
|
@@ -83,13 +84,38 @@ export interface ILlmFunction {
|
|
|
83
84
|
* Type validation is NOT performed — use {@link validate} after parsing.
|
|
84
85
|
*
|
|
85
86
|
* If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
|
|
86
|
-
* and provides a pre-parsed object, use
|
|
87
|
-
*
|
|
87
|
+
* and provides a pre-parsed object, use {@link coerce} instead to apply
|
|
88
|
+
* schema-based type coercion without re-parsing.
|
|
88
89
|
*
|
|
89
90
|
* @param str Raw JSON string from LLM output
|
|
90
91
|
* @returns Parse result with data on success, or partial data with errors
|
|
91
92
|
*/
|
|
92
93
|
parse: (str: string) => IJsonParseResult<unknown>;
|
|
94
|
+
/**
|
|
95
|
+
* Coerce pre-parsed arguments to match expected schema types.
|
|
96
|
+
*
|
|
97
|
+
* **Use this only when the SDK (e.g., LangChain, Vercel AI, MCP) already
|
|
98
|
+
* parses JSON internally.** For raw JSON strings from LLM output, use
|
|
99
|
+
* {@link parse} instead — it handles both lenient parsing and type coercion in
|
|
100
|
+
* one step.
|
|
101
|
+
*
|
|
102
|
+
* LLMs often return values with incorrect types even after parsing:
|
|
103
|
+
*
|
|
104
|
+
* - `"42"` → `42` (when schema expects number)
|
|
105
|
+
* - `"true"` → `true` (when schema expects boolean)
|
|
106
|
+
* - `"null"` → `null` (when schema expects null)
|
|
107
|
+
* - `"{...}"` → `{...}` (when schema expects object)
|
|
108
|
+
* - `"[...]"` → `[...]` (when schema expects array)
|
|
109
|
+
*
|
|
110
|
+
* This function recursively coerces these double-stringified values based on
|
|
111
|
+
* the {@link parameters} schema.
|
|
112
|
+
*
|
|
113
|
+
* Type validation is NOT performed — use {@link validate} after coercion.
|
|
114
|
+
*
|
|
115
|
+
* @param data Pre-parsed arguments object from SDK
|
|
116
|
+
* @returns Coerced arguments with corrected types
|
|
117
|
+
*/
|
|
118
|
+
coerce: (data: unknown) => unknown;
|
|
93
119
|
/**
|
|
94
120
|
* Validates LLM-generated arguments against the schema.
|
|
95
121
|
*
|
|
@@ -97,10 +123,10 @@ export interface ILlmFunction {
|
|
|
97
123
|
* numbers or missing required properties. Use this validator to check
|
|
98
124
|
* arguments before execution.
|
|
99
125
|
*
|
|
100
|
-
* When validation fails, use `
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
*
|
|
126
|
+
* When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
|
|
127
|
+
* format the error for LLM feedback. The formatted output shows the invalid
|
|
128
|
+
* JSON with inline error comments, helping the LLM understand and correct its
|
|
129
|
+
* mistakes in the next turn.
|
|
104
130
|
*
|
|
105
131
|
* @param args The arguments generated by the LLM
|
|
106
132
|
* @returns Validation result with success status and any errors
|
package/package.json
CHANGED
|
@@ -1,200 +1,200 @@
|
|
|
1
|
-
/// <reference lib="dom" />
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* HTTP connection configuration for remote server communication.
|
|
5
|
-
*
|
|
6
|
-
* `IHttpConnection` defines connection settings required to communicate with
|
|
7
|
-
* remote HTTP servers. This interface is primarily used by `@nestia/fetcher`
|
|
8
|
-
* and generated SDK functions to establish HTTP connections.
|
|
9
|
-
*
|
|
10
|
-
* The {@link host} property specifies the base URL of the target server, while
|
|
11
|
-
* {@link headers} allows passing custom HTTP headers with each request. For
|
|
12
|
-
* fine-grained control over fetch behavior, use {@link options} to configure
|
|
13
|
-
* caching, CORS, credentials, and other fetch API settings.
|
|
14
|
-
*
|
|
15
|
-
* In Node.js versions prior to 20 (which lack native fetch), provide a polyfill
|
|
16
|
-
* like `node-fetch` via the {@link fetch} property.
|
|
17
|
-
*
|
|
18
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
-
* @author Seungjun We - https://github.com/SeungjunWe
|
|
20
|
-
*/
|
|
21
|
-
export interface IHttpConnection {
|
|
22
|
-
/**
|
|
23
|
-
* Base URL of the remote HTTP server.
|
|
24
|
-
*
|
|
25
|
-
* Must include protocol (http:// or https://) and may include port. Example:
|
|
26
|
-
* `"https://api.example.com"` or `"http://localhost:3000"`.
|
|
27
|
-
*/
|
|
28
|
-
host: string;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Custom HTTP headers to send with every request.
|
|
32
|
-
*
|
|
33
|
-
* Common use cases include authentication tokens, API keys, and content
|
|
34
|
-
* negotiation headers. Values can be primitives or arrays.
|
|
35
|
-
*/
|
|
36
|
-
headers?: Record<string, IHttpConnection.HeaderValue>;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Additional fetch API options.
|
|
40
|
-
*
|
|
41
|
-
* Configure caching, CORS mode, credentials handling, and other
|
|
42
|
-
* fetch-specific behaviors. These options are passed directly to the
|
|
43
|
-
* underlying fetch call.
|
|
44
|
-
*/
|
|
45
|
-
options?: IHttpConnection.IOptions;
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Custom fetch function implementation.
|
|
49
|
-
*
|
|
50
|
-
* For Node.js versions before 20 that lack native fetch support, provide a
|
|
51
|
-
* polyfill such as `node-fetch`. This allows the same connection
|
|
52
|
-
* configuration to work across all Node.js versions.
|
|
53
|
-
*
|
|
54
|
-
* @example
|
|
55
|
-
* import fetch from "node-fetch";
|
|
56
|
-
*
|
|
57
|
-
* const connection: IHttpConnection = {
|
|
58
|
-
* host: "https://api.example.com",
|
|
59
|
-
* fetch: fetch as any,
|
|
60
|
-
* };
|
|
61
|
-
*/
|
|
62
|
-
fetch?: typeof fetch;
|
|
63
|
-
}
|
|
64
|
-
export namespace IHttpConnection {
|
|
65
|
-
/**
|
|
66
|
-
* Fetch API request options.
|
|
67
|
-
*
|
|
68
|
-
* Subset of the standard `RequestInit` interface, excluding properties that
|
|
69
|
-
* are managed internally (body, headers, method). These options control
|
|
70
|
-
* caching, CORS, credentials, and request lifecycle behavior.
|
|
71
|
-
*/
|
|
72
|
-
export interface IOptions {
|
|
73
|
-
/**
|
|
74
|
-
* Request cache mode.
|
|
75
|
-
*
|
|
76
|
-
* Controls how the request interacts with the browser's HTTP cache.
|
|
77
|
-
*
|
|
78
|
-
* - `"default"`: Standard browser caching behavior
|
|
79
|
-
* - `"no-store"`: Bypass cache completely, don't store response
|
|
80
|
-
* - `"reload"`: Bypass cache, but store response
|
|
81
|
-
* - `"no-cache"`: Validate with server before using cache
|
|
82
|
-
* - `"force-cache"`: Use cache even if stale
|
|
83
|
-
* - `"only-if-cached"`: Only use cache, fail if not cached
|
|
84
|
-
*/
|
|
85
|
-
cache?:
|
|
86
|
-
| "default"
|
|
87
|
-
| "force-cache"
|
|
88
|
-
| "no-cache"
|
|
89
|
-
| "no-store"
|
|
90
|
-
| "only-if-cached"
|
|
91
|
-
| "reload";
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Credentials inclusion mode.
|
|
95
|
-
*
|
|
96
|
-
* Controls whether cookies and HTTP authentication are sent.
|
|
97
|
-
*
|
|
98
|
-
* - `"omit"`: Never send credentials
|
|
99
|
-
* - `"same-origin"`: Send credentials only for same-origin requests
|
|
100
|
-
* - `"include"`: Always send credentials, even cross-origin
|
|
101
|
-
*/
|
|
102
|
-
credentials?: "omit" | "same-origin" | "include";
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Subresource integrity hash for verification.
|
|
106
|
-
*
|
|
107
|
-
* A cryptographic hash (e.g., `"sha256-abc123..."`) to verify the fetched
|
|
108
|
-
* resource hasn't been tampered with. The browser will reject responses
|
|
109
|
-
* that don't match the expected hash.
|
|
110
|
-
*/
|
|
111
|
-
integrity?: string;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Whether to keep the connection alive after page unload.
|
|
115
|
-
*
|
|
116
|
-
* When `true`, the request can outlive the page that initiated it. Useful
|
|
117
|
-
* for analytics or logging requests that should complete even if the user
|
|
118
|
-
* navigates away.
|
|
119
|
-
*/
|
|
120
|
-
keepalive?: boolean;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* CORS (Cross-Origin Resource Sharing) mode.
|
|
124
|
-
*
|
|
125
|
-
* Controls cross-origin request behavior.
|
|
126
|
-
*
|
|
127
|
-
* - `"cors"`: Standard CORS request (requires server support)
|
|
128
|
-
* - `"no-cors"`: Limited cross-origin request (opaque response)
|
|
129
|
-
* - `"same-origin"`: Only allow same-origin requests
|
|
130
|
-
* - `"navigate"`: For navigation requests (used by browsers)
|
|
131
|
-
*/
|
|
132
|
-
mode?: "cors" | "navigate" | "no-cors" | "same-origin";
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* HTTP redirect handling behavior.
|
|
136
|
-
*
|
|
137
|
-
* - `"follow"`: Automatically follow redirects (default)
|
|
138
|
-
* - `"error"`: Throw an error on redirect
|
|
139
|
-
* - `"manual"`: Return redirect response for manual handling
|
|
140
|
-
*/
|
|
141
|
-
redirect?: "error" | "follow" | "manual";
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* Referrer URL to send with the request.
|
|
145
|
-
*
|
|
146
|
-
* Overrides the default referrer. Use empty string to suppress the referrer
|
|
147
|
-
* header entirely.
|
|
148
|
-
*/
|
|
149
|
-
referrer?: string;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Policy for how much referrer information to include.
|
|
153
|
-
*
|
|
154
|
-
* Controls what referrer information is sent with requests. More
|
|
155
|
-
* restrictive policies improve privacy but may break some server-side
|
|
156
|
-
* analytics or security checks.
|
|
157
|
-
*/
|
|
158
|
-
referrerPolicy?:
|
|
159
|
-
| ""
|
|
160
|
-
| "no-referrer"
|
|
161
|
-
| "no-referrer-when-downgrade"
|
|
162
|
-
| "origin"
|
|
163
|
-
| "origin-when-cross-origin"
|
|
164
|
-
| "same-origin"
|
|
165
|
-
| "strict-origin"
|
|
166
|
-
| "strict-origin-when-cross-origin"
|
|
167
|
-
| "unsafe-url";
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* AbortSignal for request cancellation.
|
|
171
|
-
*
|
|
172
|
-
* Connect to an AbortController to enable cancellation of in-flight
|
|
173
|
-
* requests. When the signal is aborted, the fetch promise rejects with an
|
|
174
|
-
* AbortError.
|
|
175
|
-
*
|
|
176
|
-
* @example
|
|
177
|
-
* const controller = new AbortController();
|
|
178
|
-
* const options = { signal: controller.signal };
|
|
179
|
-
* // Later: controller.abort();
|
|
180
|
-
*/
|
|
181
|
-
signal?: AbortSignal | null;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Allowed types for HTTP header values.
|
|
186
|
-
*
|
|
187
|
-
* Supports primitive types (string, boolean, number, bigint) and arrays of
|
|
188
|
-
* primitives. Arrays are typically joined with commas when sent as HTTP
|
|
189
|
-
* headers.
|
|
190
|
-
*/
|
|
191
|
-
export type HeaderValue =
|
|
192
|
-
| string
|
|
193
|
-
| boolean
|
|
194
|
-
| number
|
|
195
|
-
| bigint
|
|
196
|
-
| Array<boolean>
|
|
197
|
-
| Array<number>
|
|
198
|
-
| Array<bigint>
|
|
199
|
-
| Array<string>;
|
|
200
|
-
}
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HTTP connection configuration for remote server communication.
|
|
5
|
+
*
|
|
6
|
+
* `IHttpConnection` defines connection settings required to communicate with
|
|
7
|
+
* remote HTTP servers. This interface is primarily used by `@nestia/fetcher`
|
|
8
|
+
* and generated SDK functions to establish HTTP connections.
|
|
9
|
+
*
|
|
10
|
+
* The {@link host} property specifies the base URL of the target server, while
|
|
11
|
+
* {@link headers} allows passing custom HTTP headers with each request. For
|
|
12
|
+
* fine-grained control over fetch behavior, use {@link options} to configure
|
|
13
|
+
* caching, CORS, credentials, and other fetch API settings.
|
|
14
|
+
*
|
|
15
|
+
* In Node.js versions prior to 20 (which lack native fetch), provide a polyfill
|
|
16
|
+
* like `node-fetch` via the {@link fetch} property.
|
|
17
|
+
*
|
|
18
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
19
|
+
* @author Seungjun We - https://github.com/SeungjunWe
|
|
20
|
+
*/
|
|
21
|
+
export interface IHttpConnection {
|
|
22
|
+
/**
|
|
23
|
+
* Base URL of the remote HTTP server.
|
|
24
|
+
*
|
|
25
|
+
* Must include protocol (http:// or https://) and may include port. Example:
|
|
26
|
+
* `"https://api.example.com"` or `"http://localhost:3000"`.
|
|
27
|
+
*/
|
|
28
|
+
host: string;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Custom HTTP headers to send with every request.
|
|
32
|
+
*
|
|
33
|
+
* Common use cases include authentication tokens, API keys, and content
|
|
34
|
+
* negotiation headers. Values can be primitives or arrays.
|
|
35
|
+
*/
|
|
36
|
+
headers?: Record<string, IHttpConnection.HeaderValue>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Additional fetch API options.
|
|
40
|
+
*
|
|
41
|
+
* Configure caching, CORS mode, credentials handling, and other
|
|
42
|
+
* fetch-specific behaviors. These options are passed directly to the
|
|
43
|
+
* underlying fetch call.
|
|
44
|
+
*/
|
|
45
|
+
options?: IHttpConnection.IOptions;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Custom fetch function implementation.
|
|
49
|
+
*
|
|
50
|
+
* For Node.js versions before 20 that lack native fetch support, provide a
|
|
51
|
+
* polyfill such as `node-fetch`. This allows the same connection
|
|
52
|
+
* configuration to work across all Node.js versions.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* import fetch from "node-fetch";
|
|
56
|
+
*
|
|
57
|
+
* const connection: IHttpConnection = {
|
|
58
|
+
* host: "https://api.example.com",
|
|
59
|
+
* fetch: fetch as any,
|
|
60
|
+
* };
|
|
61
|
+
*/
|
|
62
|
+
fetch?: typeof fetch;
|
|
63
|
+
}
|
|
64
|
+
export namespace IHttpConnection {
|
|
65
|
+
/**
|
|
66
|
+
* Fetch API request options.
|
|
67
|
+
*
|
|
68
|
+
* Subset of the standard `RequestInit` interface, excluding properties that
|
|
69
|
+
* are managed internally (body, headers, method). These options control
|
|
70
|
+
* caching, CORS, credentials, and request lifecycle behavior.
|
|
71
|
+
*/
|
|
72
|
+
export interface IOptions {
|
|
73
|
+
/**
|
|
74
|
+
* Request cache mode.
|
|
75
|
+
*
|
|
76
|
+
* Controls how the request interacts with the browser's HTTP cache.
|
|
77
|
+
*
|
|
78
|
+
* - `"default"`: Standard browser caching behavior
|
|
79
|
+
* - `"no-store"`: Bypass cache completely, don't store response
|
|
80
|
+
* - `"reload"`: Bypass cache, but store response
|
|
81
|
+
* - `"no-cache"`: Validate with server before using cache
|
|
82
|
+
* - `"force-cache"`: Use cache even if stale
|
|
83
|
+
* - `"only-if-cached"`: Only use cache, fail if not cached
|
|
84
|
+
*/
|
|
85
|
+
cache?:
|
|
86
|
+
| "default"
|
|
87
|
+
| "force-cache"
|
|
88
|
+
| "no-cache"
|
|
89
|
+
| "no-store"
|
|
90
|
+
| "only-if-cached"
|
|
91
|
+
| "reload";
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Credentials inclusion mode.
|
|
95
|
+
*
|
|
96
|
+
* Controls whether cookies and HTTP authentication are sent.
|
|
97
|
+
*
|
|
98
|
+
* - `"omit"`: Never send credentials
|
|
99
|
+
* - `"same-origin"`: Send credentials only for same-origin requests
|
|
100
|
+
* - `"include"`: Always send credentials, even cross-origin
|
|
101
|
+
*/
|
|
102
|
+
credentials?: "omit" | "same-origin" | "include";
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Subresource integrity hash for verification.
|
|
106
|
+
*
|
|
107
|
+
* A cryptographic hash (e.g., `"sha256-abc123..."`) to verify the fetched
|
|
108
|
+
* resource hasn't been tampered with. The browser will reject responses
|
|
109
|
+
* that don't match the expected hash.
|
|
110
|
+
*/
|
|
111
|
+
integrity?: string;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Whether to keep the connection alive after page unload.
|
|
115
|
+
*
|
|
116
|
+
* When `true`, the request can outlive the page that initiated it. Useful
|
|
117
|
+
* for analytics or logging requests that should complete even if the user
|
|
118
|
+
* navigates away.
|
|
119
|
+
*/
|
|
120
|
+
keepalive?: boolean;
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* CORS (Cross-Origin Resource Sharing) mode.
|
|
124
|
+
*
|
|
125
|
+
* Controls cross-origin request behavior.
|
|
126
|
+
*
|
|
127
|
+
* - `"cors"`: Standard CORS request (requires server support)
|
|
128
|
+
* - `"no-cors"`: Limited cross-origin request (opaque response)
|
|
129
|
+
* - `"same-origin"`: Only allow same-origin requests
|
|
130
|
+
* - `"navigate"`: For navigation requests (used by browsers)
|
|
131
|
+
*/
|
|
132
|
+
mode?: "cors" | "navigate" | "no-cors" | "same-origin";
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* HTTP redirect handling behavior.
|
|
136
|
+
*
|
|
137
|
+
* - `"follow"`: Automatically follow redirects (default)
|
|
138
|
+
* - `"error"`: Throw an error on redirect
|
|
139
|
+
* - `"manual"`: Return redirect response for manual handling
|
|
140
|
+
*/
|
|
141
|
+
redirect?: "error" | "follow" | "manual";
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Referrer URL to send with the request.
|
|
145
|
+
*
|
|
146
|
+
* Overrides the default referrer. Use empty string to suppress the referrer
|
|
147
|
+
* header entirely.
|
|
148
|
+
*/
|
|
149
|
+
referrer?: string;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Policy for how much referrer information to include.
|
|
153
|
+
*
|
|
154
|
+
* Controls what referrer information is sent with requests. More
|
|
155
|
+
* restrictive policies improve privacy but may break some server-side
|
|
156
|
+
* analytics or security checks.
|
|
157
|
+
*/
|
|
158
|
+
referrerPolicy?:
|
|
159
|
+
| ""
|
|
160
|
+
| "no-referrer"
|
|
161
|
+
| "no-referrer-when-downgrade"
|
|
162
|
+
| "origin"
|
|
163
|
+
| "origin-when-cross-origin"
|
|
164
|
+
| "same-origin"
|
|
165
|
+
| "strict-origin"
|
|
166
|
+
| "strict-origin-when-cross-origin"
|
|
167
|
+
| "unsafe-url";
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* AbortSignal for request cancellation.
|
|
171
|
+
*
|
|
172
|
+
* Connect to an AbortController to enable cancellation of in-flight
|
|
173
|
+
* requests. When the signal is aborted, the fetch promise rejects with an
|
|
174
|
+
* AbortError.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* const controller = new AbortController();
|
|
178
|
+
* const options = { signal: controller.signal };
|
|
179
|
+
* // Later: controller.abort();
|
|
180
|
+
*/
|
|
181
|
+
signal?: AbortSignal | null;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Allowed types for HTTP header values.
|
|
186
|
+
*
|
|
187
|
+
* Supports primitive types (string, boolean, number, bigint) and arrays of
|
|
188
|
+
* primitives. Arrays are typically joined with commas when sent as HTTP
|
|
189
|
+
* headers.
|
|
190
|
+
*/
|
|
191
|
+
export type HeaderValue =
|
|
192
|
+
| string
|
|
193
|
+
| boolean
|
|
194
|
+
| number
|
|
195
|
+
| bigint
|
|
196
|
+
| Array<boolean>
|
|
197
|
+
| Array<number>
|
|
198
|
+
| Array<bigint>
|
|
199
|
+
| Array<string>;
|
|
200
|
+
}
|