typia 7.6.0-dev.20241229 → 7.7.0-dev.20250130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/TypeGuardError.mjs +26 -0
- package/lib/TypeGuardError.mjs.map +1 -0
- package/lib/executable/setup/PluginConfigurator.js +3 -3
- package/lib/executable/typia.js +15 -15
- package/lib/functional.mjs +120 -0
- package/lib/functional.mjs.map +1 -0
- package/lib/http.d.ts +15 -15
- package/lib/http.mjs +165 -0
- package/lib/http.mjs.map +1 -0
- package/lib/index.mjs +27 -1142
- package/lib/index.mjs.map +1 -1
- package/lib/json.mjs +105 -0
- package/lib/json.mjs.map +1 -0
- package/lib/llm.mjs +33 -0
- package/lib/llm.mjs.map +1 -0
- package/lib/misc.mjs +111 -0
- package/lib/misc.mjs.map +1 -0
- package/lib/module.d.ts +4 -4
- package/lib/module.mjs +139 -0
- package/lib/module.mjs.map +1 -0
- package/lib/notations.mjs +153 -0
- package/lib/notations.mjs.map +1 -0
- package/lib/programmers/json/JsonApplicationProgrammer.d.ts +12 -0
- package/lib/programmers/json/JsonApplicationProgrammer.js +22 -22
- package/lib/programmers/json/JsonApplicationProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationOfValidateProgrammer.js +15 -7
- package/lib/programmers/llm/LlmApplicationOfValidateProgrammer.js.map +1 -1
- package/lib/programmers/llm/LlmApplicationProgrammer.js +39 -15
- package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
- package/lib/protobuf.d.ts +9 -9
- package/lib/protobuf.mjs +111 -0
- package/lib/protobuf.mjs.map +1 -0
- package/lib/reflect.mjs +18 -0
- package/lib/reflect.mjs.map +1 -0
- package/lib/schemas/llm/ILlmApplicationOfValidate.mjs +6 -0
- package/lib/schemas/llm/ILlmApplicationOfValidate.mjs.map +1 -0
- package/lib/schemas/llm/ILlmFunctionOfValidate.mjs +6 -0
- package/lib/schemas/llm/ILlmFunctionOfValidate.mjs.map +1 -0
- package/lib/tags/TagBase.d.ts +1 -1
- package/lib/tags/Type.d.ts +0 -1
- package/lib/tags/index.mjs +2 -0
- package/lib/tags/index.mjs.map +1 -0
- package/package.json +10 -8
- package/src/AssertionGuard.ts +1 -1
- package/src/CamelCase.ts +75 -75
- package/src/PascalCase.ts +71 -71
- package/src/Primitive.ts +92 -92
- package/src/Resolved.ts +74 -74
- package/src/SnakeCase.ts +126 -126
- package/src/TypeGuardError.ts +37 -37
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/PluginConfigurator.ts +69 -69
- package/src/executable/typia.ts +55 -55
- package/src/factories/CommentFactory.ts +79 -79
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +45 -45
- package/src/http.ts +15 -15
- package/src/index.ts +4 -4
- package/src/module.ts +4 -4
- package/src/programmers/helpers/ICheckEntry.ts +13 -13
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/ProtobufWire.ts +34 -34
- package/src/programmers/internal/stringify_native.ts +7 -7
- package/src/programmers/json/JsonApplicationProgrammer.ts +27 -27
- package/src/programmers/llm/LlmApplicationOfValidateProgrammer.ts +16 -2
- package/src/programmers/llm/LlmApplicationProgrammer.ts +50 -12
- package/src/protobuf.ts +9 -9
- package/src/schemas/metadata/IJsDocTagInfo.ts +10 -10
- package/src/schemas/metadata/IMetadataArrayType.ts +10 -10
- package/src/schemas/metadata/IMetadataAtomic.ts +6 -6
- package/src/schemas/metadata/IMetadataConstant.ts +18 -18
- package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
- package/src/schemas/metadata/IMetadataFunction.ts +8 -8
- package/src/schemas/metadata/IMetadataParameter.ts +9 -9
- package/src/schemas/metadata/IMetadataProperty.ts +9 -9
- package/src/schemas/metadata/IMetadataTupleType.ts +10 -10
- package/src/schemas/metadata/MetadataArrayType.ts +57 -57
- package/src/schemas/metadata/MetadataConstant.ts +34 -34
- package/src/schemas/metadata/MetadataEscaped.ts +51 -51
- package/src/schemas/metadata/MetadataFunction.ts +49 -49
- package/src/schemas/metadata/MetadataTupleType.ts +67 -67
- package/src/tags/Constant.ts +15 -15
- package/src/tags/ContentMediaType.ts +10 -10
- package/src/tags/Default.ts +22 -22
- package/src/tags/ExclusiveMaximum.ts +25 -25
- package/src/tags/ExclusiveMinimum.ts +25 -25
- package/src/tags/MaxItems.ts +12 -12
- package/src/tags/MaxLength.ts +12 -12
- package/src/tags/Maximum.ts +19 -19
- package/src/tags/MinItems.ts +12 -12
- package/src/tags/MinLength.ts +12 -12
- package/src/tags/Minimum.ts +19 -19
- package/src/tags/MultipleOf.ts +21 -21
- package/src/tags/Pattern.ts +31 -31
- package/src/tags/TagBase.ts +1 -1
- package/src/tags/Type.ts +0 -1
- package/src/tags/internal/FormatCheatSheet.ts +73 -73
- package/src/typings/Atomic.ts +13 -13
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.ts +5 -5
- package/src/typings/Equal.ts +18 -18
- package/src/typings/IsTuple.ts +9 -9
- package/src/typings/NativeClass.ts +23 -23
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/ProtobufAtomic.ts +19 -19
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/ValidationPipe.ts +9 -9
- package/src/typings/ValueOf.ts +20 -20
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +41 -41
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/PatternUtil.ts +29 -29
- package/src/utils/Singleton.ts +16 -16
package/src/SnakeCase.ts
CHANGED
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import { Equal } from "./typings/Equal";
|
|
2
|
-
import { NativeClass } from "./typings/NativeClass";
|
|
3
|
-
import { ValueOf } from "./typings/ValueOf";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Snake case type.
|
|
7
|
-
*
|
|
8
|
-
* `SnakeCase` type is a type that all keys of an object are converted to snake case.
|
|
9
|
-
*
|
|
10
|
-
* It also erase every method properties like {@link Resolved} type.
|
|
11
|
-
*
|
|
12
|
-
* @template T Target type to be snake cased
|
|
13
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
-
*/
|
|
15
|
-
export type SnakeCase<T> =
|
|
16
|
-
Equal<T, SnakageMain<T>> extends true ? T : SnakageMain<T>;
|
|
17
|
-
|
|
18
|
-
/* -----------------------------------------------------------
|
|
19
|
-
OBJECT CONVERSION
|
|
20
|
-
----------------------------------------------------------- */
|
|
21
|
-
|
|
22
|
-
type SnakageMain<T> = T extends [never]
|
|
23
|
-
? never // special trick for (jsonable | null) type
|
|
24
|
-
: T extends { valueOf(): boolean | bigint | number | string }
|
|
25
|
-
? ValueOf<T>
|
|
26
|
-
: T extends Function
|
|
27
|
-
? never
|
|
28
|
-
: T extends object
|
|
29
|
-
? SnakageObject<T>
|
|
30
|
-
: T;
|
|
31
|
-
|
|
32
|
-
type SnakageObject<T extends object> =
|
|
33
|
-
T extends Array<infer U>
|
|
34
|
-
? IsTuple<T> extends true
|
|
35
|
-
? SnakageTuple<T>
|
|
36
|
-
: SnakageMain<U>[]
|
|
37
|
-
: T extends Set<infer U>
|
|
38
|
-
? Set<SnakageMain<U>>
|
|
39
|
-
: T extends Map<infer K, infer V>
|
|
40
|
-
? Map<SnakageMain<K>, SnakageMain<V>>
|
|
41
|
-
: T extends WeakSet<any> | WeakMap<any, any>
|
|
42
|
-
? never
|
|
43
|
-
: T extends NativeClass
|
|
44
|
-
? T
|
|
45
|
-
: {
|
|
46
|
-
[Key in keyof T as SnakageString<Key & string>]: SnakageMain<
|
|
47
|
-
T[Key]
|
|
48
|
-
>;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/* -----------------------------------------------------------
|
|
52
|
-
SPECIAL CASES
|
|
53
|
-
----------------------------------------------------------- */
|
|
54
|
-
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
55
|
-
never,
|
|
56
|
-
]
|
|
57
|
-
? false
|
|
58
|
-
: T extends readonly any[]
|
|
59
|
-
? number extends T["length"]
|
|
60
|
-
? false
|
|
61
|
-
: true
|
|
62
|
-
: false;
|
|
63
|
-
type SnakageTuple<T extends readonly any[]> = T extends []
|
|
64
|
-
? []
|
|
65
|
-
: T extends [infer F]
|
|
66
|
-
? [SnakageMain<F>]
|
|
67
|
-
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
68
|
-
? [SnakageMain<F>, ...SnakageTuple<Rest>]
|
|
69
|
-
: T extends [(infer F)?]
|
|
70
|
-
? [SnakageMain<F>?]
|
|
71
|
-
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
72
|
-
? [SnakageMain<F>?, ...SnakageTuple<Rest>]
|
|
73
|
-
: [];
|
|
74
|
-
|
|
75
|
-
/* -----------------------------------------------------------
|
|
76
|
-
STRING CONVERTER
|
|
77
|
-
----------------------------------------------------------- */
|
|
78
|
-
type SnakageString<Key extends string> = Key extends `${infer _}`
|
|
79
|
-
? SnakageStringRepeatedly<Key, "">
|
|
80
|
-
: Key;
|
|
81
|
-
type SnakageStringRepeatedly<
|
|
82
|
-
S extends string,
|
|
83
|
-
Previous extends string,
|
|
84
|
-
> = S extends `${infer First}${infer Second}${infer Rest}`
|
|
85
|
-
? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
|
|
86
|
-
First,
|
|
87
|
-
Second
|
|
88
|
-
>}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
|
|
89
|
-
: S extends `${infer First}`
|
|
90
|
-
? `${Underscore<Previous, First>}${Lowercase<First>}`
|
|
91
|
-
: "";
|
|
92
|
-
type Underscore<First extends string, Second extends string> = First extends
|
|
93
|
-
| UpperAlphabetic
|
|
94
|
-
| ""
|
|
95
|
-
| "_"
|
|
96
|
-
? ""
|
|
97
|
-
: Second extends UpperAlphabetic
|
|
98
|
-
? "_"
|
|
99
|
-
: "";
|
|
100
|
-
type UpperAlphabetic =
|
|
101
|
-
| "A"
|
|
102
|
-
| "B"
|
|
103
|
-
| "C"
|
|
104
|
-
| "D"
|
|
105
|
-
| "E"
|
|
106
|
-
| "F"
|
|
107
|
-
| "G"
|
|
108
|
-
| "H"
|
|
109
|
-
| "I"
|
|
110
|
-
| "J"
|
|
111
|
-
| "K"
|
|
112
|
-
| "L"
|
|
113
|
-
| "M"
|
|
114
|
-
| "N"
|
|
115
|
-
| "O"
|
|
116
|
-
| "P"
|
|
117
|
-
| "Q"
|
|
118
|
-
| "R"
|
|
119
|
-
| "S"
|
|
120
|
-
| "T"
|
|
121
|
-
| "U"
|
|
122
|
-
| "V"
|
|
123
|
-
| "W"
|
|
124
|
-
| "X"
|
|
125
|
-
| "Y"
|
|
126
|
-
| "Z";
|
|
1
|
+
import { Equal } from "./typings/Equal";
|
|
2
|
+
import { NativeClass } from "./typings/NativeClass";
|
|
3
|
+
import { ValueOf } from "./typings/ValueOf";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Snake case type.
|
|
7
|
+
*
|
|
8
|
+
* `SnakeCase` type is a type that all keys of an object are converted to snake case.
|
|
9
|
+
*
|
|
10
|
+
* It also erase every method properties like {@link Resolved} type.
|
|
11
|
+
*
|
|
12
|
+
* @template T Target type to be snake cased
|
|
13
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
14
|
+
*/
|
|
15
|
+
export type SnakeCase<T> =
|
|
16
|
+
Equal<T, SnakageMain<T>> extends true ? T : SnakageMain<T>;
|
|
17
|
+
|
|
18
|
+
/* -----------------------------------------------------------
|
|
19
|
+
OBJECT CONVERSION
|
|
20
|
+
----------------------------------------------------------- */
|
|
21
|
+
|
|
22
|
+
type SnakageMain<T> = T extends [never]
|
|
23
|
+
? never // special trick for (jsonable | null) type
|
|
24
|
+
: T extends { valueOf(): boolean | bigint | number | string }
|
|
25
|
+
? ValueOf<T>
|
|
26
|
+
: T extends Function
|
|
27
|
+
? never
|
|
28
|
+
: T extends object
|
|
29
|
+
? SnakageObject<T>
|
|
30
|
+
: T;
|
|
31
|
+
|
|
32
|
+
type SnakageObject<T extends object> =
|
|
33
|
+
T extends Array<infer U>
|
|
34
|
+
? IsTuple<T> extends true
|
|
35
|
+
? SnakageTuple<T>
|
|
36
|
+
: SnakageMain<U>[]
|
|
37
|
+
: T extends Set<infer U>
|
|
38
|
+
? Set<SnakageMain<U>>
|
|
39
|
+
: T extends Map<infer K, infer V>
|
|
40
|
+
? Map<SnakageMain<K>, SnakageMain<V>>
|
|
41
|
+
: T extends WeakSet<any> | WeakMap<any, any>
|
|
42
|
+
? never
|
|
43
|
+
: T extends NativeClass
|
|
44
|
+
? T
|
|
45
|
+
: {
|
|
46
|
+
[Key in keyof T as SnakageString<Key & string>]: SnakageMain<
|
|
47
|
+
T[Key]
|
|
48
|
+
>;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/* -----------------------------------------------------------
|
|
52
|
+
SPECIAL CASES
|
|
53
|
+
----------------------------------------------------------- */
|
|
54
|
+
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
55
|
+
never,
|
|
56
|
+
]
|
|
57
|
+
? false
|
|
58
|
+
: T extends readonly any[]
|
|
59
|
+
? number extends T["length"]
|
|
60
|
+
? false
|
|
61
|
+
: true
|
|
62
|
+
: false;
|
|
63
|
+
type SnakageTuple<T extends readonly any[]> = T extends []
|
|
64
|
+
? []
|
|
65
|
+
: T extends [infer F]
|
|
66
|
+
? [SnakageMain<F>]
|
|
67
|
+
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
68
|
+
? [SnakageMain<F>, ...SnakageTuple<Rest>]
|
|
69
|
+
: T extends [(infer F)?]
|
|
70
|
+
? [SnakageMain<F>?]
|
|
71
|
+
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
72
|
+
? [SnakageMain<F>?, ...SnakageTuple<Rest>]
|
|
73
|
+
: [];
|
|
74
|
+
|
|
75
|
+
/* -----------------------------------------------------------
|
|
76
|
+
STRING CONVERTER
|
|
77
|
+
----------------------------------------------------------- */
|
|
78
|
+
type SnakageString<Key extends string> = Key extends `${infer _}`
|
|
79
|
+
? SnakageStringRepeatedly<Key, "">
|
|
80
|
+
: Key;
|
|
81
|
+
type SnakageStringRepeatedly<
|
|
82
|
+
S extends string,
|
|
83
|
+
Previous extends string,
|
|
84
|
+
> = S extends `${infer First}${infer Second}${infer Rest}`
|
|
85
|
+
? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
|
|
86
|
+
First,
|
|
87
|
+
Second
|
|
88
|
+
>}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
|
|
89
|
+
: S extends `${infer First}`
|
|
90
|
+
? `${Underscore<Previous, First>}${Lowercase<First>}`
|
|
91
|
+
: "";
|
|
92
|
+
type Underscore<First extends string, Second extends string> = First extends
|
|
93
|
+
| UpperAlphabetic
|
|
94
|
+
| ""
|
|
95
|
+
| "_"
|
|
96
|
+
? ""
|
|
97
|
+
: Second extends UpperAlphabetic
|
|
98
|
+
? "_"
|
|
99
|
+
: "";
|
|
100
|
+
type UpperAlphabetic =
|
|
101
|
+
| "A"
|
|
102
|
+
| "B"
|
|
103
|
+
| "C"
|
|
104
|
+
| "D"
|
|
105
|
+
| "E"
|
|
106
|
+
| "F"
|
|
107
|
+
| "G"
|
|
108
|
+
| "H"
|
|
109
|
+
| "I"
|
|
110
|
+
| "J"
|
|
111
|
+
| "K"
|
|
112
|
+
| "L"
|
|
113
|
+
| "M"
|
|
114
|
+
| "N"
|
|
115
|
+
| "O"
|
|
116
|
+
| "P"
|
|
117
|
+
| "Q"
|
|
118
|
+
| "R"
|
|
119
|
+
| "S"
|
|
120
|
+
| "T"
|
|
121
|
+
| "U"
|
|
122
|
+
| "V"
|
|
123
|
+
| "W"
|
|
124
|
+
| "X"
|
|
125
|
+
| "Y"
|
|
126
|
+
| "Z";
|
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
export class TypeGuardError<T = any> extends Error {
|
|
2
|
-
public readonly method: string;
|
|
3
|
-
public readonly path: string | undefined;
|
|
4
|
-
public readonly expected: string;
|
|
5
|
-
public readonly value: any;
|
|
6
|
-
protected readonly fake_expected_typed_value_?: T | undefined;
|
|
7
|
-
|
|
8
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
9
|
-
// MESSAGE CONSTRUCTION
|
|
10
|
-
super(
|
|
11
|
-
props.message ||
|
|
12
|
-
`Error on ${props.method}(): invalid type${
|
|
13
|
-
props.path ? ` on ${props.path}` : ""
|
|
14
|
-
}, expect to be ${props.expected}`,
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
// INHERITANCE POLYFILL
|
|
18
|
-
const proto = new.target.prototype;
|
|
19
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
20
|
-
else (this as any).__proto__ = proto;
|
|
21
|
-
|
|
22
|
-
// ASSIGN MEMBERS
|
|
23
|
-
this.method = props.method;
|
|
24
|
-
this.path = props.path;
|
|
25
|
-
this.expected = props.expected;
|
|
26
|
-
this.value = props.value;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export namespace TypeGuardError {
|
|
30
|
-
export interface IProps {
|
|
31
|
-
method: string;
|
|
32
|
-
path?: undefined | string;
|
|
33
|
-
expected: string;
|
|
34
|
-
value: any;
|
|
35
|
-
message?: undefined | string;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
1
|
+
export class TypeGuardError<T = any> extends Error {
|
|
2
|
+
public readonly method: string;
|
|
3
|
+
public readonly path: string | undefined;
|
|
4
|
+
public readonly expected: string;
|
|
5
|
+
public readonly value: any;
|
|
6
|
+
protected readonly fake_expected_typed_value_?: T | undefined;
|
|
7
|
+
|
|
8
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
9
|
+
// MESSAGE CONSTRUCTION
|
|
10
|
+
super(
|
|
11
|
+
props.message ||
|
|
12
|
+
`Error on ${props.method}(): invalid type${
|
|
13
|
+
props.path ? ` on ${props.path}` : ""
|
|
14
|
+
}, expect to be ${props.expected}`,
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
// INHERITANCE POLYFILL
|
|
18
|
+
const proto = new.target.prototype;
|
|
19
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
20
|
+
else (this as any).__proto__ = proto;
|
|
21
|
+
|
|
22
|
+
// ASSIGN MEMBERS
|
|
23
|
+
this.method = props.method;
|
|
24
|
+
this.path = props.path;
|
|
25
|
+
this.expected = props.expected;
|
|
26
|
+
this.value = props.value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export namespace TypeGuardError {
|
|
30
|
+
export interface IProps {
|
|
31
|
+
method: string;
|
|
32
|
+
path?: undefined | string;
|
|
33
|
+
expected: string;
|
|
34
|
+
value: any;
|
|
35
|
+
message?: undefined | string;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import cp from "child_process";
|
|
2
|
-
|
|
3
|
-
export namespace CommandExecutor {
|
|
4
|
-
export const run = (str: string): void => {
|
|
5
|
-
console.log(`\n$ ${str}`);
|
|
6
|
-
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
-
};
|
|
8
|
-
}
|
|
1
|
+
import cp from "child_process";
|
|
2
|
+
|
|
3
|
+
export namespace CommandExecutor {
|
|
4
|
+
export const run = (str: string): void => {
|
|
5
|
+
console.log(`\n$ ${str}`);
|
|
6
|
+
cp.execSync(str, { stdio: "inherit" });
|
|
7
|
+
};
|
|
8
|
+
}
|
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
import comments from "comment-json";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
import { TypiaSetupWizard } from "../TypiaSetupWizard";
|
|
5
|
-
|
|
6
|
-
export namespace PluginConfigurator {
|
|
7
|
-
export async function configure(
|
|
8
|
-
args: TypiaSetupWizard.IArguments,
|
|
9
|
-
): Promise<void> {
|
|
10
|
-
// GET COMPILER-OPTIONS
|
|
11
|
-
const config: comments.CommentObject = comments.parse(
|
|
12
|
-
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
-
) as comments.CommentObject;
|
|
14
|
-
const compilerOptions = config.compilerOptions as
|
|
15
|
-
| comments.CommentObject
|
|
16
|
-
| undefined;
|
|
17
|
-
if (compilerOptions === undefined)
|
|
18
|
-
throw new ReferenceError(
|
|
19
|
-
`${args.project} file does not have "compilerOptions" property.`,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// PREPARE PLUGINS
|
|
23
|
-
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
24
|
-
const plugins = compilerOptions.plugins as
|
|
25
|
-
| comments.CommentArray<comments.CommentObject>
|
|
26
|
-
| undefined;
|
|
27
|
-
if (plugins === undefined) return (compilerOptions.plugins = [] as any);
|
|
28
|
-
else if (!Array.isArray(plugins))
|
|
29
|
-
throw new TypeError(
|
|
30
|
-
`"plugins" property of ${args.project} must be array type.`,
|
|
31
|
-
);
|
|
32
|
-
return plugins;
|
|
33
|
-
})();
|
|
34
|
-
|
|
35
|
-
const strict: boolean | undefined = compilerOptions.strict as
|
|
36
|
-
| boolean
|
|
37
|
-
| undefined;
|
|
38
|
-
const strictNullChecks: boolean | undefined =
|
|
39
|
-
compilerOptions.strictNullChecks as boolean | undefined;
|
|
40
|
-
const oldbie: comments.CommentObject | undefined = plugins.find(
|
|
41
|
-
(p) =>
|
|
42
|
-
typeof p === "object" &&
|
|
43
|
-
p !== null &&
|
|
44
|
-
p.transform === "typia/lib/transform",
|
|
45
|
-
);
|
|
46
|
-
if (
|
|
47
|
-
strictNullChecks !== false &&
|
|
48
|
-
(strict === true || strictNullChecks === true) &&
|
|
49
|
-
oldbie !== undefined
|
|
50
|
-
)
|
|
51
|
-
return;
|
|
52
|
-
|
|
53
|
-
// DO CONFIGURE
|
|
54
|
-
compilerOptions.strictNullChecks = true;
|
|
55
|
-
if (strict === undefined && strictNullChecks === undefined)
|
|
56
|
-
compilerOptions.strict = true;
|
|
57
|
-
if (oldbie === undefined)
|
|
58
|
-
plugins.push(
|
|
59
|
-
comments.parse(`
|
|
60
|
-
{
|
|
61
|
-
"transform": "typia/lib/transform"
|
|
62
|
-
}`) as comments.CommentObject,
|
|
63
|
-
);
|
|
64
|
-
await fs.promises.writeFile(
|
|
65
|
-
args.project!,
|
|
66
|
-
comments.stringify(config, null, 2),
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
import comments from "comment-json";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
import { TypiaSetupWizard } from "../TypiaSetupWizard";
|
|
5
|
+
|
|
6
|
+
export namespace PluginConfigurator {
|
|
7
|
+
export async function configure(
|
|
8
|
+
args: TypiaSetupWizard.IArguments,
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
// GET COMPILER-OPTIONS
|
|
11
|
+
const config: comments.CommentObject = comments.parse(
|
|
12
|
+
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
+
) as comments.CommentObject;
|
|
14
|
+
const compilerOptions = config.compilerOptions as
|
|
15
|
+
| comments.CommentObject
|
|
16
|
+
| undefined;
|
|
17
|
+
if (compilerOptions === undefined)
|
|
18
|
+
throw new ReferenceError(
|
|
19
|
+
`${args.project} file does not have "compilerOptions" property.`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// PREPARE PLUGINS
|
|
23
|
+
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
24
|
+
const plugins = compilerOptions.plugins as
|
|
25
|
+
| comments.CommentArray<comments.CommentObject>
|
|
26
|
+
| undefined;
|
|
27
|
+
if (plugins === undefined) return (compilerOptions.plugins = [] as any);
|
|
28
|
+
else if (!Array.isArray(plugins))
|
|
29
|
+
throw new TypeError(
|
|
30
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
31
|
+
);
|
|
32
|
+
return plugins;
|
|
33
|
+
})();
|
|
34
|
+
|
|
35
|
+
const strict: boolean | undefined = compilerOptions.strict as
|
|
36
|
+
| boolean
|
|
37
|
+
| undefined;
|
|
38
|
+
const strictNullChecks: boolean | undefined =
|
|
39
|
+
compilerOptions.strictNullChecks as boolean | undefined;
|
|
40
|
+
const oldbie: comments.CommentObject | undefined = plugins.find(
|
|
41
|
+
(p) =>
|
|
42
|
+
typeof p === "object" &&
|
|
43
|
+
p !== null &&
|
|
44
|
+
p.transform === "typia/lib/transform",
|
|
45
|
+
);
|
|
46
|
+
if (
|
|
47
|
+
strictNullChecks !== false &&
|
|
48
|
+
(strict === true || strictNullChecks === true) &&
|
|
49
|
+
oldbie !== undefined
|
|
50
|
+
)
|
|
51
|
+
return;
|
|
52
|
+
|
|
53
|
+
// DO CONFIGURE
|
|
54
|
+
compilerOptions.strictNullChecks = true;
|
|
55
|
+
if (strict === undefined && strictNullChecks === undefined)
|
|
56
|
+
compilerOptions.strict = true;
|
|
57
|
+
if (oldbie === undefined)
|
|
58
|
+
plugins.push(
|
|
59
|
+
comments.parse(`
|
|
60
|
+
{
|
|
61
|
+
"transform": "typia/lib/transform"
|
|
62
|
+
}`) as comments.CommentObject,
|
|
63
|
+
);
|
|
64
|
+
await fs.promises.writeFile(
|
|
65
|
+
args.project!,
|
|
66
|
+
comments.stringify(config, null, 2),
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
3
|
-
|
|
4
|
-
npx typia setup \\
|
|
5
|
-
--manager (npm|pnpm|yarn) \\
|
|
6
|
-
--project {tsconfig.json file path}
|
|
7
|
-
|
|
8
|
-
- npx typia setup
|
|
9
|
-
- npx typia setup --manager pnpm
|
|
10
|
-
- npx typia setup --project tsconfig.test.json
|
|
11
|
-
|
|
12
|
-
npx typia generate
|
|
13
|
-
--input {directory} \\
|
|
14
|
-
--output {directory}
|
|
15
|
-
|
|
16
|
-
--npx typia generate --input src/templates --output src/functinoal
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
const halt = (desc: string): never => {
|
|
20
|
-
console.error(desc);
|
|
21
|
-
process.exit(-1);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const main = async (): Promise<void> => {
|
|
25
|
-
try {
|
|
26
|
-
await import("comment-json");
|
|
27
|
-
await import("inquirer");
|
|
28
|
-
await import("commander");
|
|
29
|
-
} catch {
|
|
30
|
-
halt(`typia has not been installed. Run "npm i typia" before.`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const type: string | undefined = process.argv[2];
|
|
34
|
-
if (type === "setup") {
|
|
35
|
-
const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
|
|
36
|
-
await TypiaSetupWizard.setup();
|
|
37
|
-
} else if (type === "patch") {
|
|
38
|
-
const { TypiaPatchWizard } = await import("./TypiaPatchWizard");
|
|
39
|
-
await TypiaPatchWizard.main();
|
|
40
|
-
} else if (type === "generate") {
|
|
41
|
-
try {
|
|
42
|
-
await import("typescript");
|
|
43
|
-
} catch {
|
|
44
|
-
halt(
|
|
45
|
-
`typescript has not been installed. Run "npm i -D typescript" before.`,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
|
|
49
|
-
await TypiaGenerateWizard.generate();
|
|
50
|
-
} else halt(USAGE);
|
|
51
|
-
};
|
|
52
|
-
main().catch((exp) => {
|
|
53
|
-
console.error(exp);
|
|
54
|
-
process.exit(-1);
|
|
55
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
3
|
+
|
|
4
|
+
npx typia setup \\
|
|
5
|
+
--manager (npm|pnpm|yarn) \\
|
|
6
|
+
--project {tsconfig.json file path}
|
|
7
|
+
|
|
8
|
+
- npx typia setup
|
|
9
|
+
- npx typia setup --manager pnpm
|
|
10
|
+
- npx typia setup --project tsconfig.test.json
|
|
11
|
+
|
|
12
|
+
npx typia generate
|
|
13
|
+
--input {directory} \\
|
|
14
|
+
--output {directory}
|
|
15
|
+
|
|
16
|
+
--npx typia generate --input src/templates --output src/functinoal
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const halt = (desc: string): never => {
|
|
20
|
+
console.error(desc);
|
|
21
|
+
process.exit(-1);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const main = async (): Promise<void> => {
|
|
25
|
+
try {
|
|
26
|
+
await import("comment-json");
|
|
27
|
+
await import("inquirer");
|
|
28
|
+
await import("commander");
|
|
29
|
+
} catch {
|
|
30
|
+
halt(`typia has not been installed. Run "npm i typia" before.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const type: string | undefined = process.argv[2];
|
|
34
|
+
if (type === "setup") {
|
|
35
|
+
const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
|
|
36
|
+
await TypiaSetupWizard.setup();
|
|
37
|
+
} else if (type === "patch") {
|
|
38
|
+
const { TypiaPatchWizard } = await import("./TypiaPatchWizard");
|
|
39
|
+
await TypiaPatchWizard.main();
|
|
40
|
+
} else if (type === "generate") {
|
|
41
|
+
try {
|
|
42
|
+
await import("typescript");
|
|
43
|
+
} catch {
|
|
44
|
+
halt(
|
|
45
|
+
`typescript has not been installed. Run "npm i -D typescript" before.`,
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
|
|
49
|
+
await TypiaGenerateWizard.generate();
|
|
50
|
+
} else halt(USAGE);
|
|
51
|
+
};
|
|
52
|
+
main().catch((exp) => {
|
|
53
|
+
console.error(exp);
|
|
54
|
+
process.exit(-1);
|
|
55
|
+
});
|