typia 9.3.1 → 9.4.0
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/README.md +1 -1
- package/lib/AssertionGuard.d.mts +38 -0
- package/lib/AssertionGuard.d.ts +38 -0
- package/lib/TypeGuardError.d.mts +124 -3
- package/lib/TypeGuardError.d.ts +124 -3
- package/lib/TypeGuardError.js +47 -0
- package/lib/TypeGuardError.js.map +1 -1
- package/lib/TypeGuardError.mjs +96 -0
- package/lib/executable/typia.d.mts +1 -1
- package/lib/executable/typia.d.ts +1 -1
- package/lib/executable/typia.js +1 -1
- package/lib/executable/typia.mjs +1 -1
- package/lib/programmers/json/JsonSchemasProgrammer.js +2 -2
- package/lib/programmers/json/JsonSchemasProgrammer.mjs +2 -2
- package/lib/schemas/json/IJsonSchemaCollection.d.mts +161 -3
- package/lib/schemas/json/IJsonSchemaCollection.d.ts +161 -3
- package/lib/schemas/json/IJsonSchemaUnit.d.mts +215 -5
- package/lib/schemas/json/IJsonSchemaUnit.d.ts +215 -5
- package/package.json +3 -3
- package/src/AssertionGuard.ts +38 -0
- package/src/TypeGuardError.ts +144 -2
- package/src/executable/typia.ts +1 -1
- package/src/programmers/json/JsonSchemasProgrammer.ts +2 -2
- package/src/schemas/json/IJsonSchemaCollection.ts +169 -3
- package/src/schemas/json/IJsonSchemaUnit.ts +223 -5
package/README.md
CHANGED
package/lib/AssertionGuard.d.mts
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for assertion guard functions in `typia`.
|
|
3
|
+
*
|
|
4
|
+
* An assertion guard is a function that asserts an input value's type at runtime
|
|
5
|
+
* and performs a TypeScript type assertion if validation passes. Unlike regular
|
|
6
|
+
* assertion functions that return the validated value, assertion guards return
|
|
7
|
+
* nothing but automatically cast the input parameter to the expected type `T`.
|
|
8
|
+
*
|
|
9
|
+
* This type is used by `typia.createAssertGuard<T>()` and `typia.createAssertGuardEquals<T>()`
|
|
10
|
+
* to generate reusable assertion guard functions.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The expected type to validate and assert against
|
|
13
|
+
* @param input - The value to validate (type unknown)
|
|
14
|
+
* @throws {TypeGuardError} When the input value doesn't match the expected type T
|
|
15
|
+
* @returns void - Returns nothing, but asserts that input is type T
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* interface IMember {
|
|
20
|
+
* name: string;
|
|
21
|
+
* age: number;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Create reusable assertion guard
|
|
25
|
+
* const assertMember: AssertionGuard<IMember> = typia.createAssertGuard<IMember>();
|
|
26
|
+
*
|
|
27
|
+
* // Usage - input will be automatically cast to IMember if validation passes
|
|
28
|
+
* const unknownData: unknown = { name: "John", age: 25 };
|
|
29
|
+
*
|
|
30
|
+
* assertMember(unknownData);
|
|
31
|
+
* // After this line, unknownData is automatically treated as IMember type
|
|
32
|
+
* console.log(unknownData.name); // TypeScript knows this is safe
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://github.com/samchon/typia#assertguard-functions} Typia assertion guards documentation
|
|
36
|
+
* @see {@link TypeGuardError} Error thrown when assertion fails
|
|
37
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
38
|
+
*/
|
|
1
39
|
export type AssertionGuard<T> = (input: unknown) => asserts input is T;
|
package/lib/AssertionGuard.d.ts
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definition for assertion guard functions in `typia`.
|
|
3
|
+
*
|
|
4
|
+
* An assertion guard is a function that asserts an input value's type at runtime
|
|
5
|
+
* and performs a TypeScript type assertion if validation passes. Unlike regular
|
|
6
|
+
* assertion functions that return the validated value, assertion guards return
|
|
7
|
+
* nothing but automatically cast the input parameter to the expected type `T`.
|
|
8
|
+
*
|
|
9
|
+
* This type is used by `typia.createAssertGuard<T>()` and `typia.createAssertGuardEquals<T>()`
|
|
10
|
+
* to generate reusable assertion guard functions.
|
|
11
|
+
*
|
|
12
|
+
* @template T - The expected type to validate and assert against
|
|
13
|
+
* @param input - The value to validate (type unknown)
|
|
14
|
+
* @throws {TypeGuardError} When the input value doesn't match the expected type T
|
|
15
|
+
* @returns void - Returns nothing, but asserts that input is type T
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* interface IMember {
|
|
20
|
+
* name: string;
|
|
21
|
+
* age: number;
|
|
22
|
+
* }
|
|
23
|
+
*
|
|
24
|
+
* // Create reusable assertion guard
|
|
25
|
+
* const assertMember: AssertionGuard<IMember> = typia.createAssertGuard<IMember>();
|
|
26
|
+
*
|
|
27
|
+
* // Usage - input will be automatically cast to IMember if validation passes
|
|
28
|
+
* const unknownData: unknown = { name: "John", age: 25 };
|
|
29
|
+
*
|
|
30
|
+
* assertMember(unknownData);
|
|
31
|
+
* // After this line, unknownData is automatically treated as IMember type
|
|
32
|
+
* console.log(unknownData.name); // TypeScript knows this is safe
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://github.com/samchon/typia#assertguard-functions} Typia assertion guards documentation
|
|
36
|
+
* @see {@link TypeGuardError} Error thrown when assertion fails
|
|
37
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
38
|
+
*/
|
|
1
39
|
export type AssertionGuard<T> = (input: unknown) => asserts input is T;
|
package/lib/TypeGuardError.d.mts
CHANGED
|
@@ -1,17 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
|
|
3
|
+
*
|
|
4
|
+
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
5
|
+
* doesn't match the expected type.
|
|
6
|
+
*
|
|
7
|
+
* The error provides detailed information about the first assertion failure encountered,
|
|
8
|
+
* including the access path where the error occurred, the expected type, and the actual value.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The expected type (generic for type safety)
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* interface IMember {
|
|
15
|
+
* name: string;
|
|
16
|
+
* age: number & ExclusiveMinimum<19>;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* try {
|
|
20
|
+
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof TypeGuardError) {
|
|
23
|
+
* console.log(error.method); // "typia.assert"
|
|
24
|
+
* console.log(error.path); // "input.age"
|
|
25
|
+
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
26
|
+
* console.log(error.value); // 18
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
1
31
|
export declare class TypeGuardError<T = any> extends Error {
|
|
32
|
+
/**
|
|
33
|
+
* The name of the typia method that threw this error.
|
|
34
|
+
*
|
|
35
|
+
* @example "typia.assert"
|
|
36
|
+
*/
|
|
2
37
|
readonly method: string;
|
|
38
|
+
/**
|
|
39
|
+
* The access path to the property where the assertion error occurred.
|
|
40
|
+
*
|
|
41
|
+
* Uses dot notation to indicate the path for nested object properties.
|
|
42
|
+
* May be `undefined` if the error occurred at the root level.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* - `"input.age"` - Error in the age property of the object
|
|
46
|
+
* - `"input.profile.email"` - Error in the email property of a nested object
|
|
47
|
+
* - `"input[0].name"` - Error in the name property of the first array element
|
|
48
|
+
* - `undefined` - Error occurred at the root level
|
|
49
|
+
*/
|
|
3
50
|
readonly path: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* String representation of the expected type at the error location.
|
|
53
|
+
*
|
|
54
|
+
* Represents TypeScript types as strings, including detailed type information
|
|
55
|
+
* for complex types.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* - `"string"` - Expected string type
|
|
59
|
+
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
|
|
60
|
+
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
|
|
61
|
+
* - `"{ name: string; age: number }"` - Expected object type
|
|
62
|
+
*/
|
|
4
63
|
readonly expected: string;
|
|
5
|
-
|
|
6
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The actual value that failed assertion.
|
|
66
|
+
*
|
|
67
|
+
* Stores the actual value at the error path as-is.
|
|
68
|
+
* Useful for debugging by comparing the expected type with the actual value.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* - `18` - Numeric value
|
|
72
|
+
* - `"invalid"` - String value
|
|
73
|
+
* - `{ name: "John", age: 18, sex: 1 }` - Object value
|
|
74
|
+
*/
|
|
75
|
+
readonly value: unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new TypeGuardError instance.
|
|
78
|
+
*
|
|
79
|
+
* @param props - Object containing the properties needed to create the error
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const error = new TypeGuardError({
|
|
84
|
+
* method: "typia.assert",
|
|
85
|
+
* path: "input.age",
|
|
86
|
+
* expected: "number & ExclusiveMinimum<19>",
|
|
87
|
+
* value: 18
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
7
91
|
constructor(props: TypeGuardError.IProps);
|
|
8
92
|
}
|
|
9
93
|
export declare namespace TypeGuardError {
|
|
94
|
+
/**
|
|
95
|
+
* Interface for properties passed to the TypeGuardError constructor.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const props: TypeGuardError.IProps = {
|
|
100
|
+
* method: "typia.assertEquals",
|
|
101
|
+
* path: "input.sex",
|
|
102
|
+
* expected: "undefined",
|
|
103
|
+
* value: 1,
|
|
104
|
+
* message: "Custom error message" // optional
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
10
108
|
interface IProps {
|
|
109
|
+
/**
|
|
110
|
+
* The name of the typia method that threw the error.
|
|
111
|
+
*
|
|
112
|
+
* @example "typia.assert", "typia.assertEquals"
|
|
113
|
+
*/
|
|
11
114
|
method: string;
|
|
115
|
+
/**
|
|
116
|
+
* The access path to the property where the assertion error occurred (optional).
|
|
117
|
+
*
|
|
118
|
+
* @example "input.age", "input.profile.email"
|
|
119
|
+
*/
|
|
12
120
|
path?: undefined | string;
|
|
121
|
+
/**
|
|
122
|
+
* String representation of the expected type at the error location.
|
|
123
|
+
*
|
|
124
|
+
* @example "string", "number & ExclusiveMinimum<19>"
|
|
125
|
+
*/
|
|
13
126
|
expected: string;
|
|
14
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The actual value that failed assertion.
|
|
129
|
+
*/
|
|
130
|
+
value: unknown;
|
|
131
|
+
/**
|
|
132
|
+
* Custom error message (optional).
|
|
133
|
+
*
|
|
134
|
+
* If not provided, a default format message will be automatically generated.
|
|
135
|
+
*/
|
|
15
136
|
message?: undefined | string;
|
|
16
137
|
}
|
|
17
138
|
}
|
package/lib/TypeGuardError.d.ts
CHANGED
|
@@ -1,17 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
|
|
3
|
+
*
|
|
4
|
+
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
5
|
+
* doesn't match the expected type.
|
|
6
|
+
*
|
|
7
|
+
* The error provides detailed information about the first assertion failure encountered,
|
|
8
|
+
* including the access path where the error occurred, the expected type, and the actual value.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The expected type (generic for type safety)
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* interface IMember {
|
|
15
|
+
* name: string;
|
|
16
|
+
* age: number & ExclusiveMinimum<19>;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* try {
|
|
20
|
+
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof TypeGuardError) {
|
|
23
|
+
* console.log(error.method); // "typia.assert"
|
|
24
|
+
* console.log(error.path); // "input.age"
|
|
25
|
+
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
26
|
+
* console.log(error.value); // 18
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
1
31
|
export declare class TypeGuardError<T = any> extends Error {
|
|
32
|
+
/**
|
|
33
|
+
* The name of the typia method that threw this error.
|
|
34
|
+
*
|
|
35
|
+
* @example "typia.assert"
|
|
36
|
+
*/
|
|
2
37
|
readonly method: string;
|
|
38
|
+
/**
|
|
39
|
+
* The access path to the property where the assertion error occurred.
|
|
40
|
+
*
|
|
41
|
+
* Uses dot notation to indicate the path for nested object properties.
|
|
42
|
+
* May be `undefined` if the error occurred at the root level.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* - `"input.age"` - Error in the age property of the object
|
|
46
|
+
* - `"input.profile.email"` - Error in the email property of a nested object
|
|
47
|
+
* - `"input[0].name"` - Error in the name property of the first array element
|
|
48
|
+
* - `undefined` - Error occurred at the root level
|
|
49
|
+
*/
|
|
3
50
|
readonly path: string | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* String representation of the expected type at the error location.
|
|
53
|
+
*
|
|
54
|
+
* Represents TypeScript types as strings, including detailed type information
|
|
55
|
+
* for complex types.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* - `"string"` - Expected string type
|
|
59
|
+
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
|
|
60
|
+
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
|
|
61
|
+
* - `"{ name: string; age: number }"` - Expected object type
|
|
62
|
+
*/
|
|
4
63
|
readonly expected: string;
|
|
5
|
-
|
|
6
|
-
|
|
64
|
+
/**
|
|
65
|
+
* The actual value that failed assertion.
|
|
66
|
+
*
|
|
67
|
+
* Stores the actual value at the error path as-is.
|
|
68
|
+
* Useful for debugging by comparing the expected type with the actual value.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* - `18` - Numeric value
|
|
72
|
+
* - `"invalid"` - String value
|
|
73
|
+
* - `{ name: "John", age: 18, sex: 1 }` - Object value
|
|
74
|
+
*/
|
|
75
|
+
readonly value: unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Creates a new TypeGuardError instance.
|
|
78
|
+
*
|
|
79
|
+
* @param props - Object containing the properties needed to create the error
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const error = new TypeGuardError({
|
|
84
|
+
* method: "typia.assert",
|
|
85
|
+
* path: "input.age",
|
|
86
|
+
* expected: "number & ExclusiveMinimum<19>",
|
|
87
|
+
* value: 18
|
|
88
|
+
* });
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
7
91
|
constructor(props: TypeGuardError.IProps);
|
|
8
92
|
}
|
|
9
93
|
export declare namespace TypeGuardError {
|
|
94
|
+
/**
|
|
95
|
+
* Interface for properties passed to the TypeGuardError constructor.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* const props: TypeGuardError.IProps = {
|
|
100
|
+
* method: "typia.assertEquals",
|
|
101
|
+
* path: "input.sex",
|
|
102
|
+
* expected: "undefined",
|
|
103
|
+
* value: 1,
|
|
104
|
+
* message: "Custom error message" // optional
|
|
105
|
+
* };
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
10
108
|
interface IProps {
|
|
109
|
+
/**
|
|
110
|
+
* The name of the typia method that threw the error.
|
|
111
|
+
*
|
|
112
|
+
* @example "typia.assert", "typia.assertEquals"
|
|
113
|
+
*/
|
|
11
114
|
method: string;
|
|
115
|
+
/**
|
|
116
|
+
* The access path to the property where the assertion error occurred (optional).
|
|
117
|
+
*
|
|
118
|
+
* @example "input.age", "input.profile.email"
|
|
119
|
+
*/
|
|
12
120
|
path?: undefined | string;
|
|
121
|
+
/**
|
|
122
|
+
* String representation of the expected type at the error location.
|
|
123
|
+
*
|
|
124
|
+
* @example "string", "number & ExclusiveMinimum<19>"
|
|
125
|
+
*/
|
|
13
126
|
expected: string;
|
|
14
|
-
|
|
127
|
+
/**
|
|
128
|
+
* The actual value that failed assertion.
|
|
129
|
+
*/
|
|
130
|
+
value: unknown;
|
|
131
|
+
/**
|
|
132
|
+
* Custom error message (optional).
|
|
133
|
+
*
|
|
134
|
+
* If not provided, a default format message will be automatically generated.
|
|
135
|
+
*/
|
|
15
136
|
message?: undefined | string;
|
|
16
137
|
}
|
|
17
138
|
}
|
package/lib/TypeGuardError.js
CHANGED
|
@@ -1,12 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TypeGuardError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
|
|
6
|
+
*
|
|
7
|
+
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
8
|
+
* doesn't match the expected type.
|
|
9
|
+
*
|
|
10
|
+
* The error provides detailed information about the first assertion failure encountered,
|
|
11
|
+
* including the access path where the error occurred, the expected type, and the actual value.
|
|
12
|
+
*
|
|
13
|
+
* @template T - The expected type (generic for type safety)
|
|
14
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* interface IMember {
|
|
18
|
+
* name: string;
|
|
19
|
+
* age: number & ExclusiveMinimum<19>;
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* try {
|
|
23
|
+
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
24
|
+
* } catch (error) {
|
|
25
|
+
* if (error instanceof TypeGuardError) {
|
|
26
|
+
* console.log(error.method); // "typia.assert"
|
|
27
|
+
* console.log(error.path); // "input.age"
|
|
28
|
+
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
29
|
+
* console.log(error.value); // 18
|
|
30
|
+
* }
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
4
34
|
class TypeGuardError extends Error {
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new TypeGuardError instance.
|
|
37
|
+
*
|
|
38
|
+
* @param props - Object containing the properties needed to create the error
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const error = new TypeGuardError({
|
|
43
|
+
* method: "typia.assert",
|
|
44
|
+
* path: "input.age",
|
|
45
|
+
* expected: "number & ExclusiveMinimum<19>",
|
|
46
|
+
* value: 18
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
5
50
|
constructor(props) {
|
|
6
51
|
// MESSAGE CONSTRUCTION
|
|
52
|
+
// Use custom message if provided, otherwise generate default format
|
|
7
53
|
super(props.message ||
|
|
8
54
|
`Error on ${props.method}(): invalid type${props.path ? ` on ${props.path}` : ""}, expect to be ${props.expected}`);
|
|
9
55
|
// INHERITANCE POLYFILL
|
|
56
|
+
// Set up prototype for compatibility across different JavaScript environments
|
|
10
57
|
const proto = new.target.prototype;
|
|
11
58
|
if (Object.setPrototypeOf)
|
|
12
59
|
Object.setPrototypeOf(this, proto);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGuardError.js","sourceRoot":"","sources":["../src/TypeGuardError.ts"],"names":[],"mappings":";;;AAAA,MAAa,cAAwB,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"TypeGuardError.js","sourceRoot":"","sources":["../src/TypeGuardError.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAa,cAAwB,SAAQ,KAAK;IA4DhD;;;;;;;;;;;;;;OAcG;IACH,YAAmB,KAA4B;QAC7C,uBAAuB;QACvB,oEAAoE;QACpE,KAAK,CACH,KAAK,CAAC,OAAO;YACX,YAAY,KAAK,CAAC,MAAM,mBACtB,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EACrC,kBAAkB,KAAK,CAAC,QAAQ,EAAE,CACrC,CAAC;QAEF,uBAAuB;QACvB,8EAA8E;QAC9E,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC;QACnC,IAAI,MAAM,CAAC,cAAc;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;;YACxD,IAAY,CAAC,SAAS,GAAG,KAAK,CAAC;QAErC,iBAAiB;QACjB,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC;QAC/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;IAC3B,CAAC;CACF;AAjGD,wCAiGC"}
|
package/lib/TypeGuardError.mjs
CHANGED
|
@@ -1,14 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Custom error class thrown when runtime assertion fails in `typia.assert<T>()` function.
|
|
3
|
+
*
|
|
4
|
+
* This error is thrown by the `typia.assert<T>()` function when the input value
|
|
5
|
+
* doesn't match the expected type.
|
|
6
|
+
*
|
|
7
|
+
* The error provides detailed information about the first assertion failure encountered,
|
|
8
|
+
* including the access path where the error occurred, the expected type, and the actual value.
|
|
9
|
+
*
|
|
10
|
+
* @template T - The expected type (generic for type safety)
|
|
11
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* interface IMember {
|
|
15
|
+
* name: string;
|
|
16
|
+
* age: number & ExclusiveMinimum<19>;
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* try {
|
|
20
|
+
* typia.assert<IMember>({ name: "John", age: 18 });
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* if (error instanceof TypeGuardError) {
|
|
23
|
+
* console.log(error.method); // "typia.assert"
|
|
24
|
+
* console.log(error.path); // "input.age"
|
|
25
|
+
* console.log(error.expected); // "number & ExclusiveMinimum<19>"
|
|
26
|
+
* console.log(error.value); // 18
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
1
31
|
class TypeGuardError extends Error {
|
|
32
|
+
/**
|
|
33
|
+
* The name of the typia method that threw this error.
|
|
34
|
+
*
|
|
35
|
+
* @example "typia.assert"
|
|
36
|
+
*/
|
|
2
37
|
method;
|
|
38
|
+
/**
|
|
39
|
+
* The access path to the property where the assertion error occurred.
|
|
40
|
+
*
|
|
41
|
+
* Uses dot notation to indicate the path for nested object properties.
|
|
42
|
+
* May be `undefined` if the error occurred at the root level.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* - `"input.age"` - Error in the age property of the object
|
|
46
|
+
* - `"input.profile.email"` - Error in the email property of a nested object
|
|
47
|
+
* - `"input[0].name"` - Error in the name property of the first array element
|
|
48
|
+
* - `undefined` - Error occurred at the root level
|
|
49
|
+
*/
|
|
3
50
|
path;
|
|
51
|
+
/**
|
|
52
|
+
* String representation of the expected type at the error location.
|
|
53
|
+
*
|
|
54
|
+
* Represents TypeScript types as strings, including detailed type information
|
|
55
|
+
* for complex types.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* - `"string"` - Expected string type
|
|
59
|
+
* - `"number & ExclusiveMinimum<19>"` - Expected number greater than 19
|
|
60
|
+
* - `"undefined"` - Expected undefined (when superfluous property found in assertion)
|
|
61
|
+
* - `"{ name: string; age: number }"` - Expected object type
|
|
62
|
+
*/
|
|
4
63
|
expected;
|
|
64
|
+
/**
|
|
65
|
+
* The actual value that failed assertion.
|
|
66
|
+
*
|
|
67
|
+
* Stores the actual value at the error path as-is.
|
|
68
|
+
* Useful for debugging by comparing the expected type with the actual value.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* - `18` - Numeric value
|
|
72
|
+
* - `"invalid"` - String value
|
|
73
|
+
* - `{ name: "John", age: 18, sex: 1 }` - Object value
|
|
74
|
+
*/
|
|
5
75
|
value;
|
|
76
|
+
/**
|
|
77
|
+
* Phantom property for type safety purposes.
|
|
78
|
+
*
|
|
79
|
+
* This property is not actually used and exists only to maintain
|
|
80
|
+
* the generic type T in TypeScript's type system.
|
|
81
|
+
* Always has an `undefined` value at runtime.
|
|
82
|
+
*
|
|
83
|
+
* @internal
|
|
84
|
+
*/
|
|
6
85
|
fake_expected_typed_value_;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a new TypeGuardError instance.
|
|
88
|
+
*
|
|
89
|
+
* @param props - Object containing the properties needed to create the error
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* const error = new TypeGuardError({
|
|
94
|
+
* method: "typia.assert",
|
|
95
|
+
* path: "input.age",
|
|
96
|
+
* expected: "number & ExclusiveMinimum<19>",
|
|
97
|
+
* value: 18
|
|
98
|
+
* });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
7
101
|
constructor(props) {
|
|
8
102
|
// MESSAGE CONSTRUCTION
|
|
103
|
+
// Use custom message if provided, otherwise generate default format
|
|
9
104
|
super(props.message ||
|
|
10
105
|
`Error on ${props.method}(): invalid type${props.path ? ` on ${props.path}` : ""}, expect to be ${props.expected}`);
|
|
11
106
|
// INHERITANCE POLYFILL
|
|
107
|
+
// Set up prototype for compatibility across different JavaScript environments
|
|
12
108
|
const proto = new.target.prototype;
|
|
13
109
|
if (Object.setPrototypeOf)
|
|
14
110
|
Object.setPrototypeOf(this, proto);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
declare const USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia generate --input src/templates --output src/
|
|
2
|
+
declare const USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia generate --input src/templates --output src/functional\n";
|
|
3
3
|
declare const halt: (desc: string) => never;
|
|
4
4
|
declare const main: () => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
declare const USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia generate --input src/templates --output src/
|
|
2
|
+
declare const USAGE = "Wrong command has been detected. Use like below:\n\n npx typia setup \\\n --manager (npm|pnpm|yarn) \\\n --project {tsconfig.json file path}\n\n - npx typia setup\n - npx typia setup --manager pnpm\n - npx typia setup --project tsconfig.test.json\n\n npx typia generate \n --input {directory} \\\n --output {directory}\n\n --npx typia generate --input src/templates --output src/functional\n";
|
|
3
3
|
declare const halt: (desc: string) => never;
|
|
4
4
|
declare const main: () => Promise<void>;
|
package/lib/executable/typia.js
CHANGED
|
@@ -56,7 +56,7 @@ const USAGE = `Wrong command has been detected. Use like below:
|
|
|
56
56
|
--input {directory} \\
|
|
57
57
|
--output {directory}
|
|
58
58
|
|
|
59
|
-
--npx typia generate --input src/templates --output src/
|
|
59
|
+
--npx typia generate --input src/templates --output src/functional
|
|
60
60
|
`;
|
|
61
61
|
const halt = (desc) => {
|
|
62
62
|
console.error(desc);
|
package/lib/executable/typia.mjs
CHANGED
|
@@ -13,7 +13,7 @@ const USAGE = `Wrong command has been detected. Use like below:
|
|
|
13
13
|
--input {directory} \\
|
|
14
14
|
--output {directory}
|
|
15
15
|
|
|
16
|
-
--npx typia generate --input src/templates --output src/
|
|
16
|
+
--npx typia generate --input src/templates --output src/functional
|
|
17
17
|
`;
|
|
18
18
|
const halt = (desc) => {
|
|
19
19
|
console.error(desc);
|
|
@@ -30,8 +30,8 @@ var JsonSchemasProgrammer;
|
|
|
30
30
|
JsonSchemasProgrammer.write = (props) => props.version === "3.0"
|
|
31
31
|
? writeV3_0(props.metadatas)
|
|
32
32
|
: writeV3_1(props.metadatas);
|
|
33
|
-
const writeV3_0 = (
|
|
34
|
-
const collection = writeV3_1(
|
|
33
|
+
const writeV3_0 = (metadataList) => {
|
|
34
|
+
const collection = writeV3_1(metadataList);
|
|
35
35
|
const asset = OpenApiV3Downgrader_1.OpenApiV3Downgrader.downgradeComponents(collection.components);
|
|
36
36
|
const caster = OpenApiV3Downgrader_1.OpenApiV3Downgrader.downgradeSchema(asset);
|
|
37
37
|
return {
|
|
@@ -28,8 +28,8 @@ var JsonSchemasProgrammer;
|
|
|
28
28
|
JsonSchemasProgrammer.write = (props) => props.version === "3.0"
|
|
29
29
|
? writeV3_0(props.metadatas)
|
|
30
30
|
: writeV3_1(props.metadatas);
|
|
31
|
-
const writeV3_0 = (
|
|
32
|
-
const collection = writeV3_1(
|
|
31
|
+
const writeV3_0 = (metadataList) => {
|
|
32
|
+
const collection = writeV3_1(metadataList);
|
|
33
33
|
const asset = OpenApiV3Downgrader.downgradeComponents(collection.components);
|
|
34
34
|
const caster = OpenApiV3Downgrader.downgradeSchema(asset);
|
|
35
35
|
return {
|