@typia/interface 12.0.0 → 12.1.0-dev.20260325

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.
@@ -1,5 +1,5 @@
1
- export * from "./OpenApi";
2
- export * from "./OpenApiV3";
3
- export * from "./OpenApiV3_1";
4
- export * from "./OpenApiV3_2";
5
- export * from "./SwaggerV2";
1
+ export * from "./OpenApi";
2
+ export * from "./OpenApiV3";
3
+ export * from "./OpenApiV3_1";
4
+ export * from "./OpenApiV3_2";
5
+ export * from "./SwaggerV2";
@@ -1,134 +1,134 @@
1
- import { DeepPartial } from "../typings/DeepPartial";
2
-
3
- /**
4
- * Result of lenient JSON parsing.
5
- *
6
- * `IJsonParseResult<T>` represents the result of parsing JSON that may be
7
- * incomplete, malformed, or contain non-standard syntax (e.g., unquoted keys,
8
- * trailing commas, missing quotes).
9
- *
10
- * Unlike standard JSON parsing which fails on any syntax error, lenient parsing
11
- * attempts to recover as much data as possible while reporting issues.
12
- *
13
- * Check the {@link IJsonParseResult.success} discriminator:
14
- *
15
- * - `true` → {@link IJsonParseResult.ISuccess} with parsed
16
- * {@link IJsonParseResult.ISuccess.data}
17
- * - `false` → {@link IJsonParseResult.IFailure} with partial
18
- * {@link IJsonParseResult.IFailure.data} and
19
- * {@link IJsonParseResult.IFailure.errors}
20
- *
21
- * @author Jeongho Nam - https://github.com/samchon
22
- * @template T The expected type after successful parsing
23
- */
24
- export type IJsonParseResult<T = unknown> =
25
- | IJsonParseResult.ISuccess<T>
26
- | IJsonParseResult.IFailure<T>;
27
-
28
- export namespace IJsonParseResult {
29
- /**
30
- * Successful parsing result.
31
- *
32
- * Indicates the JSON was parsed without any errors. The data may still have
33
- * been recovered from non-standard syntax (e.g., unquoted keys, trailing
34
- * commas), but no information was lost.
35
- *
36
- * @template T The parsed type
37
- */
38
- export interface ISuccess<T = unknown> {
39
- /**
40
- * Success discriminator.
41
- *
42
- * Always `true` for successful parsing.
43
- */
44
- success: true;
45
-
46
- /** The parsed data with correct type. */
47
- data: T;
48
- }
49
-
50
- /**
51
- * Failed parsing result with partial data and errors.
52
- *
53
- * Indicates the JSON had syntax errors that could not be fully recovered. The
54
- * {@link data} contains whatever could be parsed, and {@link errors} describes
55
- * what went wrong.
56
- *
57
- * @template T The expected type (data may be partial)
58
- */
59
- export interface IFailure<T = unknown> {
60
- /**
61
- * Success discriminator.
62
- *
63
- * Always `false` for failed parsing.
64
- */
65
- success: false;
66
-
67
- /**
68
- * Partially parsed data.
69
- *
70
- * Contains whatever could be recovered from the malformed JSON. May be
71
- * incomplete or have missing properties.
72
- */
73
- data: DeepPartial<T> | undefined;
74
-
75
- /**
76
- * The original input string that was parsed.
77
- *
78
- * Preserved for debugging or error correction purposes.
79
- */
80
- input: string;
81
-
82
- /**
83
- * Array of parsing errors encountered.
84
- *
85
- * Each error describes a specific issue found during parsing, with location
86
- * and suggested fix.
87
- */
88
- errors: IError[];
89
- }
90
-
91
- /** Detailed information about a parsing error. */
92
- export interface IError {
93
- /**
94
- * Property path to the error location.
95
- *
96
- * A dot-notation path from the root to the error location. Uses `$input` as
97
- * the root.
98
- *
99
- * @example
100
- * $input.user.email;
101
- *
102
- * @example
103
- * $input.items[0].price;
104
- */
105
- path: string;
106
-
107
- /**
108
- * What was expected at this location.
109
- *
110
- * @example
111
- * JSON value (string, number, boolean, null, object, or array)
112
- *
113
- * @example
114
- * quoted string
115
- *
116
- * @example
117
- * ":";
118
- */
119
- expected: string;
120
-
121
- /**
122
- * Description of what was actually found.
123
- *
124
- * Human/AI-readable message explaining the issue.
125
- *
126
- * @example
127
- * unquoted string 'abc' - did you forget quotes?
128
- *
129
- * @example
130
- * missing opening quote for 'hello'
131
- */
132
- description: unknown;
133
- }
134
- }
1
+ import { DeepPartial } from "../typings/DeepPartial";
2
+
3
+ /**
4
+ * Result of lenient JSON parsing.
5
+ *
6
+ * `IJsonParseResult<T>` represents the result of parsing JSON that may be
7
+ * incomplete, malformed, or contain non-standard syntax (e.g., unquoted keys,
8
+ * trailing commas, missing quotes).
9
+ *
10
+ * Unlike standard JSON parsing which fails on any syntax error, lenient parsing
11
+ * attempts to recover as much data as possible while reporting issues.
12
+ *
13
+ * Check the {@link IJsonParseResult.success} discriminator:
14
+ *
15
+ * - `true` → {@link IJsonParseResult.ISuccess} with parsed
16
+ * {@link IJsonParseResult.ISuccess.data}
17
+ * - `false` → {@link IJsonParseResult.IFailure} with partial
18
+ * {@link IJsonParseResult.IFailure.data} and
19
+ * {@link IJsonParseResult.IFailure.errors}
20
+ *
21
+ * @author Jeongho Nam - https://github.com/samchon
22
+ * @template T The expected type after successful parsing
23
+ */
24
+ export type IJsonParseResult<T = unknown> =
25
+ | IJsonParseResult.ISuccess<T>
26
+ | IJsonParseResult.IFailure<T>;
27
+
28
+ export namespace IJsonParseResult {
29
+ /**
30
+ * Successful parsing result.
31
+ *
32
+ * Indicates the JSON was parsed without any errors. The data may still have
33
+ * been recovered from non-standard syntax (e.g., unquoted keys, trailing
34
+ * commas), but no information was lost.
35
+ *
36
+ * @template T The parsed type
37
+ */
38
+ export interface ISuccess<T = unknown> {
39
+ /**
40
+ * Success discriminator.
41
+ *
42
+ * Always `true` for successful parsing.
43
+ */
44
+ success: true;
45
+
46
+ /** The parsed data with correct type. */
47
+ data: T;
48
+ }
49
+
50
+ /**
51
+ * Failed parsing result with partial data and errors.
52
+ *
53
+ * Indicates the JSON had syntax errors that could not be fully recovered. The
54
+ * {@link data} contains whatever could be parsed, and {@link errors} describes
55
+ * what went wrong.
56
+ *
57
+ * @template T The expected type (data may be partial)
58
+ */
59
+ export interface IFailure<T = unknown> {
60
+ /**
61
+ * Success discriminator.
62
+ *
63
+ * Always `false` for failed parsing.
64
+ */
65
+ success: false;
66
+
67
+ /**
68
+ * Partially parsed data.
69
+ *
70
+ * Contains whatever could be recovered from the malformed JSON. May be
71
+ * incomplete or have missing properties.
72
+ */
73
+ data: DeepPartial<T> | undefined;
74
+
75
+ /**
76
+ * The original input string that was parsed.
77
+ *
78
+ * Preserved for debugging or error correction purposes.
79
+ */
80
+ input: string;
81
+
82
+ /**
83
+ * Array of parsing errors encountered.
84
+ *
85
+ * Each error describes a specific issue found during parsing, with location
86
+ * and suggested fix.
87
+ */
88
+ errors: IError[];
89
+ }
90
+
91
+ /** Detailed information about a parsing error. */
92
+ export interface IError {
93
+ /**
94
+ * Property path to the error location.
95
+ *
96
+ * A dot-notation path from the root to the error location. Uses `$input` as
97
+ * the root.
98
+ *
99
+ * @example
100
+ * $input.user.email;
101
+ *
102
+ * @example
103
+ * $input.items[0].price;
104
+ */
105
+ path: string;
106
+
107
+ /**
108
+ * What was expected at this location.
109
+ *
110
+ * @example
111
+ * JSON value (string, number, boolean, null, object, or array)
112
+ *
113
+ * @example
114
+ * quoted string
115
+ *
116
+ * @example
117
+ * ":";
118
+ */
119
+ expected: string;
120
+
121
+ /**
122
+ * Description of what was actually found.
123
+ *
124
+ * Human/AI-readable message explaining the issue.
125
+ *
126
+ * @example
127
+ * unquoted string 'abc' - did you forget quotes?
128
+ *
129
+ * @example
130
+ * missing opening quote for 'hello'
131
+ */
132
+ description: unknown;
133
+ }
134
+ }
@@ -1,112 +1,112 @@
1
- import { IJsonParseResult } from "./IJsonParseResult";
2
- import { ILlmSchema } from "./ILlmSchema";
3
- import { IValidation } from "./IValidation";
4
-
5
- /**
6
- * LLM structured output schema with parsing and validation utilities.
7
- *
8
- * `ILlmStructuredOutput<T>` is generated by `typia.llm.structuredOutput<T>()`
9
- * to provide everything needed for handling LLM structured outputs: the JSON
10
- * schema for prompting, and functions for parsing, coercing, and validating
11
- * responses.
12
- *
13
- * Structured outputs allow LLMs to generate data conforming to a predefined
14
- * schema instead of free-form text. This is useful for:
15
- *
16
- * - Extracting structured data from conversations
17
- * - Generating typed responses for downstream processing
18
- * - Ensuring consistent output formats across LLM calls
19
- *
20
- * Workflow:
21
- *
22
- * 1. Pass {@link parameters} schema to LLM provider
23
- * 2. Receive LLM response (JSON string or pre-parsed object)
24
- * 3. Use {@link parse} for raw strings or {@link coerce} for pre-parsed objects
25
- * 4. Use {@link validate} to check the result and get detailed errors
26
- *
27
- * @author Jeongho Nam - https://github.com/samchon
28
- * @template T The expected output type
29
- */
30
- export interface ILlmStructuredOutput<T = unknown> {
31
- /**
32
- * JSON schema for the structured output.
33
- *
34
- * Pass this schema to LLM providers (OpenAI, Anthropic, Google, etc.) to
35
- * constrain the output format. The schema includes `$defs` for shared type
36
- * definitions and `properties` for the output structure.
37
- *
38
- * Most LLM providers accept this directly in their structured output or
39
- * response format configuration.
40
- */
41
- parameters: ILlmSchema.IParameters;
42
-
43
- /**
44
- * Lenient JSON parser with schema-based type coercion.
45
- *
46
- * Handles incomplete or malformed JSON commonly produced by LLMs:
47
- *
48
- * - Unclosed brackets, strings, trailing commas
49
- * - JavaScript-style comments (`//` and multi-line)
50
- * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
51
- * - Markdown code block extraction, junk prefix skipping
52
- *
53
- * Also coerces double-stringified values based on the schema:
54
- *
55
- * - `"42"` → `42` (when schema expects number)
56
- * - `"true"` → `true` (when schema expects boolean)
57
- * - `"null"` → `null` (when schema expects null)
58
- * - `"{...}"` → `{...}` (when schema expects object)
59
- * - `"[...]"` → `[...]` (when schema expects array)
60
- *
61
- * Type validation is NOT performed — use {@link validate} after parsing.
62
- *
63
- * If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
64
- * and provides a pre-parsed object, use {@link coerce} instead.
65
- *
66
- * @param input Raw JSON string from LLM output
67
- * @returns Parse result with data on success, or partial data with errors
68
- */
69
- parse: (input: string) => IJsonParseResult<T>;
70
-
71
- /**
72
- * Coerce pre-parsed output to match expected schema types.
73
- *
74
- * **Use this only when the SDK already parses JSON internally.** For raw JSON
75
- * strings from LLM output, use {@link parse} instead — it handles both lenient
76
- * parsing and type coercion in one step.
77
- *
78
- * LLMs often return values with incorrect types even after parsing:
79
- *
80
- * - `"42"` → `42` (when schema expects number)
81
- * - `"true"` → `true` (when schema expects boolean)
82
- * - `"null"` → `null` (when schema expects null)
83
- * - `"{...}"` → `{...}` (when schema expects object)
84
- * - `"[...]"` → `[...]` (when schema expects array)
85
- *
86
- * This function recursively coerces these double-stringified values based on
87
- * the {@link parameters} schema.
88
- *
89
- * Type validation is NOT performed — use {@link validate} after coercion.
90
- *
91
- * @param input Pre-parsed output object from SDK
92
- * @returns Coerced output with corrected types
93
- */
94
- coerce: (input: unknown) => T;
95
-
96
- /**
97
- * Validates LLM-generated output against the schema.
98
- *
99
- * LLMs frequently make type errors such as returning strings instead of
100
- * numbers or missing required properties. Use this validator to check output
101
- * before further processing.
102
- *
103
- * When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
104
- * format the error for LLM feedback. The formatted output shows the invalid
105
- * JSON with inline error comments, helping the LLM understand and correct its
106
- * mistakes in the next turn.
107
- *
108
- * @param input The output generated by the LLM
109
- * @returns Validation result with success status and any errors
110
- */
111
- validate: (input: unknown) => IValidation<T>;
112
- }
1
+ import { IJsonParseResult } from "./IJsonParseResult";
2
+ import { ILlmSchema } from "./ILlmSchema";
3
+ import { IValidation } from "./IValidation";
4
+
5
+ /**
6
+ * LLM structured output schema with parsing and validation utilities.
7
+ *
8
+ * `ILlmStructuredOutput<T>` is generated by `typia.llm.structuredOutput<T>()`
9
+ * to provide everything needed for handling LLM structured outputs: the JSON
10
+ * schema for prompting, and functions for parsing, coercing, and validating
11
+ * responses.
12
+ *
13
+ * Structured outputs allow LLMs to generate data conforming to a predefined
14
+ * schema instead of free-form text. This is useful for:
15
+ *
16
+ * - Extracting structured data from conversations
17
+ * - Generating typed responses for downstream processing
18
+ * - Ensuring consistent output formats across LLM calls
19
+ *
20
+ * Workflow:
21
+ *
22
+ * 1. Pass {@link parameters} schema to LLM provider
23
+ * 2. Receive LLM response (JSON string or pre-parsed object)
24
+ * 3. Use {@link parse} for raw strings or {@link coerce} for pre-parsed objects
25
+ * 4. Use {@link validate} to check the result and get detailed errors
26
+ *
27
+ * @author Jeongho Nam - https://github.com/samchon
28
+ * @template T The expected output type
29
+ */
30
+ export interface ILlmStructuredOutput<T = unknown> {
31
+ /**
32
+ * JSON schema for the structured output.
33
+ *
34
+ * Pass this schema to LLM providers (OpenAI, Anthropic, Google, etc.) to
35
+ * constrain the output format. The schema includes `$defs` for shared type
36
+ * definitions and `properties` for the output structure.
37
+ *
38
+ * Most LLM providers accept this directly in their structured output or
39
+ * response format configuration.
40
+ */
41
+ parameters: ILlmSchema.IParameters;
42
+
43
+ /**
44
+ * Lenient JSON parser with schema-based type coercion.
45
+ *
46
+ * Handles incomplete or malformed JSON commonly produced by LLMs:
47
+ *
48
+ * - Unclosed brackets, strings, trailing commas
49
+ * - JavaScript-style comments (`//` and multi-line)
50
+ * - Unquoted object keys, incomplete keywords (`tru`, `fal`, `nul`)
51
+ * - Markdown code block extraction, junk prefix skipping
52
+ *
53
+ * Also coerces double-stringified values based on the schema:
54
+ *
55
+ * - `"42"` → `42` (when schema expects number)
56
+ * - `"true"` → `true` (when schema expects boolean)
57
+ * - `"null"` → `null` (when schema expects null)
58
+ * - `"{...}"` → `{...}` (when schema expects object)
59
+ * - `"[...]"` → `[...]` (when schema expects array)
60
+ *
61
+ * Type validation is NOT performed — use {@link validate} after parsing.
62
+ *
63
+ * If the SDK (e.g., LangChain, Vercel AI, MCP) already parses JSON internally
64
+ * and provides a pre-parsed object, use {@link coerce} instead.
65
+ *
66
+ * @param input Raw JSON string from LLM output
67
+ * @returns Parse result with data on success, or partial data with errors
68
+ */
69
+ parse: (input: string) => IJsonParseResult<T>;
70
+
71
+ /**
72
+ * Coerce pre-parsed output to match expected schema types.
73
+ *
74
+ * **Use this only when the SDK already parses JSON internally.** For raw JSON
75
+ * strings from LLM output, use {@link parse} instead — it handles both lenient
76
+ * parsing and type coercion in one step.
77
+ *
78
+ * LLMs often return values with incorrect types even after parsing:
79
+ *
80
+ * - `"42"` → `42` (when schema expects number)
81
+ * - `"true"` → `true` (when schema expects boolean)
82
+ * - `"null"` → `null` (when schema expects null)
83
+ * - `"{...}"` → `{...}` (when schema expects object)
84
+ * - `"[...]"` → `[...]` (when schema expects array)
85
+ *
86
+ * This function recursively coerces these double-stringified values based on
87
+ * the {@link parameters} schema.
88
+ *
89
+ * Type validation is NOT performed — use {@link validate} after coercion.
90
+ *
91
+ * @param input Pre-parsed output object from SDK
92
+ * @returns Coerced output with corrected types
93
+ */
94
+ coerce: (input: unknown) => T;
95
+
96
+ /**
97
+ * Validates LLM-generated output against the schema.
98
+ *
99
+ * LLMs frequently make type errors such as returning strings instead of
100
+ * numbers or missing required properties. Use this validator to check output
101
+ * before further processing.
102
+ *
103
+ * When validation fails, use {@link LlmJson.stringify} from `@typia/utils` to
104
+ * format the error for LLM feedback. The formatted output shows the invalid
105
+ * JSON with inline error comments, helping the LLM understand and correct its
106
+ * mistakes in the next turn.
107
+ *
108
+ * @param input The output generated by the LLM
109
+ * @returns Validation result with success status and any errors
110
+ */
111
+ validate: (input: unknown) => IValidation<T>;
112
+ }
@@ -1,15 +1,15 @@
1
- export * from "./IResult";
2
- export * from "./IValidation";
3
-
4
- export * from "./IJsonSchemaTransformError";
5
- export * from "./IJsonSchemaApplication";
6
- export * from "./IJsonSchemaCollection";
7
- export * from "./IJsonSchemaUnit";
8
- export * from "./IJsonSchemaAttribute";
9
-
10
- export * from "./ILlmController";
11
- export * from "./ILlmApplication";
12
- export * from "./ILlmFunction";
13
- export * from "./ILlmSchema";
14
- export * from "./ILlmStructuredOutput";
15
- export * from "./IJsonParseResult";
1
+ export * from "./IResult";
2
+ export * from "./IValidation";
3
+
4
+ export * from "./IJsonSchemaTransformError";
5
+ export * from "./IJsonSchemaApplication";
6
+ export * from "./IJsonSchemaCollection";
7
+ export * from "./IJsonSchemaUnit";
8
+ export * from "./IJsonSchemaAttribute";
9
+
10
+ export * from "./ILlmController";
11
+ export * from "./ILlmApplication";
12
+ export * from "./ILlmFunction";
13
+ export * from "./ILlmSchema";
14
+ export * from "./ILlmStructuredOutput";
15
+ export * from "./IJsonParseResult";