typia 4.2.1 → 4.2.2
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/programmers/helpers/RandomRanger.js +1 -1
- package/lib/programmers/helpers/RandomRanger.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/TypiaSetupWizard.ts +153 -153
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/programmers/RandomProgrammer.ts +579 -579
- package/src/programmers/helpers/RandomRanger.ts +1 -1
- package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
- package/src/utils/PatternUtil.ts +33 -33
|
@@ -26,7 +26,7 @@ export namespace RandomRanger {
|
|
|
26
26
|
|
|
27
27
|
props.minimum ??= defs.minimum;
|
|
28
28
|
props.maximum ??= defs.maximum;
|
|
29
|
-
if (props.maximum
|
|
29
|
+
if (props.maximum < props.minimum)
|
|
30
30
|
(props.maximum as number) += defs.gap;
|
|
31
31
|
|
|
32
32
|
return ts.factory.createCallExpression(
|
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
-
|
|
6
|
-
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/
|
|
12
|
-
export const stringify_dynamic_properties = (
|
|
13
|
-
dynamic: IExpressionEntry<ts.Expression>[],
|
|
14
|
-
regular: string[],
|
|
15
|
-
): ts.Expression => {
|
|
16
|
-
// BASIC STATMEMENT, CHECK UNDEFINED
|
|
17
|
-
const statements: ts.Statement[] = [
|
|
18
|
-
ts.factory.createIfStatement(
|
|
19
|
-
ts.factory.createStrictEquality(
|
|
20
|
-
ts.factory.createIdentifier("undefined"),
|
|
21
|
-
ts.factory.createIdentifier("value"),
|
|
22
|
-
),
|
|
23
|
-
ts.factory.createReturnStatement(
|
|
24
|
-
ts.factory.createStringLiteral(""),
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
];
|
|
28
|
-
|
|
29
|
-
// PREPARE RETURN FUNCTION
|
|
30
|
-
const output = () => {
|
|
31
|
-
const mapped = ts.factory.createCallExpression(
|
|
32
|
-
IdentifierFactory.access(
|
|
33
|
-
ts.factory.createCallExpression(
|
|
34
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
35
|
-
undefined,
|
|
36
|
-
[ts.factory.createIdentifier("input")],
|
|
37
|
-
),
|
|
38
|
-
)("map"),
|
|
39
|
-
undefined,
|
|
40
|
-
[
|
|
41
|
-
ts.factory.createArrowFunction(
|
|
42
|
-
undefined,
|
|
43
|
-
undefined,
|
|
44
|
-
[
|
|
45
|
-
IdentifierFactory.parameter(
|
|
46
|
-
ts.factory.createArrayBindingPattern([
|
|
47
|
-
ts.factory.createBindingElement(
|
|
48
|
-
undefined,
|
|
49
|
-
undefined,
|
|
50
|
-
"key",
|
|
51
|
-
),
|
|
52
|
-
ts.factory.createBindingElement(
|
|
53
|
-
undefined,
|
|
54
|
-
undefined,
|
|
55
|
-
"value",
|
|
56
|
-
),
|
|
57
|
-
]),
|
|
58
|
-
ts.factory.createTypeReferenceNode("[string, any]"),
|
|
59
|
-
),
|
|
60
|
-
],
|
|
61
|
-
undefined,
|
|
62
|
-
undefined,
|
|
63
|
-
ts.factory.createBlock(statements),
|
|
64
|
-
),
|
|
65
|
-
],
|
|
66
|
-
);
|
|
67
|
-
const filtered = ts.factory.createCallExpression(
|
|
68
|
-
IdentifierFactory.access(mapped)("filter"),
|
|
69
|
-
undefined,
|
|
70
|
-
[
|
|
71
|
-
ts.factory.createArrowFunction(
|
|
72
|
-
undefined,
|
|
73
|
-
undefined,
|
|
74
|
-
[IdentifierFactory.parameter("str")],
|
|
75
|
-
undefined,
|
|
76
|
-
undefined,
|
|
77
|
-
ts.factory.createStrictInequality(
|
|
78
|
-
ts.factory.createStringLiteral(""),
|
|
79
|
-
ts.factory.createIdentifier("str"),
|
|
80
|
-
),
|
|
81
|
-
),
|
|
82
|
-
],
|
|
83
|
-
);
|
|
84
|
-
return ts.factory.createCallExpression(
|
|
85
|
-
IdentifierFactory.access(filtered)("join"),
|
|
86
|
-
undefined,
|
|
87
|
-
[ts.factory.createStringLiteral(",")],
|
|
88
|
-
);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// WHEN REGULAR PROPERTY EXISTS
|
|
92
|
-
if (regular.length)
|
|
93
|
-
statements.push(
|
|
94
|
-
ts.factory.createIfStatement(
|
|
95
|
-
ts.factory.createCallExpression(
|
|
96
|
-
IdentifierFactory.access(
|
|
97
|
-
ts.factory.createArrayLiteralExpression(
|
|
98
|
-
regular.map((key) =>
|
|
99
|
-
ts.factory.createStringLiteral(key),
|
|
100
|
-
),
|
|
101
|
-
),
|
|
102
|
-
)("some"),
|
|
103
|
-
undefined,
|
|
104
|
-
[
|
|
105
|
-
ts.factory.createArrowFunction(
|
|
106
|
-
undefined,
|
|
107
|
-
undefined,
|
|
108
|
-
[IdentifierFactory.parameter("regular")],
|
|
109
|
-
undefined,
|
|
110
|
-
undefined,
|
|
111
|
-
ts.factory.createStrictEquality(
|
|
112
|
-
ts.factory.createIdentifier("regular"),
|
|
113
|
-
ts.factory.createIdentifier("key"),
|
|
114
|
-
),
|
|
115
|
-
),
|
|
116
|
-
],
|
|
117
|
-
),
|
|
118
|
-
ts.factory.createReturnStatement(
|
|
119
|
-
ts.factory.createStringLiteral(""),
|
|
120
|
-
),
|
|
121
|
-
),
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
// ONLY STRING TYPED KEY EXISTS
|
|
125
|
-
const simple: boolean =
|
|
126
|
-
dynamic.length === 1 &&
|
|
127
|
-
dynamic[0]!.key.size() === 1 &&
|
|
128
|
-
dynamic[0]!.key.atomics[0] === "string";
|
|
129
|
-
if (simple === true) {
|
|
130
|
-
statements.push(stringify(dynamic[0]!));
|
|
131
|
-
return output();
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// COMPOSITE TEMPLATE LITERAL TYPES
|
|
135
|
-
for (const entry of dynamic) {
|
|
136
|
-
const condition: ts.IfStatement = ts.factory.createIfStatement(
|
|
137
|
-
ts.factory.createCallExpression(
|
|
138
|
-
ts.factory.createIdentifier(
|
|
139
|
-
`RegExp(/${metadata_to_pattern(true)(entry.key)}/).test`,
|
|
140
|
-
),
|
|
141
|
-
undefined,
|
|
142
|
-
[ts.factory.createIdentifier("key")],
|
|
143
|
-
),
|
|
144
|
-
stringify(entry),
|
|
145
|
-
);
|
|
146
|
-
statements.push(condition);
|
|
147
|
-
}
|
|
148
|
-
statements.push(
|
|
149
|
-
ts.factory.createReturnStatement(ts.factory.createStringLiteral("")),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
return output();
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* @internal
|
|
157
|
-
*/
|
|
158
|
-
const stringify = (
|
|
159
|
-
entry: IExpressionEntry<ts.Expression>,
|
|
160
|
-
): ts.ReturnStatement =>
|
|
161
|
-
ts.factory.createReturnStatement(
|
|
162
|
-
TemplateFactory.generate([
|
|
163
|
-
ts.factory.createCallExpression(
|
|
164
|
-
ts.factory.createIdentifier("JSON.stringify"),
|
|
165
|
-
[],
|
|
166
|
-
[ts.factory.createIdentifier("key")],
|
|
167
|
-
),
|
|
168
|
-
ts.factory.createStringLiteral(":"),
|
|
169
|
-
entry.expression,
|
|
170
|
-
]),
|
|
171
|
-
);
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { TemplateFactory } from "../../factories/TemplateFactory";
|
|
5
|
+
|
|
6
|
+
import { IExpressionEntry } from "../helpers/IExpressionEntry";
|
|
7
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export const stringify_dynamic_properties = (
|
|
13
|
+
dynamic: IExpressionEntry<ts.Expression>[],
|
|
14
|
+
regular: string[],
|
|
15
|
+
): ts.Expression => {
|
|
16
|
+
// BASIC STATMEMENT, CHECK UNDEFINED
|
|
17
|
+
const statements: ts.Statement[] = [
|
|
18
|
+
ts.factory.createIfStatement(
|
|
19
|
+
ts.factory.createStrictEquality(
|
|
20
|
+
ts.factory.createIdentifier("undefined"),
|
|
21
|
+
ts.factory.createIdentifier("value"),
|
|
22
|
+
),
|
|
23
|
+
ts.factory.createReturnStatement(
|
|
24
|
+
ts.factory.createStringLiteral(""),
|
|
25
|
+
),
|
|
26
|
+
),
|
|
27
|
+
];
|
|
28
|
+
|
|
29
|
+
// PREPARE RETURN FUNCTION
|
|
30
|
+
const output = () => {
|
|
31
|
+
const mapped = ts.factory.createCallExpression(
|
|
32
|
+
IdentifierFactory.access(
|
|
33
|
+
ts.factory.createCallExpression(
|
|
34
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
35
|
+
undefined,
|
|
36
|
+
[ts.factory.createIdentifier("input")],
|
|
37
|
+
),
|
|
38
|
+
)("map"),
|
|
39
|
+
undefined,
|
|
40
|
+
[
|
|
41
|
+
ts.factory.createArrowFunction(
|
|
42
|
+
undefined,
|
|
43
|
+
undefined,
|
|
44
|
+
[
|
|
45
|
+
IdentifierFactory.parameter(
|
|
46
|
+
ts.factory.createArrayBindingPattern([
|
|
47
|
+
ts.factory.createBindingElement(
|
|
48
|
+
undefined,
|
|
49
|
+
undefined,
|
|
50
|
+
"key",
|
|
51
|
+
),
|
|
52
|
+
ts.factory.createBindingElement(
|
|
53
|
+
undefined,
|
|
54
|
+
undefined,
|
|
55
|
+
"value",
|
|
56
|
+
),
|
|
57
|
+
]),
|
|
58
|
+
ts.factory.createTypeReferenceNode("[string, any]"),
|
|
59
|
+
),
|
|
60
|
+
],
|
|
61
|
+
undefined,
|
|
62
|
+
undefined,
|
|
63
|
+
ts.factory.createBlock(statements),
|
|
64
|
+
),
|
|
65
|
+
],
|
|
66
|
+
);
|
|
67
|
+
const filtered = ts.factory.createCallExpression(
|
|
68
|
+
IdentifierFactory.access(mapped)("filter"),
|
|
69
|
+
undefined,
|
|
70
|
+
[
|
|
71
|
+
ts.factory.createArrowFunction(
|
|
72
|
+
undefined,
|
|
73
|
+
undefined,
|
|
74
|
+
[IdentifierFactory.parameter("str")],
|
|
75
|
+
undefined,
|
|
76
|
+
undefined,
|
|
77
|
+
ts.factory.createStrictInequality(
|
|
78
|
+
ts.factory.createStringLiteral(""),
|
|
79
|
+
ts.factory.createIdentifier("str"),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
],
|
|
83
|
+
);
|
|
84
|
+
return ts.factory.createCallExpression(
|
|
85
|
+
IdentifierFactory.access(filtered)("join"),
|
|
86
|
+
undefined,
|
|
87
|
+
[ts.factory.createStringLiteral(",")],
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// WHEN REGULAR PROPERTY EXISTS
|
|
92
|
+
if (regular.length)
|
|
93
|
+
statements.push(
|
|
94
|
+
ts.factory.createIfStatement(
|
|
95
|
+
ts.factory.createCallExpression(
|
|
96
|
+
IdentifierFactory.access(
|
|
97
|
+
ts.factory.createArrayLiteralExpression(
|
|
98
|
+
regular.map((key) =>
|
|
99
|
+
ts.factory.createStringLiteral(key),
|
|
100
|
+
),
|
|
101
|
+
),
|
|
102
|
+
)("some"),
|
|
103
|
+
undefined,
|
|
104
|
+
[
|
|
105
|
+
ts.factory.createArrowFunction(
|
|
106
|
+
undefined,
|
|
107
|
+
undefined,
|
|
108
|
+
[IdentifierFactory.parameter("regular")],
|
|
109
|
+
undefined,
|
|
110
|
+
undefined,
|
|
111
|
+
ts.factory.createStrictEquality(
|
|
112
|
+
ts.factory.createIdentifier("regular"),
|
|
113
|
+
ts.factory.createIdentifier("key"),
|
|
114
|
+
),
|
|
115
|
+
),
|
|
116
|
+
],
|
|
117
|
+
),
|
|
118
|
+
ts.factory.createReturnStatement(
|
|
119
|
+
ts.factory.createStringLiteral(""),
|
|
120
|
+
),
|
|
121
|
+
),
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
// ONLY STRING TYPED KEY EXISTS
|
|
125
|
+
const simple: boolean =
|
|
126
|
+
dynamic.length === 1 &&
|
|
127
|
+
dynamic[0]!.key.size() === 1 &&
|
|
128
|
+
dynamic[0]!.key.atomics[0] === "string";
|
|
129
|
+
if (simple === true) {
|
|
130
|
+
statements.push(stringify(dynamic[0]!));
|
|
131
|
+
return output();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// COMPOSITE TEMPLATE LITERAL TYPES
|
|
135
|
+
for (const entry of dynamic) {
|
|
136
|
+
const condition: ts.IfStatement = ts.factory.createIfStatement(
|
|
137
|
+
ts.factory.createCallExpression(
|
|
138
|
+
ts.factory.createIdentifier(
|
|
139
|
+
`RegExp(/${metadata_to_pattern(true)(entry.key)}/).test`,
|
|
140
|
+
),
|
|
141
|
+
undefined,
|
|
142
|
+
[ts.factory.createIdentifier("key")],
|
|
143
|
+
),
|
|
144
|
+
stringify(entry),
|
|
145
|
+
);
|
|
146
|
+
statements.push(condition);
|
|
147
|
+
}
|
|
148
|
+
statements.push(
|
|
149
|
+
ts.factory.createReturnStatement(ts.factory.createStringLiteral("")),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return output();
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
const stringify = (
|
|
159
|
+
entry: IExpressionEntry<ts.Expression>,
|
|
160
|
+
): ts.ReturnStatement =>
|
|
161
|
+
ts.factory.createReturnStatement(
|
|
162
|
+
TemplateFactory.generate([
|
|
163
|
+
ts.factory.createCallExpression(
|
|
164
|
+
ts.factory.createIdentifier("JSON.stringify"),
|
|
165
|
+
[],
|
|
166
|
+
[ts.factory.createIdentifier("key")],
|
|
167
|
+
),
|
|
168
|
+
ts.factory.createStringLiteral(":"),
|
|
169
|
+
entry.expression,
|
|
170
|
+
]),
|
|
171
|
+
);
|
package/src/utils/PatternUtil.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
export namespace PatternUtil {
|
|
2
|
-
export const fix = (str: string): string => {
|
|
3
|
-
const first: number = str.indexOf(STRING);
|
|
4
|
-
const last: number = str.lastIndexOf(STRING);
|
|
5
|
-
return [
|
|
6
|
-
first === -1 || none("(")(str.slice(0, first)) ? "^" : "",
|
|
7
|
-
str,
|
|
8
|
-
last === -1 || none(")")(str.slice(last + STRING.length))
|
|
9
|
-
? "$"
|
|
10
|
-
: "",
|
|
11
|
-
].join("");
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export const escape = (str: string): string => {
|
|
15
|
-
return str
|
|
16
|
-
.replace(/[|\\/{}()[\]^$+*?.]/g, "\\$&")
|
|
17
|
-
.replace(/-/g, "\\x2d");
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const NUMBER =
|
|
21
|
-
"[+-]?" + // optional sign
|
|
22
|
-
"\\d+(?:\\.\\d+)?" + // integer or decimal
|
|
23
|
-
"(?:[eE][+-]?\\d+)?"; // optional exponent
|
|
24
|
-
export const BOOLEAN = "true|false";
|
|
25
|
-
export const STRING = "(.*)";
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const none =
|
|
29
|
-
(parenthesis: string) =>
|
|
30
|
-
(str: string): boolean => {
|
|
31
|
-
for (const ch of str) if (ch !== parenthesis) return true;
|
|
32
|
-
return false;
|
|
33
|
-
};
|
|
1
|
+
export namespace PatternUtil {
|
|
2
|
+
export const fix = (str: string): string => {
|
|
3
|
+
const first: number = str.indexOf(STRING);
|
|
4
|
+
const last: number = str.lastIndexOf(STRING);
|
|
5
|
+
return [
|
|
6
|
+
first === -1 || none("(")(str.slice(0, first)) ? "^" : "",
|
|
7
|
+
str,
|
|
8
|
+
last === -1 || none(")")(str.slice(last + STRING.length))
|
|
9
|
+
? "$"
|
|
10
|
+
: "",
|
|
11
|
+
].join("");
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const escape = (str: string): string => {
|
|
15
|
+
return str
|
|
16
|
+
.replace(/[|\\/{}()[\]^$+*?.]/g, "\\$&")
|
|
17
|
+
.replace(/-/g, "\\x2d");
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const NUMBER =
|
|
21
|
+
"[+-]?" + // optional sign
|
|
22
|
+
"\\d+(?:\\.\\d+)?" + // integer or decimal
|
|
23
|
+
"(?:[eE][+-]?\\d+)?"; // optional exponent
|
|
24
|
+
export const BOOLEAN = "true|false";
|
|
25
|
+
export const STRING = "(.*)";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const none =
|
|
29
|
+
(parenthesis: string) =>
|
|
30
|
+
(str: string): boolean => {
|
|
31
|
+
for (const ch of str) if (ch !== parenthesis) return true;
|
|
32
|
+
return false;
|
|
33
|
+
};
|