typia 5.2.6 → 5.2.7-dev.20231109
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/factories/ExpressionFactory.js +14 -16
- package/lib/factories/ExpressionFactory.js.map +1 -1
- package/lib/factories/JsonMetadataFactory.d.ts +1 -1
- package/lib/factories/JsonMetadataFactory.js +2 -2
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/factories/LiteralFactory.js +2 -0
- package/lib/factories/LiteralFactory.js.map +1 -1
- package/lib/factories/MetadataFactory.d.ts +1 -1
- package/lib/factories/MetadataFactory.js +233 -168
- package/lib/factories/MetadataFactory.js.map +1 -1
- package/lib/factories/NumericRangeFactory.d.ts +2 -2
- package/lib/factories/NumericRangeFactory.js +41 -21
- package/lib/factories/NumericRangeFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.d.ts +1 -1
- package/lib/factories/ProtobufFactory.js +2 -2
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +11 -16
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +1 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
- package/lib/programmers/internal/application_array.js +8 -0
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_number.js +8 -1
- package/lib/programmers/internal/application_number.js.map +1 -1
- package/lib/programmers/internal/application_string.js +8 -1
- package/lib/programmers/internal/application_string.js.map +1 -1
- package/lib/programmers/internal/check_array_length.js +7 -4
- package/lib/programmers/internal/check_array_length.js.map +1 -1
- package/lib/programmers/internal/check_bigint.js +7 -4
- package/lib/programmers/internal/check_bigint.js.map +1 -1
- package/lib/programmers/internal/check_number.js +7 -4
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/programmers/internal/check_string.js.map +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +3 -8
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +19 -24
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +11 -16
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +11 -16
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js +38 -42
- package/lib/programmers/protobuf/ProtobufEncodeProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.d.ts +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +22 -25
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/schemas/json/IJsonSchema.d.ts +1 -0
- package/lib/schemas/metadata/Metadata.js +1 -6
- package/lib/schemas/metadata/Metadata.js.map +1 -1
- package/lib/schemas/metadata/MetadataAtomic.d.ts +2 -0
- package/lib/schemas/metadata/MetadataAtomic.js +15 -0
- package/lib/schemas/metadata/MetadataAtomic.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.d.ts +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js +4 -5
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/misc/MetadataTransformer.d.ts +1 -1
- package/lib/transformers/features/misc/MetadataTransformer.js +3 -4
- package/lib/transformers/features/misc/MetadataTransformer.js.map +1 -1
- package/package.json +2 -2
- package/src/Primitive.ts +135 -135
- package/src/executable/TypiaSetupWizard.ts +142 -142
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/factories/ExpressionFactory.ts +12 -13
- package/src/factories/JsonMetadataFactory.ts +53 -50
- package/src/factories/LiteralFactory.ts +2 -0
- package/src/factories/MetadataCollection.ts +282 -282
- package/src/factories/MetadataFactory.ts +48 -18
- package/src/factories/NumericRangeFactory.ts +56 -17
- package/src/factories/ProtobufFactory.ts +5 -2
- package/src/factories/internal/metadata/emplace_metadata_object.ts +178 -178
- package/src/functional/$stoll.ts +8 -8
- package/src/functional/Namespace.ts +168 -168
- package/src/programmers/AssertProgrammer.ts +322 -322
- package/src/programmers/CheckerProgrammer.ts +16 -17
- package/src/programmers/IsProgrammer.ts +258 -258
- package/src/programmers/RandomProgrammer.ts +4 -1
- package/src/programmers/ValidateProgrammer.ts +350 -350
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/http/HttpHeadersProgrammer.ts +4 -1
- package/src/programmers/http/HttpParameterProgrammer.ts +4 -1
- package/src/programmers/http/HttpQueryProgrammer.ts +4 -1
- package/src/programmers/internal/application_array.ts +8 -0
- package/src/programmers/internal/application_number.ts +8 -1
- package/src/programmers/internal/application_string.ts +8 -1
- package/src/programmers/internal/check_array_length.ts +5 -2
- package/src/programmers/internal/check_bigint.ts +5 -2
- package/src/programmers/internal/check_dynamic_key.ts +178 -178
- package/src/programmers/internal/check_dynamic_properties.ts +202 -202
- package/src/programmers/internal/check_number.ts +5 -2
- package/src/programmers/internal/check_object.ts +62 -62
- package/src/programmers/internal/check_string.ts +0 -1
- package/src/programmers/json/JsonAssertParseProgrammer.ts +1 -0
- package/src/programmers/json/JsonIsParseProgrammer.ts +1 -0
- package/src/programmers/json/JsonStringifyProgrammer.ts +959 -960
- package/src/programmers/json/JsonValidateParseProgrammer.ts +1 -0
- package/src/programmers/misc/MiscCloneProgrammer.ts +787 -786
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +549 -548
- package/src/programmers/notations/NotationGeneralProgrammer.ts +717 -716
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -0
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +872 -882
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +21 -21
- package/src/schemas/json/IJsonSchema.ts +1 -0
- package/src/schemas/metadata/IMetadataTypeTag.ts +7 -0
- package/src/schemas/metadata/Metadata.ts +1 -6
- package/src/schemas/metadata/MetadataAtomic.ts +17 -0
- package/src/transform.ts +35 -35
- package/src/transformers/features/json/JsonApplicationTransformer.ts +7 -4
- package/src/transformers/features/misc/MetadataTransformer.ts +6 -3
package/src/Primitive.ts
CHANGED
|
@@ -1,135 +1,135 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Primitive type of JSON.
|
|
3
|
-
*
|
|
4
|
-
* `Primitive<T>` is a TMP (Type Meta Programming) type which converts
|
|
5
|
-
* its argument as a primitive type within framework JSON.
|
|
6
|
-
*
|
|
7
|
-
* If the target argument is a built-in class which returns its origin primitive type
|
|
8
|
-
* through the `valueOf()` method like the `String` or `Number`, its return type would
|
|
9
|
-
* be the `string` or `number`. Otherwise, the built-in class does not have the
|
|
10
|
-
* `valueOf()` method, the return type would be an empty object (`{}`).
|
|
11
|
-
*
|
|
12
|
-
* Otherwise, the target argument is a type of custom class, all of its custom method
|
|
13
|
-
* would be erased and its prototype would be changed to the primitive `object`.
|
|
14
|
-
* Therefore, return type of the TMP type finally be the primitive object.
|
|
15
|
-
*
|
|
16
|
-
* In addition, if the target argument is a type of custom class and it has a special
|
|
17
|
-
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
18
|
-
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
19
|
-
*
|
|
20
|
-
* Before | After
|
|
21
|
-
* ------------------------|----------------------------------------
|
|
22
|
-
* `Boolean` | `boolean`
|
|
23
|
-
* `Number` | `number`
|
|
24
|
-
* `String` | `string`
|
|
25
|
-
* `Class` | `object`
|
|
26
|
-
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
27
|
-
* Native Class | never
|
|
28
|
-
* Others | No change
|
|
29
|
-
*
|
|
30
|
-
* @template T Target argument type.
|
|
31
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
-
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
33
|
-
* @author Michael - https://github.com/8471919
|
|
34
|
-
*/
|
|
35
|
-
export type Primitive<T> = Equal<T, PrimitiveMain<T>> extends true
|
|
36
|
-
? T
|
|
37
|
-
: PrimitiveMain<T>;
|
|
38
|
-
|
|
39
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
40
|
-
|
|
41
|
-
type PrimitiveMain<Instance> = Instance extends [never]
|
|
42
|
-
? never // (special trick for jsonable | null) type
|
|
43
|
-
: ValueOf<Instance> extends bigint
|
|
44
|
-
? never
|
|
45
|
-
: ValueOf<Instance> extends boolean | number | string
|
|
46
|
-
? ValueOf<Instance>
|
|
47
|
-
: Instance extends Function
|
|
48
|
-
? never
|
|
49
|
-
: ValueOf<Instance> extends object
|
|
50
|
-
? Instance extends object
|
|
51
|
-
? Instance extends NativeClass
|
|
52
|
-
? never
|
|
53
|
-
: Instance extends IJsonable<infer Raw>
|
|
54
|
-
? ValueOf<Raw> extends object
|
|
55
|
-
? Raw extends object
|
|
56
|
-
? PrimitiveObject<Raw> // object would be primitified
|
|
57
|
-
: never // cannot be
|
|
58
|
-
: ValueOf<Raw> // atomic value
|
|
59
|
-
: PrimitiveObject<Instance> // object would be primitified
|
|
60
|
-
: never // cannot be
|
|
61
|
-
: ValueOf<Instance>;
|
|
62
|
-
|
|
63
|
-
type PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
64
|
-
? IsTuple<Instance> extends true
|
|
65
|
-
? PrimitiveTuple<Instance>
|
|
66
|
-
: PrimitiveMain<T>[]
|
|
67
|
-
: {
|
|
68
|
-
[P in keyof Instance]: PrimitiveMain<Instance[P]>;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
72
|
-
? []
|
|
73
|
-
: T extends [infer F]
|
|
74
|
-
? [PrimitiveMain<F>]
|
|
75
|
-
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
76
|
-
? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>]
|
|
77
|
-
: T extends [(infer F)?]
|
|
78
|
-
? [PrimitiveMain<F>?]
|
|
79
|
-
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
80
|
-
? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>]
|
|
81
|
-
: [];
|
|
82
|
-
|
|
83
|
-
type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
|
|
84
|
-
? boolean
|
|
85
|
-
: IsValueOf<Instance, Number> extends true
|
|
86
|
-
? number
|
|
87
|
-
: IsValueOf<Instance, String> extends true
|
|
88
|
-
? string
|
|
89
|
-
: Instance;
|
|
90
|
-
|
|
91
|
-
type NativeClass =
|
|
92
|
-
| Set<any>
|
|
93
|
-
| Map<any, any>
|
|
94
|
-
| WeakSet<any>
|
|
95
|
-
| WeakMap<any, any>
|
|
96
|
-
| Uint8Array
|
|
97
|
-
| Uint8ClampedArray
|
|
98
|
-
| Uint16Array
|
|
99
|
-
| Uint32Array
|
|
100
|
-
| BigUint64Array
|
|
101
|
-
| Int8Array
|
|
102
|
-
| Int16Array
|
|
103
|
-
| Int32Array
|
|
104
|
-
| BigInt64Array
|
|
105
|
-
| Float32Array
|
|
106
|
-
| Float64Array
|
|
107
|
-
| ArrayBuffer
|
|
108
|
-
| SharedArrayBuffer
|
|
109
|
-
| DataView;
|
|
110
|
-
|
|
111
|
-
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
112
|
-
never,
|
|
113
|
-
]
|
|
114
|
-
? false
|
|
115
|
-
: T extends readonly any[]
|
|
116
|
-
? number extends T["length"]
|
|
117
|
-
? false
|
|
118
|
-
: true
|
|
119
|
-
: false;
|
|
120
|
-
|
|
121
|
-
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
122
|
-
? Object extends IValueOf<infer U>
|
|
123
|
-
? Instance extends U
|
|
124
|
-
? false
|
|
125
|
-
: true // not Primitive, but Object
|
|
126
|
-
: false // cannot be
|
|
127
|
-
: false;
|
|
128
|
-
|
|
129
|
-
interface IValueOf<T> {
|
|
130
|
-
valueOf(): T;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
interface IJsonable<T> {
|
|
134
|
-
toJSON(): T;
|
|
135
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Primitive type of JSON.
|
|
3
|
+
*
|
|
4
|
+
* `Primitive<T>` is a TMP (Type Meta Programming) type which converts
|
|
5
|
+
* its argument as a primitive type within framework JSON.
|
|
6
|
+
*
|
|
7
|
+
* If the target argument is a built-in class which returns its origin primitive type
|
|
8
|
+
* through the `valueOf()` method like the `String` or `Number`, its return type would
|
|
9
|
+
* be the `string` or `number`. Otherwise, the built-in class does not have the
|
|
10
|
+
* `valueOf()` method, the return type would be an empty object (`{}`).
|
|
11
|
+
*
|
|
12
|
+
* Otherwise, the target argument is a type of custom class, all of its custom method
|
|
13
|
+
* would be erased and its prototype would be changed to the primitive `object`.
|
|
14
|
+
* Therefore, return type of the TMP type finally be the primitive object.
|
|
15
|
+
*
|
|
16
|
+
* In addition, if the target argument is a type of custom class and it has a special
|
|
17
|
+
* method `toJSON()`, return type of this `Primitive` would be not `Primitive<Instance>`
|
|
18
|
+
* but `Primitive<ReturnType<Instance.toJSON>>`.
|
|
19
|
+
*
|
|
20
|
+
* Before | After
|
|
21
|
+
* ------------------------|----------------------------------------
|
|
22
|
+
* `Boolean` | `boolean`
|
|
23
|
+
* `Number` | `number`
|
|
24
|
+
* `String` | `string`
|
|
25
|
+
* `Class` | `object`
|
|
26
|
+
* `Class` with `toJSON()` | `Primitive<ReturnType<Class.toJSON>>`
|
|
27
|
+
* Native Class | never
|
|
28
|
+
* Others | No change
|
|
29
|
+
*
|
|
30
|
+
* @template T Target argument type.
|
|
31
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
32
|
+
* @author Kyungsu Kang - https://github.com/kakasoo
|
|
33
|
+
* @author Michael - https://github.com/8471919
|
|
34
|
+
*/
|
|
35
|
+
export type Primitive<T> = Equal<T, PrimitiveMain<T>> extends true
|
|
36
|
+
? T
|
|
37
|
+
: PrimitiveMain<T>;
|
|
38
|
+
|
|
39
|
+
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
40
|
+
|
|
41
|
+
type PrimitiveMain<Instance> = Instance extends [never]
|
|
42
|
+
? never // (special trick for jsonable | null) type
|
|
43
|
+
: ValueOf<Instance> extends bigint
|
|
44
|
+
? never
|
|
45
|
+
: ValueOf<Instance> extends boolean | number | string
|
|
46
|
+
? ValueOf<Instance>
|
|
47
|
+
: Instance extends Function
|
|
48
|
+
? never
|
|
49
|
+
: ValueOf<Instance> extends object
|
|
50
|
+
? Instance extends object
|
|
51
|
+
? Instance extends NativeClass
|
|
52
|
+
? never
|
|
53
|
+
: Instance extends IJsonable<infer Raw>
|
|
54
|
+
? ValueOf<Raw> extends object
|
|
55
|
+
? Raw extends object
|
|
56
|
+
? PrimitiveObject<Raw> // object would be primitified
|
|
57
|
+
: never // cannot be
|
|
58
|
+
: ValueOf<Raw> // atomic value
|
|
59
|
+
: PrimitiveObject<Instance> // object would be primitified
|
|
60
|
+
: never // cannot be
|
|
61
|
+
: ValueOf<Instance>;
|
|
62
|
+
|
|
63
|
+
type PrimitiveObject<Instance extends object> = Instance extends Array<infer T>
|
|
64
|
+
? IsTuple<Instance> extends true
|
|
65
|
+
? PrimitiveTuple<Instance>
|
|
66
|
+
: PrimitiveMain<T>[]
|
|
67
|
+
: {
|
|
68
|
+
[P in keyof Instance]: PrimitiveMain<Instance[P]>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
type PrimitiveTuple<T extends readonly any[]> = T extends []
|
|
72
|
+
? []
|
|
73
|
+
: T extends [infer F]
|
|
74
|
+
? [PrimitiveMain<F>]
|
|
75
|
+
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
76
|
+
? [PrimitiveMain<F>, ...PrimitiveTuple<Rest>]
|
|
77
|
+
: T extends [(infer F)?]
|
|
78
|
+
? [PrimitiveMain<F>?]
|
|
79
|
+
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
80
|
+
? [PrimitiveMain<F>?, ...PrimitiveTuple<Rest>]
|
|
81
|
+
: [];
|
|
82
|
+
|
|
83
|
+
type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
|
|
84
|
+
? boolean
|
|
85
|
+
: IsValueOf<Instance, Number> extends true
|
|
86
|
+
? number
|
|
87
|
+
: IsValueOf<Instance, String> extends true
|
|
88
|
+
? string
|
|
89
|
+
: Instance;
|
|
90
|
+
|
|
91
|
+
type NativeClass =
|
|
92
|
+
| Set<any>
|
|
93
|
+
| Map<any, any>
|
|
94
|
+
| WeakSet<any>
|
|
95
|
+
| WeakMap<any, any>
|
|
96
|
+
| Uint8Array
|
|
97
|
+
| Uint8ClampedArray
|
|
98
|
+
| Uint16Array
|
|
99
|
+
| Uint32Array
|
|
100
|
+
| BigUint64Array
|
|
101
|
+
| Int8Array
|
|
102
|
+
| Int16Array
|
|
103
|
+
| Int32Array
|
|
104
|
+
| BigInt64Array
|
|
105
|
+
| Float32Array
|
|
106
|
+
| Float64Array
|
|
107
|
+
| ArrayBuffer
|
|
108
|
+
| SharedArrayBuffer
|
|
109
|
+
| DataView;
|
|
110
|
+
|
|
111
|
+
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
112
|
+
never,
|
|
113
|
+
]
|
|
114
|
+
? false
|
|
115
|
+
: T extends readonly any[]
|
|
116
|
+
? number extends T["length"]
|
|
117
|
+
? false
|
|
118
|
+
: true
|
|
119
|
+
: false;
|
|
120
|
+
|
|
121
|
+
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
122
|
+
? Object extends IValueOf<infer U>
|
|
123
|
+
? Instance extends U
|
|
124
|
+
? false
|
|
125
|
+
: true // not Primitive, but Object
|
|
126
|
+
: false // cannot be
|
|
127
|
+
: false;
|
|
128
|
+
|
|
129
|
+
interface IValueOf<T> {
|
|
130
|
+
valueOf(): T;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
interface IJsonable<T> {
|
|
134
|
+
toJSON(): T;
|
|
135
|
+
}
|
|
@@ -1,142 +1,142 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
|
|
3
|
-
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
4
|
-
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
5
|
-
import { PackageManager } from "./setup/PackageManager";
|
|
6
|
-
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
7
|
-
|
|
8
|
-
export namespace TypiaSetupWizard {
|
|
9
|
-
export interface IArguments {
|
|
10
|
-
manager: "npm" | "pnpm" | "yarn";
|
|
11
|
-
project: string | null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export async function setup(): Promise<void> {
|
|
15
|
-
console.log("----------------------------------------");
|
|
16
|
-
console.log(" Typia Setup Wizard");
|
|
17
|
-
console.log("----------------------------------------");
|
|
18
|
-
|
|
19
|
-
// PREPARE ASSETS
|
|
20
|
-
const pack: PackageManager = await PackageManager.mount();
|
|
21
|
-
const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
|
|
22
|
-
|
|
23
|
-
// INSTALL TYPESCRIPT COMPILERS
|
|
24
|
-
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
25
|
-
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
26
|
-
pack.install({ dev: true, modulo: "typescript", version: "5.2.2" });
|
|
27
|
-
args.project ??= (() => {
|
|
28
|
-
const runner: string =
|
|
29
|
-
pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
-
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
-
return (args.project = "tsconfig.json");
|
|
32
|
-
})();
|
|
33
|
-
|
|
34
|
-
// SETUP TRANSFORMER
|
|
35
|
-
await pack.save((data) => {
|
|
36
|
-
// COMPOSE PREPARE COMMAND
|
|
37
|
-
data.scripts ??= {};
|
|
38
|
-
if (
|
|
39
|
-
typeof data.scripts.prepare === "string" &&
|
|
40
|
-
data.scripts.prepare.trim().length
|
|
41
|
-
) {
|
|
42
|
-
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
43
|
-
data.scripts.prepare =
|
|
44
|
-
"ts-patch install && " + data.scripts.prepare;
|
|
45
|
-
} else data.scripts.prepare = "ts-patch install";
|
|
46
|
-
|
|
47
|
-
// FOR OLDER VERSIONS
|
|
48
|
-
if (typeof data.scripts.postinstall === "string") {
|
|
49
|
-
data.scripts.postinstall = data.scripts.postinstall
|
|
50
|
-
.split("&&")
|
|
51
|
-
.map((str) => str.trim())
|
|
52
|
-
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
53
|
-
.join(" && ");
|
|
54
|
-
if (data.scripts.postinstall.length === 0)
|
|
55
|
-
delete data.scripts.postinstall;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
59
|
-
|
|
60
|
-
// CONFIGURE TYPIA
|
|
61
|
-
await PluginConfigurator.configure(args);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
65
|
-
pack,
|
|
66
|
-
command,
|
|
67
|
-
prompt,
|
|
68
|
-
action,
|
|
69
|
-
) => {
|
|
70
|
-
// PREPARE ASSETS
|
|
71
|
-
command.option("--manager [manager", "package manager");
|
|
72
|
-
command.option("--project [project]", "tsconfig.json file location");
|
|
73
|
-
|
|
74
|
-
// INTERNAL PROCEDURES
|
|
75
|
-
const questioned = { value: false };
|
|
76
|
-
const select =
|
|
77
|
-
(name: string) =>
|
|
78
|
-
(message: string) =>
|
|
79
|
-
async <Choice extends string>(
|
|
80
|
-
choices: Choice[],
|
|
81
|
-
filter?: (choice: string) => Choice,
|
|
82
|
-
): Promise<Choice> => {
|
|
83
|
-
questioned.value = true;
|
|
84
|
-
return (
|
|
85
|
-
await prompt()({
|
|
86
|
-
type: "list",
|
|
87
|
-
name: name,
|
|
88
|
-
message: message,
|
|
89
|
-
choices: choices,
|
|
90
|
-
...(filter
|
|
91
|
-
? {
|
|
92
|
-
filter,
|
|
93
|
-
}
|
|
94
|
-
: {}),
|
|
95
|
-
})
|
|
96
|
-
)[name];
|
|
97
|
-
};
|
|
98
|
-
const configure = async (): Promise<string | null> => {
|
|
99
|
-
const fileList: string[] = await (
|
|
100
|
-
await fs.promises.readdir(process.cwd())
|
|
101
|
-
)
|
|
102
|
-
.filter(
|
|
103
|
-
(str) =>
|
|
104
|
-
str.substring(0, 8) === "tsconfig" &&
|
|
105
|
-
str.substring(str.length - 5) === ".json",
|
|
106
|
-
)
|
|
107
|
-
.sort((x, y) =>
|
|
108
|
-
x === "tsconfig.json"
|
|
109
|
-
? -1
|
|
110
|
-
: y === "tsconfig.json"
|
|
111
|
-
? 1
|
|
112
|
-
: x < y
|
|
113
|
-
? -1
|
|
114
|
-
: 1,
|
|
115
|
-
);
|
|
116
|
-
if (fileList.length === 0) {
|
|
117
|
-
if (process.cwd() !== pack.directory)
|
|
118
|
-
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
119
|
-
return null;
|
|
120
|
-
} else if (fileList.length === 1) return fileList[0]!;
|
|
121
|
-
return select("tsconfig")("TS Config File")(fileList);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// DO CONSTRUCT
|
|
125
|
-
return action(async (options) => {
|
|
126
|
-
pack.manager = options.manager ??= await select("manager")(
|
|
127
|
-
"Package Manager",
|
|
128
|
-
)(
|
|
129
|
-
[
|
|
130
|
-
"npm" as const,
|
|
131
|
-
"pnpm" as const,
|
|
132
|
-
"yarn (berry is not supported)" as "yarn",
|
|
133
|
-
],
|
|
134
|
-
(value) => value.split(" ")[0] as "yarn",
|
|
135
|
-
);
|
|
136
|
-
options.project ??= await configure();
|
|
137
|
-
|
|
138
|
-
if (questioned.value) console.log("");
|
|
139
|
-
return options as IArguments;
|
|
140
|
-
});
|
|
141
|
-
};
|
|
142
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
|
|
3
|
+
import { ArgumentParser } from "./setup/ArgumentParser";
|
|
4
|
+
import { CommandExecutor } from "./setup/CommandExecutor";
|
|
5
|
+
import { PackageManager } from "./setup/PackageManager";
|
|
6
|
+
import { PluginConfigurator } from "./setup/PluginConfigurator";
|
|
7
|
+
|
|
8
|
+
export namespace TypiaSetupWizard {
|
|
9
|
+
export interface IArguments {
|
|
10
|
+
manager: "npm" | "pnpm" | "yarn";
|
|
11
|
+
project: string | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export async function setup(): Promise<void> {
|
|
15
|
+
console.log("----------------------------------------");
|
|
16
|
+
console.log(" Typia Setup Wizard");
|
|
17
|
+
console.log("----------------------------------------");
|
|
18
|
+
|
|
19
|
+
// PREPARE ASSETS
|
|
20
|
+
const pack: PackageManager = await PackageManager.mount();
|
|
21
|
+
const args: IArguments = await ArgumentParser.parse(pack)(inquiry);
|
|
22
|
+
|
|
23
|
+
// INSTALL TYPESCRIPT COMPILERS
|
|
24
|
+
pack.install({ dev: true, modulo: "ts-patch", version: "latest" });
|
|
25
|
+
pack.install({ dev: true, modulo: "ts-node", version: "latest" });
|
|
26
|
+
pack.install({ dev: true, modulo: "typescript", version: "5.2.2" });
|
|
27
|
+
args.project ??= (() => {
|
|
28
|
+
const runner: string =
|
|
29
|
+
pack.manager === "npm" ? "npx" : pack.manager;
|
|
30
|
+
CommandExecutor.run(`${runner} tsc --init`);
|
|
31
|
+
return (args.project = "tsconfig.json");
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
// SETUP TRANSFORMER
|
|
35
|
+
await pack.save((data) => {
|
|
36
|
+
// COMPOSE PREPARE COMMAND
|
|
37
|
+
data.scripts ??= {};
|
|
38
|
+
if (
|
|
39
|
+
typeof data.scripts.prepare === "string" &&
|
|
40
|
+
data.scripts.prepare.trim().length
|
|
41
|
+
) {
|
|
42
|
+
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
43
|
+
data.scripts.prepare =
|
|
44
|
+
"ts-patch install && " + data.scripts.prepare;
|
|
45
|
+
} else data.scripts.prepare = "ts-patch install";
|
|
46
|
+
|
|
47
|
+
// FOR OLDER VERSIONS
|
|
48
|
+
if (typeof data.scripts.postinstall === "string") {
|
|
49
|
+
data.scripts.postinstall = data.scripts.postinstall
|
|
50
|
+
.split("&&")
|
|
51
|
+
.map((str) => str.trim())
|
|
52
|
+
.filter((str) => str.indexOf("ts-patch install") === -1)
|
|
53
|
+
.join(" && ");
|
|
54
|
+
if (data.scripts.postinstall.length === 0)
|
|
55
|
+
delete data.scripts.postinstall;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
59
|
+
|
|
60
|
+
// CONFIGURE TYPIA
|
|
61
|
+
await PluginConfigurator.configure(args);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const inquiry: ArgumentParser.Inquiry<IArguments> = async (
|
|
65
|
+
pack,
|
|
66
|
+
command,
|
|
67
|
+
prompt,
|
|
68
|
+
action,
|
|
69
|
+
) => {
|
|
70
|
+
// PREPARE ASSETS
|
|
71
|
+
command.option("--manager [manager", "package manager");
|
|
72
|
+
command.option("--project [project]", "tsconfig.json file location");
|
|
73
|
+
|
|
74
|
+
// INTERNAL PROCEDURES
|
|
75
|
+
const questioned = { value: false };
|
|
76
|
+
const select =
|
|
77
|
+
(name: string) =>
|
|
78
|
+
(message: string) =>
|
|
79
|
+
async <Choice extends string>(
|
|
80
|
+
choices: Choice[],
|
|
81
|
+
filter?: (choice: string) => Choice,
|
|
82
|
+
): Promise<Choice> => {
|
|
83
|
+
questioned.value = true;
|
|
84
|
+
return (
|
|
85
|
+
await prompt()({
|
|
86
|
+
type: "list",
|
|
87
|
+
name: name,
|
|
88
|
+
message: message,
|
|
89
|
+
choices: choices,
|
|
90
|
+
...(filter
|
|
91
|
+
? {
|
|
92
|
+
filter,
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
})
|
|
96
|
+
)[name];
|
|
97
|
+
};
|
|
98
|
+
const configure = async (): Promise<string | null> => {
|
|
99
|
+
const fileList: string[] = await (
|
|
100
|
+
await fs.promises.readdir(process.cwd())
|
|
101
|
+
)
|
|
102
|
+
.filter(
|
|
103
|
+
(str) =>
|
|
104
|
+
str.substring(0, 8) === "tsconfig" &&
|
|
105
|
+
str.substring(str.length - 5) === ".json",
|
|
106
|
+
)
|
|
107
|
+
.sort((x, y) =>
|
|
108
|
+
x === "tsconfig.json"
|
|
109
|
+
? -1
|
|
110
|
+
: y === "tsconfig.json"
|
|
111
|
+
? 1
|
|
112
|
+
: x < y
|
|
113
|
+
? -1
|
|
114
|
+
: 1,
|
|
115
|
+
);
|
|
116
|
+
if (fileList.length === 0) {
|
|
117
|
+
if (process.cwd() !== pack.directory)
|
|
118
|
+
throw new URIError(`Unable to find "tsconfig.json" file.`);
|
|
119
|
+
return null;
|
|
120
|
+
} else if (fileList.length === 1) return fileList[0]!;
|
|
121
|
+
return select("tsconfig")("TS Config File")(fileList);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// DO CONSTRUCT
|
|
125
|
+
return action(async (options) => {
|
|
126
|
+
pack.manager = options.manager ??= await select("manager")(
|
|
127
|
+
"Package Manager",
|
|
128
|
+
)(
|
|
129
|
+
[
|
|
130
|
+
"npm" as const,
|
|
131
|
+
"pnpm" as const,
|
|
132
|
+
"yarn (berry is not supported)" as "yarn",
|
|
133
|
+
],
|
|
134
|
+
(value) => value.split(" ")[0] as "yarn",
|
|
135
|
+
);
|
|
136
|
+
options.project ??= await configure();
|
|
137
|
+
|
|
138
|
+
if (questioned.value) console.log("");
|
|
139
|
+
return options as IArguments;
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -133,9 +133,7 @@ export namespace ExpressionFactory {
|
|
|
133
133
|
);
|
|
134
134
|
|
|
135
135
|
export const transpile =
|
|
136
|
-
(context: ts.TransformationContext) =>
|
|
137
|
-
(script: string) =>
|
|
138
|
-
(input: ts.Expression): ts.Expression => {
|
|
136
|
+
(context: ts.TransformationContext) => (script: string) => {
|
|
139
137
|
const file: ts.SourceFile = ts.createSourceFile(
|
|
140
138
|
`${RandomGenerator.uuid()}.ts`,
|
|
141
139
|
script,
|
|
@@ -152,16 +150,17 @@ export namespace ExpressionFactory {
|
|
|
152
150
|
throw new TypeError(
|
|
153
151
|
"Error on ExpressionFactory.transpile(): statement is not an expression statement.",
|
|
154
152
|
);
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
153
|
+
return (input: ts.Expression): ts.Expression => {
|
|
154
|
+
const visitor = (node: ts.Node): ts.Node => {
|
|
155
|
+
if (ts.isIdentifier(node) && node.text === "$input")
|
|
156
|
+
return input;
|
|
157
|
+
return ts.visitEachChild(
|
|
158
|
+
(ts.factory as any).cloneNode(node),
|
|
159
|
+
visitor,
|
|
160
|
+
context,
|
|
161
|
+
);
|
|
162
|
+
};
|
|
163
|
+
return visitor(statement.expression) as ts.Expression;
|
|
164
164
|
};
|
|
165
|
-
return visitor(statement.expression) as ts.Expression;
|
|
166
165
|
};
|
|
167
166
|
}
|