typia 9.7.2 → 10.0.0-dev.20251107
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/LICENSE +21 -21
- package/README.md +153 -153
- package/lib/factories/ProtobufFactory.js +1 -1
- package/lib/factories/ProtobufFactory.mjs +1 -1
- package/lib/programmers/internal/json_schema_station.d.mts +2 -2
- package/lib/programmers/internal/json_schema_station.d.ts +2 -2
- package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
- package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
- package/package.json +121 -121
- package/src/AssertionGuard.ts +41 -41
- package/src/CamelCase.ts +75 -75
- package/src/IRandomGenerator.ts +337 -337
- package/src/IReadableURLSearchParams.ts +9 -9
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +90 -90
- package/src/Resolved.ts +72 -72
- package/src/SnakeCase.ts +127 -127
- package/src/TypeGuardError.ts +216 -216
- package/src/factories/MetadataCollection.ts +270 -270
- package/src/factories/MetadataCommentTagFactory.ts +632 -632
- package/src/factories/MetadataFactory.ts +402 -402
- package/src/factories/ProtobufFactory.ts +873 -873
- package/src/functional.ts +705 -705
- package/src/http.ts +972 -972
- package/src/internal/_ProtobufReader.ts +188 -188
- package/src/internal/_ProtobufSizer.ts +137 -137
- package/src/internal/_ProtobufWriter.ts +135 -135
- package/src/internal/_jsonStringifyString.ts +42 -42
- package/src/json.ts +643 -643
- package/src/llm.ts +615 -615
- package/src/misc.ts +594 -594
- package/src/module.ts +889 -889
- package/src/notations.ts +751 -751
- package/src/programmers/FeatureProgrammer.ts +605 -605
- package/src/programmers/ImportProgrammer.ts +179 -179
- package/src/programmers/RandomProgrammer.ts +1195 -1195
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/check_array_length.ts +43 -43
- package/src/programmers/internal/check_bigint.ts +46 -46
- package/src/programmers/internal/check_dynamic_key.ts +197 -197
- package/src/programmers/internal/check_dynamic_properties.ts +231 -231
- package/src/programmers/internal/check_everything.ts +21 -21
- package/src/programmers/internal/check_native.ts +23 -23
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_object.ts +72 -72
- package/src/programmers/internal/check_string.ts +46 -46
- package/src/programmers/internal/check_template.ts +46 -46
- package/src/programmers/internal/check_union_array_like.ts +331 -331
- package/src/programmers/internal/decode_union_object.ts +110 -110
- package/src/programmers/internal/feature_object_entries.ts +59 -59
- package/src/programmers/internal/json_schema_escaped.ts +78 -78
- package/src/programmers/internal/json_schema_object.ts +150 -150
- package/src/programmers/internal/json_schema_station.ts +2 -2
- package/src/programmers/internal/metadata_to_pattern.ts +40 -40
- package/src/programmers/internal/postfix_of_tuple.ts +3 -3
- package/src/programmers/internal/prune_object_properties.ts +69 -69
- package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
- package/src/programmers/internal/stringify_native.ts +5 -5
- package/src/programmers/internal/stringify_regular_properties.ts +77 -77
- package/src/programmers/internal/template_to_pattern.ts +21 -21
- package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
- package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
- package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
- package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
- package/src/protobuf.ts +820 -820
- package/src/reflect.ts +46 -46
- package/src/schemas/json/IJsonApplication.ts +77 -77
- package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
- package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
- package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
- package/src/schemas/metadata/Metadata.ts +669 -669
- package/src/schemas/metadata/MetadataAliasType.ts +57 -57
- package/src/schemas/metadata/MetadataApplication.ts +40 -40
- package/src/schemas/metadata/MetadataArray.ts +47 -47
- package/src/schemas/metadata/MetadataArrayType.ts +51 -51
- package/src/schemas/metadata/MetadataAtomic.ts +85 -85
- package/src/schemas/metadata/MetadataEscaped.ts +45 -45
- package/src/schemas/metadata/MetadataFunction.ts +45 -45
- package/src/schemas/metadata/MetadataObject.ts +46 -46
- package/src/schemas/metadata/MetadataObjectType.ts +137 -137
- package/src/schemas/metadata/MetadataParameter.ts +52 -52
- package/src/schemas/metadata/MetadataProperty.ts +53 -53
- package/src/schemas/metadata/MetadataTemplate.ts +78 -78
- package/src/schemas/metadata/MetadataTuple.ts +28 -28
- package/src/schemas/metadata/MetadataTupleType.ts +61 -61
- package/src/tags/Constant.ts +47 -47
- package/src/tags/ContentMediaType.ts +27 -27
- package/src/tags/Default.ts +52 -52
- package/src/tags/Example.ts +56 -56
- package/src/tags/Examples.ts +56 -56
- package/src/tags/ExclusiveMaximum.ts +44 -44
- package/src/tags/ExclusiveMinimum.ts +44 -44
- package/src/tags/Format.ts +78 -78
- package/src/tags/JsonSchemaPlugin.ts +36 -36
- package/src/tags/MaxItems.ts +31 -31
- package/src/tags/MaxLength.ts +25 -25
- package/src/tags/Maximum.ts +39 -39
- package/src/tags/MinItems.ts +31 -31
- package/src/tags/MinLength.ts +25 -25
- package/src/tags/Minimum.ts +39 -39
- package/src/tags/MultipleOf.ts +42 -42
- package/src/tags/Pattern.ts +49 -49
- package/src/tags/Sequence.ts +37 -37
- package/src/tags/TagBase.ts +102 -102
- package/src/tags/Type.ts +64 -64
- package/src/tags/UniqueItems.ts +34 -34
- package/src/tags/internal/FormatCheatSheet.ts +71 -71
- package/src/transformers/ITransformOptions.ts +70 -70
- package/src/transformers/ImportTransformer.ts +253 -253
- package/src/transformers/NoTransformConfigurationError.ts +16 -16
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
- package/src/typings/Equal.ts +18 -18
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,216 +1,216 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()`
|
|
3
|
-
* function.
|
|
4
|
-
*
|
|
5
|
-
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
6
|
-
* doesn't match the expected type.
|
|
7
|
-
*
|
|
8
|
-
* The error provides detailed information about the first assertion failure
|
|
9
|
-
* encountered, including the access path where the error occurred, the expected
|
|
10
|
-
* type, and the actual value.
|
|
11
|
-
*
|
|
12
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
-
* @example
|
|
14
|
-
* ```typescript
|
|
15
|
-
* interface IMember {
|
|
16
|
-
* name: string;
|
|
17
|
-
* age: number & ExclusiveMinimum<19>;
|
|
18
|
-
* }
|
|
19
|
-
*
|
|
20
|
-
* try {
|
|
21
|
-
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
22
|
-
* } catch (error) {
|
|
23
|
-
* if (error instanceof TypeGuardError) {
|
|
24
|
-
* console.log(error.method); // "typia.assert"
|
|
25
|
-
* console.log(error.path); // "input.age"
|
|
26
|
-
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
27
|
-
* console.log(error.value); // 18
|
|
28
|
-
* }
|
|
29
|
-
* }
|
|
30
|
-
* ```;
|
|
31
|
-
*
|
|
32
|
-
* @template T - The expected type (generic for type safety)
|
|
33
|
-
*/
|
|
34
|
-
export class TypeGuardError<T = any> extends Error {
|
|
35
|
-
/**
|
|
36
|
-
* The name of the typia method that threw this error.
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* typia.assert;
|
|
40
|
-
*/
|
|
41
|
-
public readonly method: string;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The access path to the property where the assertion error occurred.
|
|
45
|
-
*
|
|
46
|
-
* Uses dot notation to indicate the path for nested object properties. May be
|
|
47
|
-
* `undefined` if the error occurred at the root level.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* - `"input.age"` - Error in the age property of the object
|
|
51
|
-
* - `"input.profile.email"` - Error in the email property of a nested object
|
|
52
|
-
* - `"input[0].name"` - Error in the name property of the first array element
|
|
53
|
-
* - `undefined` - Error occurred at the root level
|
|
54
|
-
*/
|
|
55
|
-
public readonly path: string | undefined;
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* String representation of the expected type at the error location.
|
|
59
|
-
*
|
|
60
|
-
* Represents TypeScript types as strings, including detailed type information
|
|
61
|
-
* for complex types.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* - `"string"` - Expected string type
|
|
65
|
-
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
|
|
66
|
-
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
|
|
67
|
-
* - `"{ name: string; age: number }"` - Expected object type
|
|
68
|
-
*/
|
|
69
|
-
public readonly expected: string;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* The actual value that failed assertion.
|
|
73
|
-
*
|
|
74
|
-
* Stores the actual value at the error path as-is. Useful for debugging by
|
|
75
|
-
* comparing the expected type with the actual value.
|
|
76
|
-
*
|
|
77
|
-
* @example
|
|
78
|
-
* - `18` - Numeric value
|
|
79
|
-
* - `"invalid"` - String value
|
|
80
|
-
* - `{ name: "John", age: 18, sex: 1 }` - Object value
|
|
81
|
-
*/
|
|
82
|
-
public readonly value: unknown;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Optional human-readable description of the type guard error
|
|
86
|
-
*
|
|
87
|
-
* This field is rarely populated in standard typia type assertion and is
|
|
88
|
-
* primarily intended for specialized AI agent libraries or custom validation
|
|
89
|
-
* scenarios that require additional context beyond the technical type
|
|
90
|
-
* information. Most assertion errors rely solely on the path, expected, and
|
|
91
|
-
* value fields for comprehensive error reporting.
|
|
92
|
-
*/
|
|
93
|
-
public readonly description?: string | undefined;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Phantom property for type safety purposes.
|
|
97
|
-
*
|
|
98
|
-
* This property is not actually used and exists only to maintain the generic
|
|
99
|
-
* type T in TypeScript's type system. Always has an `undefined` value at
|
|
100
|
-
* runtime.
|
|
101
|
-
*
|
|
102
|
-
* @internal
|
|
103
|
-
*/
|
|
104
|
-
protected readonly fake_expected_typed_value_?: T | undefined;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Creates a new TypeGuardError instance.
|
|
108
|
-
*
|
|
109
|
-
* @example
|
|
110
|
-
* ```typescript
|
|
111
|
-
* const error = new TypeGuardError({
|
|
112
|
-
* method: "typia.assert",
|
|
113
|
-
* path: "input.age",
|
|
114
|
-
* expected: "number & ExclusiveMinimum<19>",
|
|
115
|
-
* value: 18
|
|
116
|
-
* });
|
|
117
|
-
* ```;
|
|
118
|
-
*
|
|
119
|
-
* @param props - Object containing the properties needed to create the error
|
|
120
|
-
*/
|
|
121
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
122
|
-
// MESSAGE CONSTRUCTION
|
|
123
|
-
// Use custom message if provided, otherwise generate default format
|
|
124
|
-
super(
|
|
125
|
-
props.message ||
|
|
126
|
-
`Error on ${props.method}(): invalid type${
|
|
127
|
-
props.path ? ` on ${props.path}` : ""
|
|
128
|
-
}, expect to be ${props.expected}`,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
// INHERITANCE POLYFILL
|
|
132
|
-
// Set up prototype for compatibility across different JavaScript environments
|
|
133
|
-
const proto = new.target.prototype;
|
|
134
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
135
|
-
else (this as any).__proto__ = proto;
|
|
136
|
-
|
|
137
|
-
// ASSIGN MEMBERS
|
|
138
|
-
this.method = props.method;
|
|
139
|
-
this.path = props.path;
|
|
140
|
-
this.expected = props.expected;
|
|
141
|
-
this.value = props.value;
|
|
142
|
-
if (props.description || props.value === undefined)
|
|
143
|
-
this.description =
|
|
144
|
-
props.description ??
|
|
145
|
-
[
|
|
146
|
-
"The value at this path is `undefined`.",
|
|
147
|
-
"",
|
|
148
|
-
`Please fill the \`${props.expected}\` typed value next time.`,
|
|
149
|
-
].join("\n");
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export namespace TypeGuardError {
|
|
154
|
-
/**
|
|
155
|
-
* Interface for properties passed to the TypeGuardError constructor.
|
|
156
|
-
*
|
|
157
|
-
* @example
|
|
158
|
-
* ```typescript
|
|
159
|
-
* const props: TypeGuardError.IProps = {
|
|
160
|
-
* method: "typia.assertEquals",
|
|
161
|
-
* path: "input.sex",
|
|
162
|
-
* expected: "undefined",
|
|
163
|
-
* value: 1,
|
|
164
|
-
* message: "Custom error message" // optional
|
|
165
|
-
* };
|
|
166
|
-
* ```;
|
|
167
|
-
*/
|
|
168
|
-
export interface IProps {
|
|
169
|
-
/**
|
|
170
|
-
* The name of the typia method that threw the error.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* typia.assert, "typia.assertEquals";
|
|
174
|
-
*/
|
|
175
|
-
method: string;
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* The access path to the property where the assertion error occurred
|
|
179
|
-
* (optional).
|
|
180
|
-
*
|
|
181
|
-
* @example
|
|
182
|
-
* input.age, "input.profile.email";
|
|
183
|
-
*/
|
|
184
|
-
path?: undefined | string;
|
|
185
|
-
|
|
186
|
-
/**
|
|
187
|
-
* String representation of the expected type at the error location.
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* string, "number & ExclusiveMinimum<19>";
|
|
191
|
-
*/
|
|
192
|
-
expected: string;
|
|
193
|
-
|
|
194
|
-
/** The actual value that failed assertion. */
|
|
195
|
-
value: unknown;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Optional human-readable description of the type guard error
|
|
199
|
-
*
|
|
200
|
-
* This field is rarely populated in standard typia type assertion and is
|
|
201
|
-
* primarily intended for specialized AI agent libraries or custom
|
|
202
|
-
* validation scenarios that require additional context beyond the technical
|
|
203
|
-
* type information. Most assertion errors rely solely on the path,
|
|
204
|
-
* expected, and value fields for comprehensive error reporting.
|
|
205
|
-
*/
|
|
206
|
-
description?: string;
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Custom error message (optional).
|
|
210
|
-
*
|
|
211
|
-
* If not provided, a default format message will be automatically
|
|
212
|
-
* generated.
|
|
213
|
-
*/
|
|
214
|
-
message?: undefined | string;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()`
|
|
3
|
+
* function.
|
|
4
|
+
*
|
|
5
|
+
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
6
|
+
* doesn't match the expected type.
|
|
7
|
+
*
|
|
8
|
+
* The error provides detailed information about the first assertion failure
|
|
9
|
+
* encountered, including the access path where the error occurred, the expected
|
|
10
|
+
* type, and the actual value.
|
|
11
|
+
*
|
|
12
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* interface IMember {
|
|
16
|
+
* name: string;
|
|
17
|
+
* age: number & ExclusiveMinimum<19>;
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* try {
|
|
21
|
+
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
22
|
+
* } catch (error) {
|
|
23
|
+
* if (error instanceof TypeGuardError) {
|
|
24
|
+
* console.log(error.method); // "typia.assert"
|
|
25
|
+
* console.log(error.path); // "input.age"
|
|
26
|
+
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
27
|
+
* console.log(error.value); // 18
|
|
28
|
+
* }
|
|
29
|
+
* }
|
|
30
|
+
* ```;
|
|
31
|
+
*
|
|
32
|
+
* @template T - The expected type (generic for type safety)
|
|
33
|
+
*/
|
|
34
|
+
export class TypeGuardError<T = any> extends Error {
|
|
35
|
+
/**
|
|
36
|
+
* The name of the typia method that threw this error.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* typia.assert;
|
|
40
|
+
*/
|
|
41
|
+
public readonly method: string;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The access path to the property where the assertion error occurred.
|
|
45
|
+
*
|
|
46
|
+
* Uses dot notation to indicate the path for nested object properties. May be
|
|
47
|
+
* `undefined` if the error occurred at the root level.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* - `"input.age"` - Error in the age property of the object
|
|
51
|
+
* - `"input.profile.email"` - Error in the email property of a nested object
|
|
52
|
+
* - `"input[0].name"` - Error in the name property of the first array element
|
|
53
|
+
* - `undefined` - Error occurred at the root level
|
|
54
|
+
*/
|
|
55
|
+
public readonly path: string | undefined;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* String representation of the expected type at the error location.
|
|
59
|
+
*
|
|
60
|
+
* Represents TypeScript types as strings, including detailed type information
|
|
61
|
+
* for complex types.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* - `"string"` - Expected string type
|
|
65
|
+
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
|
|
66
|
+
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
|
|
67
|
+
* - `"{ name: string; age: number }"` - Expected object type
|
|
68
|
+
*/
|
|
69
|
+
public readonly expected: string;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The actual value that failed assertion.
|
|
73
|
+
*
|
|
74
|
+
* Stores the actual value at the error path as-is. Useful for debugging by
|
|
75
|
+
* comparing the expected type with the actual value.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* - `18` - Numeric value
|
|
79
|
+
* - `"invalid"` - String value
|
|
80
|
+
* - `{ name: "John", age: 18, sex: 1 }` - Object value
|
|
81
|
+
*/
|
|
82
|
+
public readonly value: unknown;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Optional human-readable description of the type guard error
|
|
86
|
+
*
|
|
87
|
+
* This field is rarely populated in standard typia type assertion and is
|
|
88
|
+
* primarily intended for specialized AI agent libraries or custom validation
|
|
89
|
+
* scenarios that require additional context beyond the technical type
|
|
90
|
+
* information. Most assertion errors rely solely on the path, expected, and
|
|
91
|
+
* value fields for comprehensive error reporting.
|
|
92
|
+
*/
|
|
93
|
+
public readonly description?: string | undefined;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Phantom property for type safety purposes.
|
|
97
|
+
*
|
|
98
|
+
* This property is not actually used and exists only to maintain the generic
|
|
99
|
+
* type T in TypeScript's type system. Always has an `undefined` value at
|
|
100
|
+
* runtime.
|
|
101
|
+
*
|
|
102
|
+
* @internal
|
|
103
|
+
*/
|
|
104
|
+
protected readonly fake_expected_typed_value_?: T | undefined;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a new TypeGuardError instance.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const error = new TypeGuardError({
|
|
112
|
+
* method: "typia.assert",
|
|
113
|
+
* path: "input.age",
|
|
114
|
+
* expected: "number & ExclusiveMinimum<19>",
|
|
115
|
+
* value: 18
|
|
116
|
+
* });
|
|
117
|
+
* ```;
|
|
118
|
+
*
|
|
119
|
+
* @param props - Object containing the properties needed to create the error
|
|
120
|
+
*/
|
|
121
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
122
|
+
// MESSAGE CONSTRUCTION
|
|
123
|
+
// Use custom message if provided, otherwise generate default format
|
|
124
|
+
super(
|
|
125
|
+
props.message ||
|
|
126
|
+
`Error on ${props.method}(): invalid type${
|
|
127
|
+
props.path ? ` on ${props.path}` : ""
|
|
128
|
+
}, expect to be ${props.expected}`,
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
// INHERITANCE POLYFILL
|
|
132
|
+
// Set up prototype for compatibility across different JavaScript environments
|
|
133
|
+
const proto = new.target.prototype;
|
|
134
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
135
|
+
else (this as any).__proto__ = proto;
|
|
136
|
+
|
|
137
|
+
// ASSIGN MEMBERS
|
|
138
|
+
this.method = props.method;
|
|
139
|
+
this.path = props.path;
|
|
140
|
+
this.expected = props.expected;
|
|
141
|
+
this.value = props.value;
|
|
142
|
+
if (props.description || props.value === undefined)
|
|
143
|
+
this.description =
|
|
144
|
+
props.description ??
|
|
145
|
+
[
|
|
146
|
+
"The value at this path is `undefined`.",
|
|
147
|
+
"",
|
|
148
|
+
`Please fill the \`${props.expected}\` typed value next time.`,
|
|
149
|
+
].join("\n");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export namespace TypeGuardError {
|
|
154
|
+
/**
|
|
155
|
+
* Interface for properties passed to the TypeGuardError constructor.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* const props: TypeGuardError.IProps = {
|
|
160
|
+
* method: "typia.assertEquals",
|
|
161
|
+
* path: "input.sex",
|
|
162
|
+
* expected: "undefined",
|
|
163
|
+
* value: 1,
|
|
164
|
+
* message: "Custom error message" // optional
|
|
165
|
+
* };
|
|
166
|
+
* ```;
|
|
167
|
+
*/
|
|
168
|
+
export interface IProps {
|
|
169
|
+
/**
|
|
170
|
+
* The name of the typia method that threw the error.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* typia.assert, "typia.assertEquals";
|
|
174
|
+
*/
|
|
175
|
+
method: string;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The access path to the property where the assertion error occurred
|
|
179
|
+
* (optional).
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* input.age, "input.profile.email";
|
|
183
|
+
*/
|
|
184
|
+
path?: undefined | string;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* String representation of the expected type at the error location.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* string, "number & ExclusiveMinimum<19>";
|
|
191
|
+
*/
|
|
192
|
+
expected: string;
|
|
193
|
+
|
|
194
|
+
/** The actual value that failed assertion. */
|
|
195
|
+
value: unknown;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Optional human-readable description of the type guard error
|
|
199
|
+
*
|
|
200
|
+
* This field is rarely populated in standard typia type assertion and is
|
|
201
|
+
* primarily intended for specialized AI agent libraries or custom
|
|
202
|
+
* validation scenarios that require additional context beyond the technical
|
|
203
|
+
* type information. Most assertion errors rely solely on the path,
|
|
204
|
+
* expected, and value fields for comprehensive error reporting.
|
|
205
|
+
*/
|
|
206
|
+
description?: string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Custom error message (optional).
|
|
210
|
+
*
|
|
211
|
+
* If not provided, a default format message will be automatically
|
|
212
|
+
* generated.
|
|
213
|
+
*/
|
|
214
|
+
message?: undefined | string;
|
|
215
|
+
}
|
|
216
|
+
}
|