typia 3.5.0-dev.20221222 → 3.5.0-dev.20230107
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 +5 -2
- package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
- package/lib/executable/internal/TypiaSetupWizard.js +23 -22
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/typia.js +11 -10
- package/lib/executable/typia.js.map +1 -1
- package/lib/metadata/Metadata.js +32 -29
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +1 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +1 -0
- package/lib/programmers/CheckerProgrammer.js +147 -138
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +1 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
- package/lib/programmers/helpers/UnionExplorer.js +29 -41
- package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +2 -0
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_array.js +4 -32
- package/lib/programmers/internal/check_array.js.map +1 -1
- package/lib/programmers/internal/check_array_length.d.ts +1 -0
- package/lib/programmers/internal/check_array_length.js +47 -0
- package/lib/programmers/internal/check_array_length.js.map +1 -0
- package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
- package/lib/programmers/internal/check_union_array_like.js +83 -0
- package/lib/programmers/internal/check_union_array_like.js.map +1 -0
- package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
- package/lib/programmers/internal/check_union_tuple.js +11 -0
- package/lib/programmers/internal/check_union_tuple.js.map +1 -0
- package/package.json +4 -4
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/TypiaSetupWizard.ts +30 -21
- package/src/executable/typia.ts +48 -46
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/Metadata.ts +10 -7
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +1 -1
- package/src/programmers/CheckerProgrammer.ts +252 -200
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/ValidateProgrammer.ts +1 -1
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +274 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_schema.ts +5 -0
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +25 -25
- package/src/programmers/internal/check_array.ts +22 -44
- package/src/programmers/internal/check_array_length.ts +45 -0
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/check_union_array_like.ts +242 -0
- package/src/programmers/internal/check_union_tuple.ts +33 -0
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -0
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
package/src/Primitive.ts
CHANGED
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
-
* primitive type.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
-
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
-
* `string` or `number`.
|
|
10
|
-
*
|
|
11
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
-
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
-
* type of the TMP type finally be the primitive object.
|
|
14
|
-
*
|
|
15
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
-
*
|
|
19
|
-
* Before | After
|
|
20
|
-
* ------------------------|----------------------------------------
|
|
21
|
-
* `Boolean` | `boolean`
|
|
22
|
-
* `Number` | `number`
|
|
23
|
-
* `String` | `string`
|
|
24
|
-
* `Class` | `object`
|
|
25
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
-
* Others | No change
|
|
27
|
-
*
|
|
28
|
-
* @template Instance Target argument type.
|
|
29
|
-
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
-
*/
|
|
31
|
-
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
-
? T
|
|
33
|
-
: _Primitive<T>;
|
|
34
|
-
|
|
35
|
-
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
-
|
|
37
|
-
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
-
? Instance extends object
|
|
39
|
-
? Instance extends IJsonable<infer Raw>
|
|
40
|
-
? _ValueOf<Raw> extends object
|
|
41
|
-
? Raw extends object
|
|
42
|
-
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
-
: never // cannot be
|
|
44
|
-
: _ValueOf<Raw> // atomic value
|
|
45
|
-
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
-
: never // cannot be
|
|
47
|
-
: _ValueOf<Instance>;
|
|
48
|
-
|
|
49
|
-
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
-
? _Primitive<T>[]
|
|
51
|
-
: {
|
|
52
|
-
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
-
? never
|
|
54
|
-
: _Primitive<Instance[P]>;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
-
? boolean
|
|
59
|
-
: _IsValueOf<Instance, Number> extends true
|
|
60
|
-
? number
|
|
61
|
-
: _IsValueOf<Instance, String> extends true
|
|
62
|
-
? string
|
|
63
|
-
: Instance;
|
|
64
|
-
|
|
65
|
-
type _IsValueOf<
|
|
66
|
-
Instance,
|
|
67
|
-
Object extends IValueOf<any>,
|
|
68
|
-
> = Instance extends Object
|
|
69
|
-
? Object extends IValueOf<infer Primitive>
|
|
70
|
-
? Instance extends Primitive
|
|
71
|
-
? false
|
|
72
|
-
: true // not Primitive, but Object
|
|
73
|
-
: false // cannot be
|
|
74
|
-
: false;
|
|
75
|
-
|
|
76
|
-
interface IValueOf<T> {
|
|
77
|
-
valueOf(): T;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface IJsonable<T> {
|
|
81
|
-
toJSON(): T;
|
|
82
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive` is a type of TMP (Type Meta Programming) type who converts its argument as a
|
|
5
|
+
* primitive type.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class who returns its origin primitive type through
|
|
8
|
+
* the `valueOf()` method like the `String` or `Number`, its return type would be the
|
|
9
|
+
* `string` or `number`.
|
|
10
|
+
*
|
|
11
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method would
|
|
12
|
+
* be erased and its prototype would be changed to the primitive `object`. Therefore, return
|
|
13
|
+
* type of the TMP type finally be the primitive object.
|
|
14
|
+
*
|
|
15
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
16
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
17
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
18
|
+
*
|
|
19
|
+
* Before | After
|
|
20
|
+
* ------------------------|----------------------------------------
|
|
21
|
+
* `Boolean` | `boolean`
|
|
22
|
+
* `Number` | `number`
|
|
23
|
+
* `String` | `string`
|
|
24
|
+
* `Class` | `object`
|
|
25
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
26
|
+
* Others | No change
|
|
27
|
+
*
|
|
28
|
+
* @template Instance Target argument type.
|
|
29
|
+
* @author Jenogho Nam - https://github.com/samchon
|
|
30
|
+
*/
|
|
31
|
+
export type Primitive<T> = _Equal<T, _Primitive<T>> extends true
|
|
32
|
+
? T
|
|
33
|
+
: _Primitive<T>;
|
|
34
|
+
|
|
35
|
+
type _Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
36
|
+
|
|
37
|
+
type _Primitive<Instance> = _ValueOf<Instance> extends object
|
|
38
|
+
? Instance extends object
|
|
39
|
+
? Instance extends IJsonable<infer Raw>
|
|
40
|
+
? _ValueOf<Raw> extends object
|
|
41
|
+
? Raw extends object
|
|
42
|
+
? _PrimitiveObject<Raw> // object would be primitified
|
|
43
|
+
: never // cannot be
|
|
44
|
+
: _ValueOf<Raw> // atomic value
|
|
45
|
+
: _PrimitiveObject<Instance> // object would be primitified
|
|
46
|
+
: never // cannot be
|
|
47
|
+
: _ValueOf<Instance>;
|
|
48
|
+
|
|
49
|
+
type _PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
50
|
+
? _Primitive<T>[]
|
|
51
|
+
: {
|
|
52
|
+
[P in keyof Instance]: Instance[P] extends Function
|
|
53
|
+
? never
|
|
54
|
+
: _Primitive<Instance[P]>;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
type _ValueOf<Instance> = _IsValueOf<Instance, Boolean> extends true
|
|
58
|
+
? boolean
|
|
59
|
+
: _IsValueOf<Instance, Number> extends true
|
|
60
|
+
? number
|
|
61
|
+
: _IsValueOf<Instance, String> extends true
|
|
62
|
+
? string
|
|
63
|
+
: Instance;
|
|
64
|
+
|
|
65
|
+
type _IsValueOf<
|
|
66
|
+
Instance,
|
|
67
|
+
Object extends IValueOf<any>,
|
|
68
|
+
> = Instance extends Object
|
|
69
|
+
? Object extends IValueOf<infer Primitive>
|
|
70
|
+
? Instance extends Primitive
|
|
71
|
+
? false
|
|
72
|
+
: true // not Primitive, but Object
|
|
73
|
+
: false // cannot be
|
|
74
|
+
: false;
|
|
75
|
+
|
|
76
|
+
interface IValueOf<T> {
|
|
77
|
+
valueOf(): T;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
interface IJsonable<T> {
|
|
81
|
+
toJSON(): T;
|
|
82
|
+
}
|
package/src/TypeGuardError.ts
CHANGED
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
export class TypeGuardError extends Error {
|
|
2
|
-
public readonly method: string;
|
|
3
|
-
public readonly path: string | undefined;
|
|
4
|
-
public readonly expected: string;
|
|
5
|
-
public readonly value: any;
|
|
6
|
-
|
|
7
|
-
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
-
// MESSAGE CONSTRUCTION
|
|
9
|
-
super(
|
|
10
|
-
props.message ||
|
|
11
|
-
`Error on ${props.method}(): invalid type${
|
|
12
|
-
props.path ? ` on ${props.path}` : ""
|
|
13
|
-
}, expect to be ${props.expected}`,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
// INHERITANCE POLYFILL
|
|
17
|
-
const proto = new.target.prototype;
|
|
18
|
-
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
-
else (this as any).__proto__ = proto;
|
|
20
|
-
|
|
21
|
-
// ASSIGN MEMBERS
|
|
22
|
-
this.method = props.method;
|
|
23
|
-
this.path = props.path;
|
|
24
|
-
this.expected = props.expected;
|
|
25
|
-
this.value = props.value;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export namespace TypeGuardError {
|
|
29
|
-
export interface IProps {
|
|
30
|
-
method: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
expected: string;
|
|
33
|
-
value: any;
|
|
34
|
-
message?: string;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
1
|
+
export class TypeGuardError extends Error {
|
|
2
|
+
public readonly method: string;
|
|
3
|
+
public readonly path: string | undefined;
|
|
4
|
+
public readonly expected: string;
|
|
5
|
+
public readonly value: any;
|
|
6
|
+
|
|
7
|
+
public constructor(props: TypeGuardError.IProps) {
|
|
8
|
+
// MESSAGE CONSTRUCTION
|
|
9
|
+
super(
|
|
10
|
+
props.message ||
|
|
11
|
+
`Error on ${props.method}(): invalid type${
|
|
12
|
+
props.path ? ` on ${props.path}` : ""
|
|
13
|
+
}, expect to be ${props.expected}`,
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
// INHERITANCE POLYFILL
|
|
17
|
+
const proto = new.target.prototype;
|
|
18
|
+
if (Object.setPrototypeOf) Object.setPrototypeOf(this, proto);
|
|
19
|
+
else (this as any).__proto__ = proto;
|
|
20
|
+
|
|
21
|
+
// ASSIGN MEMBERS
|
|
22
|
+
this.method = props.method;
|
|
23
|
+
this.path = props.path;
|
|
24
|
+
this.expected = props.expected;
|
|
25
|
+
this.value = props.value;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export namespace TypeGuardError {
|
|
29
|
+
export interface IProps {
|
|
30
|
+
method: string;
|
|
31
|
+
path?: string;
|
|
32
|
+
expected: string;
|
|
33
|
+
value: any;
|
|
34
|
+
message?: string;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
export namespace CommandParser {
|
|
2
|
-
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
-
const output: Record<string, string> = {};
|
|
4
|
-
argList.forEach((arg, i) => {
|
|
5
|
-
if (arg.startsWith("--") === false) return;
|
|
6
|
-
|
|
7
|
-
const key = arg.slice(2);
|
|
8
|
-
const value: string | undefined = argList[i + 1];
|
|
9
|
-
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
-
|
|
11
|
-
output[key] = value;
|
|
12
|
-
});
|
|
13
|
-
return output;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
1
|
+
export namespace CommandParser {
|
|
2
|
+
export function parse(argList: string[]): Record<string, string> {
|
|
3
|
+
const output: Record<string, string> = {};
|
|
4
|
+
argList.forEach((arg, i) => {
|
|
5
|
+
if (arg.startsWith("--") === false) return;
|
|
6
|
+
|
|
7
|
+
const key = arg.slice(2);
|
|
8
|
+
const value: string | undefined = argList[i + 1];
|
|
9
|
+
if (value === undefined || value.startsWith("--")) return;
|
|
10
|
+
|
|
11
|
+
output[key] = value;
|
|
12
|
+
});
|
|
13
|
+
return output;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -3,19 +3,24 @@ import type Comment from "comment-json";
|
|
|
3
3
|
import fs from "fs";
|
|
4
4
|
|
|
5
5
|
export namespace TypiaSetupWizard {
|
|
6
|
-
export
|
|
6
|
+
export interface IArguments {
|
|
7
|
+
manager: "npm" | "pnpm" | "yarn";
|
|
8
|
+
project: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function ttypescript(args: IArguments): Promise<void> {
|
|
7
12
|
// INSTALL
|
|
8
|
-
const pack: any = await prepare(manager);
|
|
9
|
-
add(manager)(pack)("ttypescript", true);
|
|
10
|
-
add(manager)(pack)("ts-node", true);
|
|
13
|
+
const pack: any = await prepare(args.manager);
|
|
14
|
+
add(args.manager)(pack)("ttypescript", true);
|
|
15
|
+
add(args.manager)(pack)("ts-node", true);
|
|
11
16
|
|
|
12
17
|
// TSCONFIG.JSON
|
|
13
|
-
await configure(
|
|
18
|
+
await configure(args)(pack);
|
|
14
19
|
}
|
|
15
20
|
|
|
16
|
-
export async function tsPatch(
|
|
21
|
+
export async function tsPatch(args: IArguments): Promise<void> {
|
|
17
22
|
// INSTALL
|
|
18
|
-
add(manager)(await prepare(manager))("ts-patch", true);
|
|
23
|
+
add(args.manager)(await prepare(args.manager))("ts-patch", true);
|
|
19
24
|
execute("npx ts-patch install");
|
|
20
25
|
|
|
21
26
|
// PACKAGE.JSON
|
|
@@ -37,7 +42,7 @@ export namespace TypiaSetupWizard {
|
|
|
37
42
|
);
|
|
38
43
|
|
|
39
44
|
// TSCONFIG.JSON
|
|
40
|
-
await configure(
|
|
45
|
+
await configure(args)(pack);
|
|
41
46
|
}
|
|
42
47
|
|
|
43
48
|
async function prepare(manager: string): Promise<any> {
|
|
@@ -54,22 +59,25 @@ export namespace TypiaSetupWizard {
|
|
|
54
59
|
}
|
|
55
60
|
|
|
56
61
|
const configure =
|
|
57
|
-
(
|
|
62
|
+
(args: IArguments) =>
|
|
58
63
|
async (pack: any): Promise<void> => {
|
|
59
64
|
// VALIDATE PRERATATION
|
|
60
|
-
if (fs.existsSync(
|
|
61
|
-
execute("npx tsc --init");
|
|
62
|
-
if (fs.existsSync(
|
|
63
|
-
halt(() => {})(
|
|
65
|
+
if (fs.existsSync(args.project) === false) {
|
|
66
|
+
if (args.project === "tsconfig.json") execute("npx tsc --init");
|
|
67
|
+
if (fs.existsSync(args.project) === false)
|
|
68
|
+
halt(() => {})(`${args.project} file does not exist.`);
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
// INSTALL COMMENT-JSON FOR A WHILE
|
|
66
72
|
const temporary: boolean = !fs.existsSync(
|
|
67
73
|
"node_modules/comment-json",
|
|
68
74
|
);
|
|
69
|
-
if (temporary === true)
|
|
75
|
+
if (temporary === true)
|
|
76
|
+
add(args.manager)(pack)("comment-json", true);
|
|
70
77
|
|
|
71
78
|
const halter: (msg: string) => never = halt(() => {
|
|
72
|
-
if (temporary === true)
|
|
79
|
+
if (temporary === true)
|
|
80
|
+
remove(args.manager)("comment-json", true);
|
|
73
81
|
});
|
|
74
82
|
|
|
75
83
|
// READ TSCONFIG FILE
|
|
@@ -77,16 +85,17 @@ export namespace TypiaSetupWizard {
|
|
|
77
85
|
process.cwd() + "/node_modules/comment-json"
|
|
78
86
|
);
|
|
79
87
|
const config: Comment.CommentObject = Comment.parse(
|
|
80
|
-
await fs.promises.readFile(
|
|
88
|
+
await fs.promises.readFile(args.project, "utf8"),
|
|
81
89
|
) as Comment.CommentObject;
|
|
82
90
|
const options = config.compilerOptions as
|
|
83
91
|
| Comment.CommentObject
|
|
84
92
|
| undefined;
|
|
85
93
|
if (options === undefined)
|
|
86
94
|
halter(
|
|
87
|
-
|
|
95
|
+
`${args.project} file does not have "compilerOptions" property.`,
|
|
88
96
|
);
|
|
89
97
|
|
|
98
|
+
// PREPARE PLUGINS
|
|
90
99
|
const plugins: Comment.CommentArray<Comment.CommentObject> =
|
|
91
100
|
(() => {
|
|
92
101
|
const plugins = options.plugins as
|
|
@@ -96,7 +105,7 @@ export namespace TypiaSetupWizard {
|
|
|
96
105
|
return (options.plugins = [] as any);
|
|
97
106
|
else if (!Array.isArray(plugins))
|
|
98
107
|
halter(
|
|
99
|
-
`"plugins" property of
|
|
108
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
100
109
|
);
|
|
101
110
|
return plugins;
|
|
102
111
|
})();
|
|
@@ -112,7 +121,7 @@ export namespace TypiaSetupWizard {
|
|
|
112
121
|
|
|
113
122
|
if (strict === true && oldbie !== undefined) {
|
|
114
123
|
console.log(
|
|
115
|
-
|
|
124
|
+
`you've been already configured the ${args.project} file.`,
|
|
116
125
|
);
|
|
117
126
|
} else {
|
|
118
127
|
// DO CONFIGURE
|
|
@@ -125,11 +134,11 @@ export namespace TypiaSetupWizard {
|
|
|
125
134
|
}`) as Comment.CommentObject,
|
|
126
135
|
);
|
|
127
136
|
await fs.promises.writeFile(
|
|
128
|
-
|
|
137
|
+
args.project,
|
|
129
138
|
Comment.stringify(config, null, 2),
|
|
130
139
|
);
|
|
131
140
|
}
|
|
132
|
-
if (temporary === true) remove(manager)("comment-json", false);
|
|
141
|
+
if (temporary === true) remove(args.manager)("comment-json", false);
|
|
133
142
|
};
|
|
134
143
|
}
|
|
135
144
|
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,46 +1,48 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { CommandParser } from "./internal/CommandParser";
|
|
3
|
-
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
4
|
-
|
|
5
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
|
-
|
|
7
|
-
npx typia setup \\
|
|
8
|
-
--compiler (ttypescript|ts-patch) \\
|
|
9
|
-
--manager (npm|pnpm|yarn)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
- npx typia setup
|
|
13
|
-
- npx typia setup --compiler ts-patch
|
|
14
|
-
- npx typia setup --manager pnpm
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
else
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { CommandParser } from "./internal/CommandParser";
|
|
3
|
+
import { TypiaSetupWizard } from "./internal/TypiaSetupWizard";
|
|
4
|
+
|
|
5
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
6
|
+
|
|
7
|
+
npx typia setup \\
|
|
8
|
+
--compiler (ttypescript|ts-patch) \\
|
|
9
|
+
--manager (npm|pnpm|yarn) \\
|
|
10
|
+
--project {tsconfig.json file path}
|
|
11
|
+
|
|
12
|
+
- npx typia setup
|
|
13
|
+
- npx typia setup --compiler ts-patch
|
|
14
|
+
- npx typia setup --manager pnpm
|
|
15
|
+
- npx typia setup --project tsconfig.test.json`;
|
|
16
|
+
|
|
17
|
+
function halt(desc: string): never {
|
|
18
|
+
console.error(desc);
|
|
19
|
+
process.exit(-1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
async function setup(): Promise<void> {
|
|
23
|
+
const options: Record<string, string> = CommandParser.parse(
|
|
24
|
+
process.argv.slice(3),
|
|
25
|
+
);
|
|
26
|
+
const manager: string = options.manager ?? "npm";
|
|
27
|
+
const compiler: string = options.compiler ?? "ttypescript";
|
|
28
|
+
const project: string = options.project ?? "tsconfig.json";
|
|
29
|
+
|
|
30
|
+
if (
|
|
31
|
+
(compiler !== "ttypescript" && compiler !== "ts-patch") ||
|
|
32
|
+
(manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
|
|
33
|
+
)
|
|
34
|
+
halt(USAGE);
|
|
35
|
+
else if (compiler === "ttypescript")
|
|
36
|
+
await TypiaSetupWizard.ttypescript({ manager, project });
|
|
37
|
+
else await TypiaSetupWizard.tsPatch({ manager, project });
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function main(): Promise<void> {
|
|
41
|
+
const type: string | undefined = process.argv[2];
|
|
42
|
+
if (type === "setup") await setup();
|
|
43
|
+
else halt(USAGE);
|
|
44
|
+
}
|
|
45
|
+
main().catch((exp) => {
|
|
46
|
+
console.error(exp);
|
|
47
|
+
process.exit(-1);
|
|
48
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
-
return comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
}
|
|
10
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export function generate(comments: ts.SymbolDisplayPart[]): string {
|
|
5
|
+
return comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
}
|
|
10
|
+
}
|
|
@@ -1,66 +1,66 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
-
return ts.factory.createStrictInequality(
|
|
6
|
-
ts.factory.createIdentifier("undefined"),
|
|
7
|
-
input,
|
|
8
|
-
);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
-
return ts.factory.createCallExpression(
|
|
13
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
-
undefined,
|
|
15
|
-
[input],
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function isObject(
|
|
20
|
-
input: ts.Expression,
|
|
21
|
-
options: {
|
|
22
|
-
checkNull: boolean;
|
|
23
|
-
checkArray: boolean;
|
|
24
|
-
},
|
|
25
|
-
): ts.Expression {
|
|
26
|
-
const conditions: ts.Expression[] = [
|
|
27
|
-
ts.factory.createStrictEquality(
|
|
28
|
-
ts.factory.createStringLiteral("object"),
|
|
29
|
-
ts.factory.createTypeOfExpression(input),
|
|
30
|
-
),
|
|
31
|
-
];
|
|
32
|
-
if (options.checkNull === true)
|
|
33
|
-
conditions.push(
|
|
34
|
-
ts.factory.createStrictInequality(
|
|
35
|
-
ts.factory.createNull(),
|
|
36
|
-
input,
|
|
37
|
-
),
|
|
38
|
-
);
|
|
39
|
-
if (options.checkArray === true)
|
|
40
|
-
conditions.push(
|
|
41
|
-
ts.factory.createStrictEquality(
|
|
42
|
-
ts.factory.createFalse(),
|
|
43
|
-
ts.factory.createCallExpression(
|
|
44
|
-
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
-
undefined,
|
|
46
|
-
[input],
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
return conditions.length === 1
|
|
52
|
-
? conditions[0]!
|
|
53
|
-
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function isInstanceOf(
|
|
57
|
-
input: ts.Expression,
|
|
58
|
-
type: string,
|
|
59
|
-
): ts.Expression {
|
|
60
|
-
return ts.factory.createBinaryExpression(
|
|
61
|
-
input,
|
|
62
|
-
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
-
ts.factory.createIdentifier(type),
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export function isRequired(input: ts.Expression): ts.Expression {
|
|
5
|
+
return ts.factory.createStrictInequality(
|
|
6
|
+
ts.factory.createIdentifier("undefined"),
|
|
7
|
+
input,
|
|
8
|
+
);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function isArray(input: ts.Expression): ts.Expression {
|
|
12
|
+
return ts.factory.createCallExpression(
|
|
13
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
14
|
+
undefined,
|
|
15
|
+
[input],
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function isObject(
|
|
20
|
+
input: ts.Expression,
|
|
21
|
+
options: {
|
|
22
|
+
checkNull: boolean;
|
|
23
|
+
checkArray: boolean;
|
|
24
|
+
},
|
|
25
|
+
): ts.Expression {
|
|
26
|
+
const conditions: ts.Expression[] = [
|
|
27
|
+
ts.factory.createStrictEquality(
|
|
28
|
+
ts.factory.createStringLiteral("object"),
|
|
29
|
+
ts.factory.createTypeOfExpression(input),
|
|
30
|
+
),
|
|
31
|
+
];
|
|
32
|
+
if (options.checkNull === true)
|
|
33
|
+
conditions.push(
|
|
34
|
+
ts.factory.createStrictInequality(
|
|
35
|
+
ts.factory.createNull(),
|
|
36
|
+
input,
|
|
37
|
+
),
|
|
38
|
+
);
|
|
39
|
+
if (options.checkArray === true)
|
|
40
|
+
conditions.push(
|
|
41
|
+
ts.factory.createStrictEquality(
|
|
42
|
+
ts.factory.createFalse(),
|
|
43
|
+
ts.factory.createCallExpression(
|
|
44
|
+
ts.factory.createIdentifier("Array.isArray"),
|
|
45
|
+
undefined,
|
|
46
|
+
[input],
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
return conditions.length === 1
|
|
52
|
+
? conditions[0]!
|
|
53
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function isInstanceOf(
|
|
57
|
+
input: ts.Expression,
|
|
58
|
+
type: string,
|
|
59
|
+
): ts.Expression {
|
|
60
|
+
return ts.factory.createBinaryExpression(
|
|
61
|
+
input,
|
|
62
|
+
ts.factory.createToken(ts.SyntaxKind.InstanceOfKeyword),
|
|
63
|
+
ts.factory.createIdentifier(type),
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
}
|