@typia/utils 12.0.0-dev.20260312-4 → 12.0.0-dev.20260313
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/internal/HttpLlmApplicationComposer.mjs +0 -4
- package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
- package/lib/utils/LlmJson.mjs +0 -1
- package/lib/utils/LlmJson.mjs.map +1 -1
- package/lib/utils/internal/parseLenientJson.js +40 -15
- package/lib/utils/internal/parseLenientJson.js.map +1 -1
- package/lib/utils/internal/parseLenientJson.mjs +40 -15
- package/lib/utils/internal/parseLenientJson.mjs.map +1 -1
- package/lib/validators/internal/OpenApiOneOfValidator.mjs +0 -4
- package/lib/validators/internal/OpenApiOneOfValidator.mjs.map +1 -1
- package/package.json +2 -2
- package/src/converters/LlmSchemaConverter.ts +617 -617
- package/src/http/HttpError.ts +114 -114
- package/src/http/HttpMigration.ts +94 -94
- package/src/http/internal/HttpLlmApplicationComposer.ts +360 -360
- package/src/utils/internal/parseLenientJson.ts +919 -894
package/src/http/HttpError.ts
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when HTTP request fails with non-2xx status.
|
|
3
|
-
*
|
|
4
|
-
* `HttpError` is thrown by {@link HttpLlm.execute} and
|
|
5
|
-
* {@link HttpMigration.execute} when the server returns a non-2xx status code.
|
|
6
|
-
* Contains the full HTTP context: method, path, status, headers, and response
|
|
7
|
-
* body.
|
|
8
|
-
*
|
|
9
|
-
* The response body is available via {@link message} (raw string) or
|
|
10
|
-
* {@link toJSON} (parsed JSON). For non-throwing behavior, use
|
|
11
|
-
* {@link HttpLlm.propagate} or {@link HttpMigration.propagate} instead.
|
|
12
|
-
*
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
*/
|
|
15
|
-
export class HttpError extends Error {
|
|
16
|
-
/** HTTP method used for the request. */
|
|
17
|
-
public readonly method:
|
|
18
|
-
| "GET"
|
|
19
|
-
| "QUERY"
|
|
20
|
-
| "DELETE"
|
|
21
|
-
| "POST"
|
|
22
|
-
| "PUT"
|
|
23
|
-
| "PATCH"
|
|
24
|
-
| "HEAD";
|
|
25
|
-
|
|
26
|
-
/** Request path or URL. */
|
|
27
|
-
public readonly path: string;
|
|
28
|
-
|
|
29
|
-
/** HTTP status code from server. */
|
|
30
|
-
public readonly status: number;
|
|
31
|
-
|
|
32
|
-
/** Response headers from server. */
|
|
33
|
-
public readonly headers: Record<string, string | string[]>;
|
|
34
|
-
|
|
35
|
-
/** @internal */
|
|
36
|
-
private body_: any = NOT_YET;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param method HTTP method
|
|
40
|
-
* @param path Request path or URL
|
|
41
|
-
* @param status HTTP status code
|
|
42
|
-
* @param headers Response headers
|
|
43
|
-
* @param message Error message (response body)
|
|
44
|
-
*/
|
|
45
|
-
public constructor(
|
|
46
|
-
method: "GET" | "QUERY" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD",
|
|
47
|
-
path: string,
|
|
48
|
-
status: number,
|
|
49
|
-
headers: Record<string, string | string[]>,
|
|
50
|
-
message: string,
|
|
51
|
-
) {
|
|
52
|
-
super(message);
|
|
53
|
-
this.method = method;
|
|
54
|
-
this.path = path;
|
|
55
|
-
this.status = status;
|
|
56
|
-
this.headers = headers;
|
|
57
|
-
|
|
58
|
-
// INHERITANCE POLYFILL
|
|
59
|
-
const proto: HttpError = new.target.prototype;
|
|
60
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
61
|
-
else (this as any).__proto__ = proto;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Serialize to JSON-compatible object.
|
|
66
|
-
*
|
|
67
|
-
* Lazily parses JSON message body on first call. If parsing fails, returns
|
|
68
|
-
* the original string.
|
|
69
|
-
*
|
|
70
|
-
* @template T Expected response body type
|
|
71
|
-
* @returns Structured HTTP error information
|
|
72
|
-
*/
|
|
73
|
-
public toJSON<T>(): HttpError.IProps<T> {
|
|
74
|
-
if (this.body_ === NOT_YET)
|
|
75
|
-
try {
|
|
76
|
-
this.body_ = JSON.parse(this.message);
|
|
77
|
-
} catch {
|
|
78
|
-
this.body_ = this.message;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
method: this.method,
|
|
82
|
-
path: this.path,
|
|
83
|
-
status: this.status,
|
|
84
|
-
headers: this.headers,
|
|
85
|
-
message: this.body_,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export namespace HttpError {
|
|
90
|
-
/**
|
|
91
|
-
* JSON representation of HttpError.
|
|
92
|
-
*
|
|
93
|
-
* @template T Response body type
|
|
94
|
-
*/
|
|
95
|
-
export interface IProps<T> {
|
|
96
|
-
/** HTTP method. */
|
|
97
|
-
method: "GET" | "QUERY" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
|
|
98
|
-
|
|
99
|
-
/** Request path or URL. */
|
|
100
|
-
path: string;
|
|
101
|
-
|
|
102
|
-
/** HTTP status code. */
|
|
103
|
-
status: number;
|
|
104
|
-
|
|
105
|
-
/** Response headers. */
|
|
106
|
-
headers: Record<string, string | string[]>;
|
|
107
|
-
|
|
108
|
-
/** Response body (parsed JSON or original string). */
|
|
109
|
-
message: T;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** @internal */
|
|
114
|
-
const NOT_YET = {} as any;
|
|
1
|
+
/**
|
|
2
|
+
* Error thrown when HTTP request fails with non-2xx status.
|
|
3
|
+
*
|
|
4
|
+
* `HttpError` is thrown by {@link HttpLlm.execute} and
|
|
5
|
+
* {@link HttpMigration.execute} when the server returns a non-2xx status code.
|
|
6
|
+
* Contains the full HTTP context: method, path, status, headers, and response
|
|
7
|
+
* body.
|
|
8
|
+
*
|
|
9
|
+
* The response body is available via {@link message} (raw string) or
|
|
10
|
+
* {@link toJSON} (parsed JSON). For non-throwing behavior, use
|
|
11
|
+
* {@link HttpLlm.propagate} or {@link HttpMigration.propagate} instead.
|
|
12
|
+
*
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export class HttpError extends Error {
|
|
16
|
+
/** HTTP method used for the request. */
|
|
17
|
+
public readonly method:
|
|
18
|
+
| "GET"
|
|
19
|
+
| "QUERY"
|
|
20
|
+
| "DELETE"
|
|
21
|
+
| "POST"
|
|
22
|
+
| "PUT"
|
|
23
|
+
| "PATCH"
|
|
24
|
+
| "HEAD";
|
|
25
|
+
|
|
26
|
+
/** Request path or URL. */
|
|
27
|
+
public readonly path: string;
|
|
28
|
+
|
|
29
|
+
/** HTTP status code from server. */
|
|
30
|
+
public readonly status: number;
|
|
31
|
+
|
|
32
|
+
/** Response headers from server. */
|
|
33
|
+
public readonly headers: Record<string, string | string[]>;
|
|
34
|
+
|
|
35
|
+
/** @internal */
|
|
36
|
+
private body_: any = NOT_YET;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param method HTTP method
|
|
40
|
+
* @param path Request path or URL
|
|
41
|
+
* @param status HTTP status code
|
|
42
|
+
* @param headers Response headers
|
|
43
|
+
* @param message Error message (response body)
|
|
44
|
+
*/
|
|
45
|
+
public constructor(
|
|
46
|
+
method: "GET" | "QUERY" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD",
|
|
47
|
+
path: string,
|
|
48
|
+
status: number,
|
|
49
|
+
headers: Record<string, string | string[]>,
|
|
50
|
+
message: string,
|
|
51
|
+
) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.method = method;
|
|
54
|
+
this.path = path;
|
|
55
|
+
this.status = status;
|
|
56
|
+
this.headers = headers;
|
|
57
|
+
|
|
58
|
+
// INHERITANCE POLYFILL
|
|
59
|
+
const proto: HttpError = new.target.prototype;
|
|
60
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
61
|
+
else (this as any).__proto__ = proto;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Serialize to JSON-compatible object.
|
|
66
|
+
*
|
|
67
|
+
* Lazily parses JSON message body on first call. If parsing fails, returns
|
|
68
|
+
* the original string.
|
|
69
|
+
*
|
|
70
|
+
* @template T Expected response body type
|
|
71
|
+
* @returns Structured HTTP error information
|
|
72
|
+
*/
|
|
73
|
+
public toJSON<T>(): HttpError.IProps<T> {
|
|
74
|
+
if (this.body_ === NOT_YET)
|
|
75
|
+
try {
|
|
76
|
+
this.body_ = JSON.parse(this.message);
|
|
77
|
+
} catch {
|
|
78
|
+
this.body_ = this.message;
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
method: this.method,
|
|
82
|
+
path: this.path,
|
|
83
|
+
status: this.status,
|
|
84
|
+
headers: this.headers,
|
|
85
|
+
message: this.body_,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export namespace HttpError {
|
|
90
|
+
/**
|
|
91
|
+
* JSON representation of HttpError.
|
|
92
|
+
*
|
|
93
|
+
* @template T Response body type
|
|
94
|
+
*/
|
|
95
|
+
export interface IProps<T> {
|
|
96
|
+
/** HTTP method. */
|
|
97
|
+
method: "GET" | "QUERY" | "DELETE" | "POST" | "PUT" | "PATCH" | "HEAD";
|
|
98
|
+
|
|
99
|
+
/** Request path or URL. */
|
|
100
|
+
path: string;
|
|
101
|
+
|
|
102
|
+
/** HTTP status code. */
|
|
103
|
+
status: number;
|
|
104
|
+
|
|
105
|
+
/** Response headers. */
|
|
106
|
+
headers: Record<string, string | string[]>;
|
|
107
|
+
|
|
108
|
+
/** Response body (parsed JSON or original string). */
|
|
109
|
+
message: T;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** @internal */
|
|
114
|
+
const NOT_YET = {} as any;
|
|
@@ -1,94 +1,94 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IHttpConnection,
|
|
3
|
-
IHttpMigrateApplication,
|
|
4
|
-
IHttpMigrateRoute,
|
|
5
|
-
IHttpResponse,
|
|
6
|
-
OpenApi,
|
|
7
|
-
OpenApiV3,
|
|
8
|
-
OpenApiV3_1,
|
|
9
|
-
OpenApiV3_2,
|
|
10
|
-
SwaggerV2,
|
|
11
|
-
} from "@typia/interface";
|
|
12
|
-
|
|
13
|
-
import { OpenApiConverter } from "../converters/OpenApiConverter";
|
|
14
|
-
import { HttpMigrateApplicationComposer } from "./internal/HttpMigrateApplicationComposer";
|
|
15
|
-
import { HttpMigrateRouteFetcher } from "./internal/HttpMigrateRouteFetcher";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* OpenAPI to HTTP migration utilities.
|
|
19
|
-
*
|
|
20
|
-
* `HttpMigration` converts OpenAPI documents into executable HTTP routes
|
|
21
|
-
* ({@link IHttpMigrateApplication}). Unlike {@link HttpLlm} which targets LLM
|
|
22
|
-
* function calling, this focuses on SDK/client code generation.
|
|
23
|
-
*
|
|
24
|
-
* Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0, 3.1) through
|
|
25
|
-
* automatic conversion to normalized {@link OpenApi} format.
|
|
26
|
-
*
|
|
27
|
-
* Main functions:
|
|
28
|
-
*
|
|
29
|
-
* - {@link application}: Convert OpenAPI document to
|
|
30
|
-
* {@link IHttpMigrateApplication}
|
|
31
|
-
* - {@link execute}: Call a route and return response body
|
|
32
|
-
* - {@link propagate}: Call a route and return full HTTP response (including
|
|
33
|
-
* non-2xx)
|
|
34
|
-
*
|
|
35
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
-
*/
|
|
37
|
-
export namespace HttpMigration {
|
|
38
|
-
/**
|
|
39
|
-
* Convert OpenAPI document to migration application.
|
|
40
|
-
*
|
|
41
|
-
* @param document OpenAPI document (any version)
|
|
42
|
-
* @returns Migration application with callable routes
|
|
43
|
-
*/
|
|
44
|
-
export const application = (
|
|
45
|
-
document:
|
|
46
|
-
| OpenApi.IDocument
|
|
47
|
-
| SwaggerV2.IDocument
|
|
48
|
-
| OpenApiV3.IDocument
|
|
49
|
-
| OpenApiV3_1.IDocument
|
|
50
|
-
| OpenApiV3_2.IDocument,
|
|
51
|
-
): IHttpMigrateApplication =>
|
|
52
|
-
HttpMigrateApplicationComposer.compose(
|
|
53
|
-
OpenApiConverter.upgradeDocument(document),
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Execute HTTP route.
|
|
58
|
-
*
|
|
59
|
-
* @param props Fetch properties
|
|
60
|
-
* @returns Response body
|
|
61
|
-
* @throws HttpError on non-2xx status
|
|
62
|
-
*/
|
|
63
|
-
export const execute = (props: IFetchProps): Promise<unknown> =>
|
|
64
|
-
HttpMigrateRouteFetcher.execute(props);
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Execute HTTP route and return full response.
|
|
68
|
-
*
|
|
69
|
-
* @param props Fetch properties
|
|
70
|
-
* @returns Full HTTP response including non-2xx
|
|
71
|
-
*/
|
|
72
|
-
export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
|
|
73
|
-
HttpMigrateRouteFetcher.propagate(props);
|
|
74
|
-
|
|
75
|
-
/** Properties for HTTP route execution. */
|
|
76
|
-
export interface IFetchProps {
|
|
77
|
-
/** HTTP connection info. */
|
|
78
|
-
connection: IHttpConnection;
|
|
79
|
-
|
|
80
|
-
/** Route to execute. */
|
|
81
|
-
route: IHttpMigrateRoute;
|
|
82
|
-
|
|
83
|
-
/** Path parameters. */
|
|
84
|
-
parameters:
|
|
85
|
-
| Array<string | number | boolean | bigint | null>
|
|
86
|
-
| Record<string, string | number | boolean | bigint | null>;
|
|
87
|
-
|
|
88
|
-
/** Query parameters. */
|
|
89
|
-
query?: object | undefined;
|
|
90
|
-
|
|
91
|
-
/** Request body. */
|
|
92
|
-
body?: object | undefined;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
IHttpConnection,
|
|
3
|
+
IHttpMigrateApplication,
|
|
4
|
+
IHttpMigrateRoute,
|
|
5
|
+
IHttpResponse,
|
|
6
|
+
OpenApi,
|
|
7
|
+
OpenApiV3,
|
|
8
|
+
OpenApiV3_1,
|
|
9
|
+
OpenApiV3_2,
|
|
10
|
+
SwaggerV2,
|
|
11
|
+
} from "@typia/interface";
|
|
12
|
+
|
|
13
|
+
import { OpenApiConverter } from "../converters/OpenApiConverter";
|
|
14
|
+
import { HttpMigrateApplicationComposer } from "./internal/HttpMigrateApplicationComposer";
|
|
15
|
+
import { HttpMigrateRouteFetcher } from "./internal/HttpMigrateRouteFetcher";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* OpenAPI to HTTP migration utilities.
|
|
19
|
+
*
|
|
20
|
+
* `HttpMigration` converts OpenAPI documents into executable HTTP routes
|
|
21
|
+
* ({@link IHttpMigrateApplication}). Unlike {@link HttpLlm} which targets LLM
|
|
22
|
+
* function calling, this focuses on SDK/client code generation.
|
|
23
|
+
*
|
|
24
|
+
* Supports all OpenAPI versions (Swagger 2.0, OpenAPI 3.0, 3.1) through
|
|
25
|
+
* automatic conversion to normalized {@link OpenApi} format.
|
|
26
|
+
*
|
|
27
|
+
* Main functions:
|
|
28
|
+
*
|
|
29
|
+
* - {@link application}: Convert OpenAPI document to
|
|
30
|
+
* {@link IHttpMigrateApplication}
|
|
31
|
+
* - {@link execute}: Call a route and return response body
|
|
32
|
+
* - {@link propagate}: Call a route and return full HTTP response (including
|
|
33
|
+
* non-2xx)
|
|
34
|
+
*
|
|
35
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
36
|
+
*/
|
|
37
|
+
export namespace HttpMigration {
|
|
38
|
+
/**
|
|
39
|
+
* Convert OpenAPI document to migration application.
|
|
40
|
+
*
|
|
41
|
+
* @param document OpenAPI document (any version)
|
|
42
|
+
* @returns Migration application with callable routes
|
|
43
|
+
*/
|
|
44
|
+
export const application = (
|
|
45
|
+
document:
|
|
46
|
+
| OpenApi.IDocument
|
|
47
|
+
| SwaggerV2.IDocument
|
|
48
|
+
| OpenApiV3.IDocument
|
|
49
|
+
| OpenApiV3_1.IDocument
|
|
50
|
+
| OpenApiV3_2.IDocument,
|
|
51
|
+
): IHttpMigrateApplication =>
|
|
52
|
+
HttpMigrateApplicationComposer.compose(
|
|
53
|
+
OpenApiConverter.upgradeDocument(document),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Execute HTTP route.
|
|
58
|
+
*
|
|
59
|
+
* @param props Fetch properties
|
|
60
|
+
* @returns Response body
|
|
61
|
+
* @throws HttpError on non-2xx status
|
|
62
|
+
*/
|
|
63
|
+
export const execute = (props: IFetchProps): Promise<unknown> =>
|
|
64
|
+
HttpMigrateRouteFetcher.execute(props);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Execute HTTP route and return full response.
|
|
68
|
+
*
|
|
69
|
+
* @param props Fetch properties
|
|
70
|
+
* @returns Full HTTP response including non-2xx
|
|
71
|
+
*/
|
|
72
|
+
export const propagate = (props: IFetchProps): Promise<IHttpResponse> =>
|
|
73
|
+
HttpMigrateRouteFetcher.propagate(props);
|
|
74
|
+
|
|
75
|
+
/** Properties for HTTP route execution. */
|
|
76
|
+
export interface IFetchProps {
|
|
77
|
+
/** HTTP connection info. */
|
|
78
|
+
connection: IHttpConnection;
|
|
79
|
+
|
|
80
|
+
/** Route to execute. */
|
|
81
|
+
route: IHttpMigrateRoute;
|
|
82
|
+
|
|
83
|
+
/** Path parameters. */
|
|
84
|
+
parameters:
|
|
85
|
+
| Array<string | number | boolean | bigint | null>
|
|
86
|
+
| Record<string, string | number | boolean | bigint | null>;
|
|
87
|
+
|
|
88
|
+
/** Query parameters. */
|
|
89
|
+
query?: object | undefined;
|
|
90
|
+
|
|
91
|
+
/** Request body. */
|
|
92
|
+
body?: object | undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|