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.
Files changed (116) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +153 -153
  3. package/lib/factories/ProtobufFactory.js +1 -1
  4. package/lib/factories/ProtobufFactory.mjs +1 -1
  5. package/lib/programmers/internal/json_schema_station.d.mts +2 -2
  6. package/lib/programmers/internal/json_schema_station.d.ts +2 -2
  7. package/lib/programmers/llm/LlmApplicationProgrammer.js +5 -1
  8. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  9. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +5 -1
  10. package/lib/programmers/llm/LlmSchemaProgrammer.js +1 -4
  11. package/lib/programmers/llm/LlmSchemaProgrammer.js.map +1 -1
  12. package/lib/programmers/llm/LlmSchemaProgrammer.mjs +1 -35
  13. package/package.json +121 -121
  14. package/src/AssertionGuard.ts +41 -41
  15. package/src/CamelCase.ts +75 -75
  16. package/src/IRandomGenerator.ts +337 -337
  17. package/src/IReadableURLSearchParams.ts +9 -9
  18. package/src/PascalCase.ts +71 -71
  19. package/src/Primitive.ts +90 -90
  20. package/src/Resolved.ts +72 -72
  21. package/src/SnakeCase.ts +127 -127
  22. package/src/TypeGuardError.ts +216 -216
  23. package/src/factories/MetadataCollection.ts +270 -270
  24. package/src/factories/MetadataCommentTagFactory.ts +632 -632
  25. package/src/factories/MetadataFactory.ts +402 -402
  26. package/src/factories/ProtobufFactory.ts +873 -873
  27. package/src/functional.ts +705 -705
  28. package/src/http.ts +972 -972
  29. package/src/internal/_ProtobufReader.ts +188 -188
  30. package/src/internal/_ProtobufSizer.ts +137 -137
  31. package/src/internal/_ProtobufWriter.ts +135 -135
  32. package/src/internal/_jsonStringifyString.ts +42 -42
  33. package/src/json.ts +643 -643
  34. package/src/llm.ts +615 -615
  35. package/src/misc.ts +594 -594
  36. package/src/module.ts +889 -889
  37. package/src/notations.ts +751 -751
  38. package/src/programmers/FeatureProgrammer.ts +605 -605
  39. package/src/programmers/ImportProgrammer.ts +179 -179
  40. package/src/programmers/RandomProgrammer.ts +1195 -1195
  41. package/src/programmers/helpers/ProtobufWire.ts +34 -34
  42. package/src/programmers/internal/check_array_length.ts +43 -43
  43. package/src/programmers/internal/check_bigint.ts +46 -46
  44. package/src/programmers/internal/check_dynamic_key.ts +197 -197
  45. package/src/programmers/internal/check_dynamic_properties.ts +231 -231
  46. package/src/programmers/internal/check_everything.ts +21 -21
  47. package/src/programmers/internal/check_native.ts +23 -23
  48. package/src/programmers/internal/check_number.ts +108 -108
  49. package/src/programmers/internal/check_object.ts +72 -72
  50. package/src/programmers/internal/check_string.ts +46 -46
  51. package/src/programmers/internal/check_template.ts +46 -46
  52. package/src/programmers/internal/check_union_array_like.ts +331 -331
  53. package/src/programmers/internal/decode_union_object.ts +110 -110
  54. package/src/programmers/internal/feature_object_entries.ts +59 -59
  55. package/src/programmers/internal/json_schema_escaped.ts +78 -78
  56. package/src/programmers/internal/json_schema_object.ts +150 -150
  57. package/src/programmers/internal/json_schema_station.ts +2 -2
  58. package/src/programmers/internal/metadata_to_pattern.ts +40 -40
  59. package/src/programmers/internal/postfix_of_tuple.ts +3 -3
  60. package/src/programmers/internal/prune_object_properties.ts +69 -69
  61. package/src/programmers/internal/stringify_dynamic_properties.ts +158 -158
  62. package/src/programmers/internal/stringify_native.ts +5 -5
  63. package/src/programmers/internal/stringify_regular_properties.ts +77 -77
  64. package/src/programmers/internal/template_to_pattern.ts +21 -21
  65. package/src/programmers/internal/wrap_metadata_rest_tuple.ts +21 -21
  66. package/src/programmers/json/JsonStringifyProgrammer.ts +1124 -1124
  67. package/src/programmers/llm/LlmApplicationProgrammer.ts +10 -1
  68. package/src/programmers/llm/LlmSchemaProgrammer.ts +2 -7
  69. package/src/protobuf.ts +820 -820
  70. package/src/reflect.ts +46 -46
  71. package/src/schemas/json/IJsonApplication.ts +77 -77
  72. package/src/schemas/json/IJsonSchemaCollection.ts +212 -212
  73. package/src/schemas/json/IJsonSchemaUnit.ts +263 -263
  74. package/src/schemas/metadata/IMetadataTypeTag.ts +14 -14
  75. package/src/schemas/metadata/Metadata.ts +669 -669
  76. package/src/schemas/metadata/MetadataAliasType.ts +57 -57
  77. package/src/schemas/metadata/MetadataApplication.ts +40 -40
  78. package/src/schemas/metadata/MetadataArray.ts +47 -47
  79. package/src/schemas/metadata/MetadataArrayType.ts +51 -51
  80. package/src/schemas/metadata/MetadataAtomic.ts +85 -85
  81. package/src/schemas/metadata/MetadataEscaped.ts +45 -45
  82. package/src/schemas/metadata/MetadataFunction.ts +45 -45
  83. package/src/schemas/metadata/MetadataObject.ts +46 -46
  84. package/src/schemas/metadata/MetadataObjectType.ts +137 -137
  85. package/src/schemas/metadata/MetadataParameter.ts +52 -52
  86. package/src/schemas/metadata/MetadataProperty.ts +53 -53
  87. package/src/schemas/metadata/MetadataTemplate.ts +78 -78
  88. package/src/schemas/metadata/MetadataTuple.ts +28 -28
  89. package/src/schemas/metadata/MetadataTupleType.ts +61 -61
  90. package/src/tags/Constant.ts +47 -47
  91. package/src/tags/ContentMediaType.ts +27 -27
  92. package/src/tags/Default.ts +52 -52
  93. package/src/tags/Example.ts +56 -56
  94. package/src/tags/Examples.ts +56 -56
  95. package/src/tags/ExclusiveMaximum.ts +44 -44
  96. package/src/tags/ExclusiveMinimum.ts +44 -44
  97. package/src/tags/Format.ts +78 -78
  98. package/src/tags/JsonSchemaPlugin.ts +36 -36
  99. package/src/tags/MaxItems.ts +31 -31
  100. package/src/tags/MaxLength.ts +25 -25
  101. package/src/tags/Maximum.ts +39 -39
  102. package/src/tags/MinItems.ts +31 -31
  103. package/src/tags/MinLength.ts +25 -25
  104. package/src/tags/Minimum.ts +39 -39
  105. package/src/tags/MultipleOf.ts +42 -42
  106. package/src/tags/Pattern.ts +49 -49
  107. package/src/tags/Sequence.ts +37 -37
  108. package/src/tags/TagBase.ts +102 -102
  109. package/src/tags/Type.ts +64 -64
  110. package/src/tags/UniqueItems.ts +34 -34
  111. package/src/tags/internal/FormatCheatSheet.ts +71 -71
  112. package/src/transformers/ITransformOptions.ts +70 -70
  113. package/src/transformers/ImportTransformer.ts +253 -253
  114. package/src/transformers/NoTransformConfigurationError.ts +16 -16
  115. package/src/transformers/features/llm/LlmApplicationTransformer.ts +224 -224
  116. package/src/typings/Equal.ts +18 -18
@@ -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
+ }