typia 5.2.1 → 5.2.2-dev.20231012
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/executable/TypiaSetupWizard.js +8 -8
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/MetadataCollection.js +4 -3
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/package.json +2 -2
- package/src/CamelCase.ts +116 -116
- package/src/PascalCase.ts +116 -116
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/SnakeCase.ts +156 -156
- package/src/executable/TypiaSetupWizard.ts +9 -11
- package/src/factories/MetadataCollection.ts +6 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +150 -150
- package/src/functional/$clone.ts +4 -4
- package/src/functional/$convention.ts +40 -40
- package/src/functional/Namespace.ts +164 -164
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +662 -662
- package/src/notations.ts +855 -855
- package/src/programmers/IsProgrammer.ts +252 -252
- package/src/programmers/TypiaProgrammer.ts +169 -169
- package/src/programmers/helpers/NotationJoiner.ts +146 -146
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/json/JsonStringifyProgrammer.ts +964 -964
- package/src/programmers/misc/MiscCloneProgrammer.ts +790 -790
- package/src/programmers/misc/MiscPruneProgrammer.ts +552 -552
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +72 -72
- package/src/programmers/notations/NotationGeneralProgrammer.ts +720 -720
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +79 -79
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +88 -88
- package/src/protobuf.ts +887 -887
- package/src/transformers/CallExpressionTransformer.ts +380 -380
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
- package/src/utils/NamingConvention.ts +91 -91
- package/src/utils/StringUtil.ts +4 -4
package/src/SnakeCase.ts
CHANGED
|
@@ -1,156 +1,156 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Snake case type.
|
|
3
|
-
*
|
|
4
|
-
* `SnakeCase` type is a type that all keys of an object are converted to snake case.
|
|
5
|
-
*
|
|
6
|
-
* It also erase every method properties like {@link Resolved} type.
|
|
7
|
-
*
|
|
8
|
-
* @template T Target type to be snake cased
|
|
9
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
-
*/
|
|
11
|
-
export type SnakeCase<T> = Equal<T, SnakageMain<T>> extends true
|
|
12
|
-
? T
|
|
13
|
-
: SnakageMain<T>;
|
|
14
|
-
|
|
15
|
-
/* -----------------------------------------------------------
|
|
16
|
-
OBJECT CONVERSION
|
|
17
|
-
----------------------------------------------------------- */
|
|
18
|
-
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
19
|
-
|
|
20
|
-
type SnakageMain<T> = T extends [never]
|
|
21
|
-
? never // special trick for (jsonable | null) type
|
|
22
|
-
: T extends { valueOf(): boolean | bigint | number | string }
|
|
23
|
-
? ValueOf<T>
|
|
24
|
-
: T extends Function
|
|
25
|
-
? never
|
|
26
|
-
: T extends object
|
|
27
|
-
? SnakageObject<T>
|
|
28
|
-
: T;
|
|
29
|
-
|
|
30
|
-
type SnakageObject<T extends object> = T extends Array<infer U>
|
|
31
|
-
? IsTuple<T> extends true
|
|
32
|
-
? SnakageTuple<T>
|
|
33
|
-
: SnakageMain<U>[]
|
|
34
|
-
: T extends Set<infer U>
|
|
35
|
-
? Set<SnakageMain<U>>
|
|
36
|
-
: T extends Map<infer K, infer V>
|
|
37
|
-
? Map<SnakageMain<K>, SnakageMain<V>>
|
|
38
|
-
: T extends WeakSet<any> | WeakMap<any, any>
|
|
39
|
-
? never
|
|
40
|
-
: T extends
|
|
41
|
-
| Date
|
|
42
|
-
| Uint8Array
|
|
43
|
-
| Uint8ClampedArray
|
|
44
|
-
| Uint16Array
|
|
45
|
-
| Uint32Array
|
|
46
|
-
| BigUint64Array
|
|
47
|
-
| Int8Array
|
|
48
|
-
| Int16Array
|
|
49
|
-
| Int32Array
|
|
50
|
-
| BigInt64Array
|
|
51
|
-
| Float32Array
|
|
52
|
-
| Float64Array
|
|
53
|
-
| ArrayBuffer
|
|
54
|
-
| SharedArrayBuffer
|
|
55
|
-
| DataView
|
|
56
|
-
? T
|
|
57
|
-
: {
|
|
58
|
-
[Key in keyof T as SnakageString<Key & string>]: SnakageMain<T[Key]>;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/* -----------------------------------------------------------
|
|
62
|
-
SPECIAL CASES
|
|
63
|
-
----------------------------------------------------------- */
|
|
64
|
-
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
65
|
-
never,
|
|
66
|
-
]
|
|
67
|
-
? false
|
|
68
|
-
: T extends readonly any[]
|
|
69
|
-
? number extends T["length"]
|
|
70
|
-
? false
|
|
71
|
-
: true
|
|
72
|
-
: false;
|
|
73
|
-
type SnakageTuple<T extends readonly any[]> = T extends []
|
|
74
|
-
? []
|
|
75
|
-
: T extends [infer F]
|
|
76
|
-
? [SnakageMain<F>]
|
|
77
|
-
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
78
|
-
? [SnakageMain<F>, ...SnakageTuple<Rest>]
|
|
79
|
-
: T extends [(infer F)?]
|
|
80
|
-
? [SnakageMain<F>?]
|
|
81
|
-
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
82
|
-
? [SnakageMain<F>?, ...SnakageTuple<Rest>]
|
|
83
|
-
: [];
|
|
84
|
-
|
|
85
|
-
type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
|
|
86
|
-
? boolean
|
|
87
|
-
: IsValueOf<Instance, Number> extends true
|
|
88
|
-
? number
|
|
89
|
-
: IsValueOf<Instance, String> extends true
|
|
90
|
-
? string
|
|
91
|
-
: Instance;
|
|
92
|
-
|
|
93
|
-
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
94
|
-
? Object extends IValueOf<infer Primitive>
|
|
95
|
-
? Instance extends Primitive
|
|
96
|
-
? false
|
|
97
|
-
: true // not Primitive, but Object
|
|
98
|
-
: false // cannot be
|
|
99
|
-
: false;
|
|
100
|
-
|
|
101
|
-
interface IValueOf<T> {
|
|
102
|
-
valueOf(): T;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/* -----------------------------------------------------------
|
|
106
|
-
STRING CONVERTER
|
|
107
|
-
----------------------------------------------------------- */
|
|
108
|
-
type SnakageString<Key extends string> = Key extends `${infer _}`
|
|
109
|
-
? SnakageStringRepeatedly<Key, "">
|
|
110
|
-
: Key;
|
|
111
|
-
type SnakageStringRepeatedly<
|
|
112
|
-
S extends string,
|
|
113
|
-
Previous extends string,
|
|
114
|
-
> = S extends `${infer First}${infer Second}${infer Rest}`
|
|
115
|
-
? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
|
|
116
|
-
First,
|
|
117
|
-
Second
|
|
118
|
-
>}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
|
|
119
|
-
: S extends `${infer First}`
|
|
120
|
-
? `${Underscore<Previous, First>}${Lowercase<First>}`
|
|
121
|
-
: "";
|
|
122
|
-
type Underscore<First extends string, Second extends string> = First extends
|
|
123
|
-
| UpperAlphabetic
|
|
124
|
-
| ""
|
|
125
|
-
| "_"
|
|
126
|
-
? ""
|
|
127
|
-
: Second extends UpperAlphabetic
|
|
128
|
-
? "_"
|
|
129
|
-
: "";
|
|
130
|
-
type UpperAlphabetic =
|
|
131
|
-
| "A"
|
|
132
|
-
| "B"
|
|
133
|
-
| "C"
|
|
134
|
-
| "D"
|
|
135
|
-
| "E"
|
|
136
|
-
| "F"
|
|
137
|
-
| "G"
|
|
138
|
-
| "H"
|
|
139
|
-
| "I"
|
|
140
|
-
| "J"
|
|
141
|
-
| "K"
|
|
142
|
-
| "L"
|
|
143
|
-
| "M"
|
|
144
|
-
| "N"
|
|
145
|
-
| "O"
|
|
146
|
-
| "P"
|
|
147
|
-
| "Q"
|
|
148
|
-
| "R"
|
|
149
|
-
| "S"
|
|
150
|
-
| "T"
|
|
151
|
-
| "U"
|
|
152
|
-
| "V"
|
|
153
|
-
| "W"
|
|
154
|
-
| "X"
|
|
155
|
-
| "Y"
|
|
156
|
-
| "Z";
|
|
1
|
+
/**
|
|
2
|
+
* Snake case type.
|
|
3
|
+
*
|
|
4
|
+
* `SnakeCase` type is a type that all keys of an object are converted to snake case.
|
|
5
|
+
*
|
|
6
|
+
* It also erase every method properties like {@link Resolved} type.
|
|
7
|
+
*
|
|
8
|
+
* @template T Target type to be snake cased
|
|
9
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
10
|
+
*/
|
|
11
|
+
export type SnakeCase<T> = Equal<T, SnakageMain<T>> extends true
|
|
12
|
+
? T
|
|
13
|
+
: SnakageMain<T>;
|
|
14
|
+
|
|
15
|
+
/* -----------------------------------------------------------
|
|
16
|
+
OBJECT CONVERSION
|
|
17
|
+
----------------------------------------------------------- */
|
|
18
|
+
type Equal<X, Y> = X extends Y ? (Y extends X ? true : false) : false;
|
|
19
|
+
|
|
20
|
+
type SnakageMain<T> = T extends [never]
|
|
21
|
+
? never // special trick for (jsonable | null) type
|
|
22
|
+
: T extends { valueOf(): boolean | bigint | number | string }
|
|
23
|
+
? ValueOf<T>
|
|
24
|
+
: T extends Function
|
|
25
|
+
? never
|
|
26
|
+
: T extends object
|
|
27
|
+
? SnakageObject<T>
|
|
28
|
+
: T;
|
|
29
|
+
|
|
30
|
+
type SnakageObject<T extends object> = T extends Array<infer U>
|
|
31
|
+
? IsTuple<T> extends true
|
|
32
|
+
? SnakageTuple<T>
|
|
33
|
+
: SnakageMain<U>[]
|
|
34
|
+
: T extends Set<infer U>
|
|
35
|
+
? Set<SnakageMain<U>>
|
|
36
|
+
: T extends Map<infer K, infer V>
|
|
37
|
+
? Map<SnakageMain<K>, SnakageMain<V>>
|
|
38
|
+
: T extends WeakSet<any> | WeakMap<any, any>
|
|
39
|
+
? never
|
|
40
|
+
: T extends
|
|
41
|
+
| Date
|
|
42
|
+
| Uint8Array
|
|
43
|
+
| Uint8ClampedArray
|
|
44
|
+
| Uint16Array
|
|
45
|
+
| Uint32Array
|
|
46
|
+
| BigUint64Array
|
|
47
|
+
| Int8Array
|
|
48
|
+
| Int16Array
|
|
49
|
+
| Int32Array
|
|
50
|
+
| BigInt64Array
|
|
51
|
+
| Float32Array
|
|
52
|
+
| Float64Array
|
|
53
|
+
| ArrayBuffer
|
|
54
|
+
| SharedArrayBuffer
|
|
55
|
+
| DataView
|
|
56
|
+
? T
|
|
57
|
+
: {
|
|
58
|
+
[Key in keyof T as SnakageString<Key & string>]: SnakageMain<T[Key]>;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/* -----------------------------------------------------------
|
|
62
|
+
SPECIAL CASES
|
|
63
|
+
----------------------------------------------------------- */
|
|
64
|
+
type IsTuple<T extends readonly any[] | { length: number }> = [T] extends [
|
|
65
|
+
never,
|
|
66
|
+
]
|
|
67
|
+
? false
|
|
68
|
+
: T extends readonly any[]
|
|
69
|
+
? number extends T["length"]
|
|
70
|
+
? false
|
|
71
|
+
: true
|
|
72
|
+
: false;
|
|
73
|
+
type SnakageTuple<T extends readonly any[]> = T extends []
|
|
74
|
+
? []
|
|
75
|
+
: T extends [infer F]
|
|
76
|
+
? [SnakageMain<F>]
|
|
77
|
+
: T extends [infer F, ...infer Rest extends readonly any[]]
|
|
78
|
+
? [SnakageMain<F>, ...SnakageTuple<Rest>]
|
|
79
|
+
: T extends [(infer F)?]
|
|
80
|
+
? [SnakageMain<F>?]
|
|
81
|
+
: T extends [(infer F)?, ...infer Rest extends readonly any[]]
|
|
82
|
+
? [SnakageMain<F>?, ...SnakageTuple<Rest>]
|
|
83
|
+
: [];
|
|
84
|
+
|
|
85
|
+
type ValueOf<Instance> = IsValueOf<Instance, Boolean> extends true
|
|
86
|
+
? boolean
|
|
87
|
+
: IsValueOf<Instance, Number> extends true
|
|
88
|
+
? number
|
|
89
|
+
: IsValueOf<Instance, String> extends true
|
|
90
|
+
? string
|
|
91
|
+
: Instance;
|
|
92
|
+
|
|
93
|
+
type IsValueOf<Instance, Object extends IValueOf<any>> = Instance extends Object
|
|
94
|
+
? Object extends IValueOf<infer Primitive>
|
|
95
|
+
? Instance extends Primitive
|
|
96
|
+
? false
|
|
97
|
+
: true // not Primitive, but Object
|
|
98
|
+
: false // cannot be
|
|
99
|
+
: false;
|
|
100
|
+
|
|
101
|
+
interface IValueOf<T> {
|
|
102
|
+
valueOf(): T;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/* -----------------------------------------------------------
|
|
106
|
+
STRING CONVERTER
|
|
107
|
+
----------------------------------------------------------- */
|
|
108
|
+
type SnakageString<Key extends string> = Key extends `${infer _}`
|
|
109
|
+
? SnakageStringRepeatedly<Key, "">
|
|
110
|
+
: Key;
|
|
111
|
+
type SnakageStringRepeatedly<
|
|
112
|
+
S extends string,
|
|
113
|
+
Previous extends string,
|
|
114
|
+
> = S extends `${infer First}${infer Second}${infer Rest}`
|
|
115
|
+
? `${Underscore<Previous, First>}${Lowercase<First>}${Underscore<
|
|
116
|
+
First,
|
|
117
|
+
Second
|
|
118
|
+
>}${Lowercase<Second>}${SnakageStringRepeatedly<Rest, Second>}`
|
|
119
|
+
: S extends `${infer First}`
|
|
120
|
+
? `${Underscore<Previous, First>}${Lowercase<First>}`
|
|
121
|
+
: "";
|
|
122
|
+
type Underscore<First extends string, Second extends string> = First extends
|
|
123
|
+
| UpperAlphabetic
|
|
124
|
+
| ""
|
|
125
|
+
| "_"
|
|
126
|
+
? ""
|
|
127
|
+
: Second extends UpperAlphabetic
|
|
128
|
+
? "_"
|
|
129
|
+
: "";
|
|
130
|
+
type UpperAlphabetic =
|
|
131
|
+
| "A"
|
|
132
|
+
| "B"
|
|
133
|
+
| "C"
|
|
134
|
+
| "D"
|
|
135
|
+
| "E"
|
|
136
|
+
| "F"
|
|
137
|
+
| "G"
|
|
138
|
+
| "H"
|
|
139
|
+
| "I"
|
|
140
|
+
| "J"
|
|
141
|
+
| "K"
|
|
142
|
+
| "L"
|
|
143
|
+
| "M"
|
|
144
|
+
| "N"
|
|
145
|
+
| "O"
|
|
146
|
+
| "P"
|
|
147
|
+
| "Q"
|
|
148
|
+
| "R"
|
|
149
|
+
| "S"
|
|
150
|
+
| "T"
|
|
151
|
+
| "U"
|
|
152
|
+
| "V"
|
|
153
|
+
| "W"
|
|
154
|
+
| "X"
|
|
155
|
+
| "Y"
|
|
156
|
+
| "Z";
|
|
@@ -33,8 +33,16 @@ export namespace TypiaSetupWizard {
|
|
|
33
33
|
|
|
34
34
|
// SETUP TRANSFORMER
|
|
35
35
|
await pack.save((data) => {
|
|
36
|
-
// COMPOSE
|
|
36
|
+
// COMPOSE PREPARE COMMAND
|
|
37
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";
|
|
38
46
|
|
|
39
47
|
// FOR OLDER VERSIONS
|
|
40
48
|
if (typeof data.scripts.postinstall === "string") {
|
|
@@ -46,16 +54,6 @@ export namespace TypiaSetupWizard {
|
|
|
46
54
|
if (data.scripts.postinstall.length === 0)
|
|
47
55
|
delete data.scripts.postinstall;
|
|
48
56
|
}
|
|
49
|
-
|
|
50
|
-
// THE PREPARE SCRIPT
|
|
51
|
-
if (
|
|
52
|
-
typeof data.scripts.prepare === "string" &&
|
|
53
|
-
data.scripts.prepare.trim().length
|
|
54
|
-
) {
|
|
55
|
-
if (data.scripts.prepare.indexOf("ts-patch install") === -1)
|
|
56
|
-
data.scripts.prepare =
|
|
57
|
-
"ts-patch install && " + data.scripts.prepare;
|
|
58
|
-
} else data.scripts.prepare = "ts-patch install";
|
|
59
57
|
});
|
|
60
58
|
CommandExecutor.run(`${pack.manager} run prepare`);
|
|
61
59
|
|
|
@@ -117,9 +117,14 @@ export class MetadataCollection {
|
|
|
117
117
|
name: $id,
|
|
118
118
|
properties: [],
|
|
119
119
|
description:
|
|
120
|
+
(type.aliasSymbol &&
|
|
121
|
+
CommentFactory.description(type.aliasSymbol)) ??
|
|
120
122
|
(type.symbol && CommentFactory.description(type.symbol)) ??
|
|
121
123
|
undefined,
|
|
122
|
-
jsDocTags:
|
|
124
|
+
jsDocTags:
|
|
125
|
+
type.aliasSymbol?.getJsDocTags() ??
|
|
126
|
+
type.symbol?.getJsDocTags() ??
|
|
127
|
+
[],
|
|
123
128
|
validated: false,
|
|
124
129
|
index: this.object_index_++,
|
|
125
130
|
recursive: null!,
|
|
@@ -1,150 +1,150 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
-
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
-
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
-
|
|
7
|
-
import { Writable } from "../../../typings/Writable";
|
|
8
|
-
|
|
9
|
-
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
-
|
|
11
|
-
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
-
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
-
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
-
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
-
import { explore_metadata } from "./explore_metadata";
|
|
16
|
-
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
-
|
|
18
|
-
export const emplace_metadata_object =
|
|
19
|
-
(checker: ts.TypeChecker) =>
|
|
20
|
-
(options: MetadataFactory.IOptions) =>
|
|
21
|
-
(collection: MetadataCollection) =>
|
|
22
|
-
(errors: MetadataFactory.IError[]) =>
|
|
23
|
-
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
-
// EMPLACE OBJECT
|
|
25
|
-
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
-
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
-
|
|
28
|
-
if (newbie === false) return obj;
|
|
29
|
-
|
|
30
|
-
// PREPARE ASSETS
|
|
31
|
-
const isClass: boolean = parent.isClass();
|
|
32
|
-
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
-
? (node) => {
|
|
34
|
-
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
-
.getChildren()[0]
|
|
36
|
-
?.getChildren()[0]?.kind;
|
|
37
|
-
return (
|
|
38
|
-
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
-
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
-
(ts.isParameter(node) || isProperty(node))
|
|
41
|
-
);
|
|
42
|
-
}
|
|
43
|
-
: (node) => isProperty(node);
|
|
44
|
-
|
|
45
|
-
const insert =
|
|
46
|
-
(key: Metadata) =>
|
|
47
|
-
(value: Metadata) =>
|
|
48
|
-
(
|
|
49
|
-
symbol: ts.Symbol | undefined,
|
|
50
|
-
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
-
): MetadataProperty => {
|
|
52
|
-
// COMMENTS AND TAGS
|
|
53
|
-
const description: string | null = symbol
|
|
54
|
-
? CommentFactory.description(symbol) ?? null
|
|
55
|
-
: null;
|
|
56
|
-
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
-
symbol?.getJsDocTags() ?? []
|
|
58
|
-
).filter(filter ?? (() => true));
|
|
59
|
-
|
|
60
|
-
// THE PROPERTY
|
|
61
|
-
const property = MetadataProperty.create({
|
|
62
|
-
key,
|
|
63
|
-
value,
|
|
64
|
-
description,
|
|
65
|
-
jsDocTags,
|
|
66
|
-
});
|
|
67
|
-
obj.properties.push(property);
|
|
68
|
-
return property;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//----
|
|
72
|
-
// REGULAR PROPERTIES
|
|
73
|
-
//----
|
|
74
|
-
for (const prop of parent.getApparentProperties()) {
|
|
75
|
-
// CHECK INTERNAL TAG
|
|
76
|
-
if (
|
|
77
|
-
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
-
(tag) => tag.name === "internal",
|
|
79
|
-
) !== undefined
|
|
80
|
-
)
|
|
81
|
-
continue;
|
|
82
|
-
|
|
83
|
-
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
-
const [node, type] = (() => {
|
|
85
|
-
const node = prop.getDeclarations()?.[0] as
|
|
86
|
-
| ts.PropertyDeclaration
|
|
87
|
-
| undefined;
|
|
88
|
-
const type: ts.Type | undefined = node
|
|
89
|
-
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
-
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
-
return [node, type];
|
|
92
|
-
})();
|
|
93
|
-
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
-
|
|
95
|
-
// GET EXACT TYPE
|
|
96
|
-
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
-
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
-
collection,
|
|
99
|
-
)(errors)(type, {
|
|
100
|
-
top: false,
|
|
101
|
-
object: obj,
|
|
102
|
-
property: prop.name,
|
|
103
|
-
nested: null,
|
|
104
|
-
escaped: false,
|
|
105
|
-
aliased: false,
|
|
106
|
-
});
|
|
107
|
-
Writable(value).optional =
|
|
108
|
-
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
-
insert(key)(value)(prop);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
//----
|
|
113
|
-
// DYNAMIC PROPERTIES
|
|
114
|
-
//----
|
|
115
|
-
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
-
// GET EXACT TYPE
|
|
117
|
-
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
-
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
-
top: false,
|
|
120
|
-
object: obj,
|
|
121
|
-
property,
|
|
122
|
-
nested: null,
|
|
123
|
-
escaped: false,
|
|
124
|
-
aliased: false,
|
|
125
|
-
});
|
|
126
|
-
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
-
const value: Metadata = analyzer(index.type)({});
|
|
128
|
-
|
|
129
|
-
// INSERT WITH REQUIRED CONFIGURATION
|
|
130
|
-
insert(key)(value)(
|
|
131
|
-
index.declaration?.parent
|
|
132
|
-
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
133
|
-
: undefined,
|
|
134
|
-
(doc) => doc.name !== "default",
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
return obj;
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
const isProperty = (node: ts.Declaration) =>
|
|
141
|
-
ts.isPropertyDeclaration(node) ||
|
|
142
|
-
ts.isPropertyAssignment(node) ||
|
|
143
|
-
ts.isPropertySignature(node) ||
|
|
144
|
-
ts.isTypeLiteralNode(node);
|
|
145
|
-
|
|
146
|
-
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
147
|
-
if (type.isUnionOrIntersection())
|
|
148
|
-
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
149
|
-
else iterate_metadata_coalesce(meta, type);
|
|
150
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../../schemas/metadata/Metadata";
|
|
4
|
+
import { MetadataObject } from "../../../schemas/metadata/MetadataObject";
|
|
5
|
+
import { MetadataProperty } from "../../../schemas/metadata/MetadataProperty";
|
|
6
|
+
|
|
7
|
+
import { Writable } from "../../../typings/Writable";
|
|
8
|
+
|
|
9
|
+
import { ArrayUtil } from "../../../utils/ArrayUtil";
|
|
10
|
+
|
|
11
|
+
import { CommentFactory } from "../../CommentFactory";
|
|
12
|
+
import { MetadataCollection } from "../../MetadataCollection";
|
|
13
|
+
import { MetadataFactory } from "../../MetadataFactory";
|
|
14
|
+
import { MetadataHelper } from "./MetadataHelper";
|
|
15
|
+
import { explore_metadata } from "./explore_metadata";
|
|
16
|
+
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
17
|
+
|
|
18
|
+
export const emplace_metadata_object =
|
|
19
|
+
(checker: ts.TypeChecker) =>
|
|
20
|
+
(options: MetadataFactory.IOptions) =>
|
|
21
|
+
(collection: MetadataCollection) =>
|
|
22
|
+
(errors: MetadataFactory.IError[]) =>
|
|
23
|
+
(parent: ts.Type, nullable: boolean): MetadataObject => {
|
|
24
|
+
// EMPLACE OBJECT
|
|
25
|
+
const [obj, newbie] = collection.emplace(checker, parent);
|
|
26
|
+
ArrayUtil.add(obj.nullables, nullable, (elem) => elem === nullable);
|
|
27
|
+
|
|
28
|
+
if (newbie === false) return obj;
|
|
29
|
+
|
|
30
|
+
// PREPARE ASSETS
|
|
31
|
+
const isClass: boolean = parent.isClass();
|
|
32
|
+
const pred: (node: ts.Declaration) => boolean = isClass
|
|
33
|
+
? (node) => {
|
|
34
|
+
const kind: ts.SyntaxKind | undefined = node
|
|
35
|
+
.getChildren()[0]
|
|
36
|
+
?.getChildren()[0]?.kind;
|
|
37
|
+
return (
|
|
38
|
+
kind !== ts.SyntaxKind.PrivateKeyword &&
|
|
39
|
+
kind !== ts.SyntaxKind.ProtectedKeyword &&
|
|
40
|
+
(ts.isParameter(node) || isProperty(node))
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
: (node) => isProperty(node);
|
|
44
|
+
|
|
45
|
+
const insert =
|
|
46
|
+
(key: Metadata) =>
|
|
47
|
+
(value: Metadata) =>
|
|
48
|
+
(
|
|
49
|
+
symbol: ts.Symbol | undefined,
|
|
50
|
+
filter?: (doc: ts.JSDocTagInfo) => boolean,
|
|
51
|
+
): MetadataProperty => {
|
|
52
|
+
// COMMENTS AND TAGS
|
|
53
|
+
const description: string | null = symbol
|
|
54
|
+
? CommentFactory.description(symbol) ?? null
|
|
55
|
+
: null;
|
|
56
|
+
const jsDocTags: ts.JSDocTagInfo[] = (
|
|
57
|
+
symbol?.getJsDocTags() ?? []
|
|
58
|
+
).filter(filter ?? (() => true));
|
|
59
|
+
|
|
60
|
+
// THE PROPERTY
|
|
61
|
+
const property = MetadataProperty.create({
|
|
62
|
+
key,
|
|
63
|
+
value,
|
|
64
|
+
description,
|
|
65
|
+
jsDocTags,
|
|
66
|
+
});
|
|
67
|
+
obj.properties.push(property);
|
|
68
|
+
return property;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
//----
|
|
72
|
+
// REGULAR PROPERTIES
|
|
73
|
+
//----
|
|
74
|
+
for (const prop of parent.getApparentProperties()) {
|
|
75
|
+
// CHECK INTERNAL TAG
|
|
76
|
+
if (
|
|
77
|
+
(prop.getJsDocTags(checker) ?? []).find(
|
|
78
|
+
(tag) => tag.name === "internal",
|
|
79
|
+
) !== undefined
|
|
80
|
+
)
|
|
81
|
+
continue;
|
|
82
|
+
|
|
83
|
+
// CHECK NODE IS A FORMAL PROPERTY
|
|
84
|
+
const [node, type] = (() => {
|
|
85
|
+
const node = prop.getDeclarations()?.[0] as
|
|
86
|
+
| ts.PropertyDeclaration
|
|
87
|
+
| undefined;
|
|
88
|
+
const type: ts.Type | undefined = node
|
|
89
|
+
? checker.getTypeOfSymbolAtLocation(prop, node)
|
|
90
|
+
: checker.getTypeOfPropertyOfType(parent, prop.name);
|
|
91
|
+
return [node, type];
|
|
92
|
+
})();
|
|
93
|
+
if ((node && pred(node) === false) || type === undefined) continue;
|
|
94
|
+
|
|
95
|
+
// GET EXACT TYPE
|
|
96
|
+
const key: Metadata = MetadataHelper.literal_to_metadata(prop.name);
|
|
97
|
+
const value: Metadata = explore_metadata(checker)(options)(
|
|
98
|
+
collection,
|
|
99
|
+
)(errors)(type, {
|
|
100
|
+
top: false,
|
|
101
|
+
object: obj,
|
|
102
|
+
property: prop.name,
|
|
103
|
+
nested: null,
|
|
104
|
+
escaped: false,
|
|
105
|
+
aliased: false,
|
|
106
|
+
});
|
|
107
|
+
Writable(value).optional =
|
|
108
|
+
(prop.flags & ts.SymbolFlags.Optional) !== 0;
|
|
109
|
+
insert(key)(value)(prop);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//----
|
|
113
|
+
// DYNAMIC PROPERTIES
|
|
114
|
+
//----
|
|
115
|
+
for (const index of checker.getIndexInfosOfType(parent)) {
|
|
116
|
+
// GET EXACT TYPE
|
|
117
|
+
const analyzer = (type: ts.Type) => (property: {} | null) =>
|
|
118
|
+
explore_metadata(checker)(options)(collection)(errors)(type, {
|
|
119
|
+
top: false,
|
|
120
|
+
object: obj,
|
|
121
|
+
property,
|
|
122
|
+
nested: null,
|
|
123
|
+
escaped: false,
|
|
124
|
+
aliased: false,
|
|
125
|
+
});
|
|
126
|
+
const key: Metadata = analyzer(index.keyType)(null);
|
|
127
|
+
const value: Metadata = analyzer(index.type)({});
|
|
128
|
+
|
|
129
|
+
// INSERT WITH REQUIRED CONFIGURATION
|
|
130
|
+
insert(key)(value)(
|
|
131
|
+
index.declaration?.parent
|
|
132
|
+
? checker.getSymbolAtLocation(index.declaration.parent)
|
|
133
|
+
: undefined,
|
|
134
|
+
(doc) => doc.name !== "default",
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return obj;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const isProperty = (node: ts.Declaration) =>
|
|
141
|
+
ts.isPropertyDeclaration(node) ||
|
|
142
|
+
ts.isPropertyAssignment(node) ||
|
|
143
|
+
ts.isPropertySignature(node) ||
|
|
144
|
+
ts.isTypeLiteralNode(node);
|
|
145
|
+
|
|
146
|
+
const iterate_optional_coalesce = (meta: Metadata, type: ts.Type): void => {
|
|
147
|
+
if (type.isUnionOrIntersection())
|
|
148
|
+
type.types.forEach((child) => iterate_optional_coalesce(meta, child));
|
|
149
|
+
else iterate_metadata_coalesce(meta, type);
|
|
150
|
+
};
|