typia 3.4.4 → 3.4.6
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 -47
- package/lib/executable/internal/TypiaSetupWizard.js +8 -6
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/internal/TypiaSetupWizard.ts +148 -149
- package/src/executable/typia.ts +35 -35
- package/src/factories/MetadataTagFactory.ts +347 -347
- package/src/factories/internal/iterate_metadata.ts +81 -81
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/functional/$number.ts +19 -19
- package/src/index.ts +4 -4
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/StringifyProgrammer.ts +746 -746
- package/src/programmers/internal/application_array.ts +45 -45
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +103 -103
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/schemas/IJsonComponents.ts +24 -24
- package/src/schemas/IJsonSchema.ts +92 -92
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- 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/StringifyTransformer.ts +36 -36
- 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
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
import { MetadataCollection } from "../MetadataCollection";
|
|
8
|
-
import { MetadataFactory } from "../MetadataFactory";
|
|
9
|
-
import { iterate_metadata_array } from "./iterate_metadata_array";
|
|
10
|
-
import { iterate_metadata_atomic } from "./iterate_metadata_atomic";
|
|
11
|
-
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
12
|
-
import { iterate_metadata_constant } from "./iterate_metadata_constant";
|
|
13
|
-
import { iterate_metadata_map } from "./iterate_metadata_map";
|
|
14
|
-
import { iterate_metadata_native } from "./iterate_metadata_native";
|
|
15
|
-
import { iterate_metadata_object } from "./iterate_metadata_object";
|
|
16
|
-
import { iterate_metadata_resolve } from "./iterate_metadata_resolve";
|
|
17
|
-
import { iterate_metadata_set } from "./iterate_metadata_set";
|
|
18
|
-
import { iterate_metadata_template } from "./iterate_metadata_template";
|
|
19
|
-
import { iterate_metadata_tuple } from "./iterate_metadata_tuple";
|
|
20
|
-
import { iterate_metadata_union } from "./iterate_metadata_union";
|
|
21
|
-
|
|
22
|
-
export const iterate_metadata =
|
|
23
|
-
(checker: ts.TypeChecker) =>
|
|
24
|
-
(options: MetadataFactory.IOptions) =>
|
|
25
|
-
(collection: MetadataCollection) =>
|
|
26
|
-
(meta: Metadata, type: ts.Type, parentResolved: boolean): void => {
|
|
27
|
-
if (type.isTypeParameter() === true)
|
|
28
|
-
throw new Error(
|
|
29
|
-
`Error on typia.MetadataFactory.generate(): non-specified generic argument on ${meta.getName()}.`,
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
// CHECK UNION & toJSON()
|
|
33
|
-
if (
|
|
34
|
-
iterate_metadata_union(checker)(options)(collection)(
|
|
35
|
-
meta,
|
|
36
|
-
type,
|
|
37
|
-
parentResolved,
|
|
38
|
-
) ||
|
|
39
|
-
iterate_metadata_resolve(checker)(options)(collection)(
|
|
40
|
-
meta,
|
|
41
|
-
type,
|
|
42
|
-
parentResolved,
|
|
43
|
-
)
|
|
44
|
-
)
|
|
45
|
-
return;
|
|
46
|
-
|
|
47
|
-
// VALIDATE NODE
|
|
48
|
-
const node: ts.TypeNode | undefined = checker.typeToTypeNode(
|
|
49
|
-
type,
|
|
50
|
-
undefined,
|
|
51
|
-
undefined,
|
|
52
|
-
);
|
|
53
|
-
if (node === undefined) {
|
|
54
|
-
// EMPTY TUPLE CASE CAN BE
|
|
55
|
-
ArrayUtil.set(meta.tuples, [], () => "[]");
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// ITERATE CASES
|
|
60
|
-
iterate_metadata_coalesce(meta, type) ||
|
|
61
|
-
iterate_metadata_constant(checker)(options)(meta, type) ||
|
|
62
|
-
iterate_metadata_template(checker)(options)(collection)(
|
|
63
|
-
meta,
|
|
64
|
-
type,
|
|
65
|
-
) ||
|
|
66
|
-
iterate_metadata_atomic(meta, type) ||
|
|
67
|
-
iterate_metadata_tuple(checker)(options)(collection)(
|
|
68
|
-
meta,
|
|
69
|
-
type,
|
|
70
|
-
node,
|
|
71
|
-
) ||
|
|
72
|
-
iterate_metadata_array(checker)(options)(collection)(meta, type) ||
|
|
73
|
-
iterate_metadata_native(checker)(meta, type) ||
|
|
74
|
-
iterate_metadata_map(checker)(options)(collection)(meta, type) ||
|
|
75
|
-
iterate_metadata_set(checker)(options)(collection)(meta, type) ||
|
|
76
|
-
iterate_metadata_object(checker)(options)(collection)(
|
|
77
|
-
meta,
|
|
78
|
-
type,
|
|
79
|
-
parentResolved,
|
|
80
|
-
);
|
|
81
|
-
};
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
import { MetadataCollection } from "../MetadataCollection";
|
|
8
|
+
import { MetadataFactory } from "../MetadataFactory";
|
|
9
|
+
import { iterate_metadata_array } from "./iterate_metadata_array";
|
|
10
|
+
import { iterate_metadata_atomic } from "./iterate_metadata_atomic";
|
|
11
|
+
import { iterate_metadata_coalesce } from "./iterate_metadata_coalesce";
|
|
12
|
+
import { iterate_metadata_constant } from "./iterate_metadata_constant";
|
|
13
|
+
import { iterate_metadata_map } from "./iterate_metadata_map";
|
|
14
|
+
import { iterate_metadata_native } from "./iterate_metadata_native";
|
|
15
|
+
import { iterate_metadata_object } from "./iterate_metadata_object";
|
|
16
|
+
import { iterate_metadata_resolve } from "./iterate_metadata_resolve";
|
|
17
|
+
import { iterate_metadata_set } from "./iterate_metadata_set";
|
|
18
|
+
import { iterate_metadata_template } from "./iterate_metadata_template";
|
|
19
|
+
import { iterate_metadata_tuple } from "./iterate_metadata_tuple";
|
|
20
|
+
import { iterate_metadata_union } from "./iterate_metadata_union";
|
|
21
|
+
|
|
22
|
+
export const iterate_metadata =
|
|
23
|
+
(checker: ts.TypeChecker) =>
|
|
24
|
+
(options: MetadataFactory.IOptions) =>
|
|
25
|
+
(collection: MetadataCollection) =>
|
|
26
|
+
(meta: Metadata, type: ts.Type, parentResolved: boolean): void => {
|
|
27
|
+
if (type.isTypeParameter() === true)
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Error on typia.MetadataFactory.generate(): non-specified generic argument on ${meta.getName()}.`,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// CHECK UNION & toJSON()
|
|
33
|
+
if (
|
|
34
|
+
iterate_metadata_union(checker)(options)(collection)(
|
|
35
|
+
meta,
|
|
36
|
+
type,
|
|
37
|
+
parentResolved,
|
|
38
|
+
) ||
|
|
39
|
+
iterate_metadata_resolve(checker)(options)(collection)(
|
|
40
|
+
meta,
|
|
41
|
+
type,
|
|
42
|
+
parentResolved,
|
|
43
|
+
)
|
|
44
|
+
)
|
|
45
|
+
return;
|
|
46
|
+
|
|
47
|
+
// VALIDATE NODE
|
|
48
|
+
const node: ts.TypeNode | undefined = checker.typeToTypeNode(
|
|
49
|
+
type,
|
|
50
|
+
undefined,
|
|
51
|
+
undefined,
|
|
52
|
+
);
|
|
53
|
+
if (node === undefined) {
|
|
54
|
+
// EMPTY TUPLE CASE CAN BE
|
|
55
|
+
ArrayUtil.set(meta.tuples, [], () => "[]");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ITERATE CASES
|
|
60
|
+
iterate_metadata_coalesce(meta, type) ||
|
|
61
|
+
iterate_metadata_constant(checker)(options)(meta, type) ||
|
|
62
|
+
iterate_metadata_template(checker)(options)(collection)(
|
|
63
|
+
meta,
|
|
64
|
+
type,
|
|
65
|
+
) ||
|
|
66
|
+
iterate_metadata_atomic(meta, type) ||
|
|
67
|
+
iterate_metadata_tuple(checker)(options)(collection)(
|
|
68
|
+
meta,
|
|
69
|
+
type,
|
|
70
|
+
node,
|
|
71
|
+
) ||
|
|
72
|
+
iterate_metadata_array(checker)(options)(collection)(meta, type) ||
|
|
73
|
+
iterate_metadata_native(checker)(meta, type) ||
|
|
74
|
+
iterate_metadata_map(checker)(options)(collection)(meta, type) ||
|
|
75
|
+
iterate_metadata_set(checker)(options)(collection)(meta, type) ||
|
|
76
|
+
iterate_metadata_object(checker)(options)(collection)(
|
|
77
|
+
meta,
|
|
78
|
+
type,
|
|
79
|
+
parentResolved,
|
|
80
|
+
);
|
|
81
|
+
};
|
|
@@ -1,227 +1,227 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
-
|
|
5
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
-
|
|
7
|
-
import { TypeFactory } from "../TypeFactory";
|
|
8
|
-
|
|
9
|
-
export const iterate_metadata_native =
|
|
10
|
-
(checker: ts.TypeChecker) =>
|
|
11
|
-
(meta: Metadata, type: ts.Type): boolean => {
|
|
12
|
-
const validator = validate(checker)(type);
|
|
13
|
-
const name: string = TypeFactory.getFullName(
|
|
14
|
-
checker,
|
|
15
|
-
type,
|
|
16
|
-
type.getSymbol(),
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
const simple = SIMPLES.get(name);
|
|
20
|
-
if (simple && validator(simple)) {
|
|
21
|
-
if (FORBIDDEN.has(name))
|
|
22
|
-
throw new Error(
|
|
23
|
-
`Error on typia.metadata(): typia does not allow "${name}" class type. Use "${name.toLowerCase()}" type instead.`,
|
|
24
|
-
);
|
|
25
|
-
ArrayUtil.set(meta.natives, name, (str) => str);
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const complicate = COMPLICATES.get(name);
|
|
30
|
-
if (complicate && validator(complicate)) {
|
|
31
|
-
ArrayUtil.set(meta.natives, complicate.name ?? name, (str) => str);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
for (const generic of GENERICS)
|
|
36
|
-
if (
|
|
37
|
-
name.substring(0, generic.name.length) === generic.name &&
|
|
38
|
-
validator(generic)
|
|
39
|
-
) {
|
|
40
|
-
ArrayUtil.set(meta.natives, generic.name ?? name, (str) => str);
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
return false;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
const validate =
|
|
47
|
-
(checker: ts.TypeChecker) => (type: ts.Type) => (info: IClassInfo) =>
|
|
48
|
-
(info.methods ?? []).every((method) => {
|
|
49
|
-
const returnType = TypeFactory.getReturnType(
|
|
50
|
-
checker,
|
|
51
|
-
type,
|
|
52
|
-
method.name,
|
|
53
|
-
);
|
|
54
|
-
return (
|
|
55
|
-
returnType !== null &&
|
|
56
|
-
checker.typeToString(returnType) === method.return
|
|
57
|
-
);
|
|
58
|
-
}) &&
|
|
59
|
-
(info.properties ?? []).every((property) => {
|
|
60
|
-
const prop = checker.getPropertyOfType(type, property.name);
|
|
61
|
-
const propType = prop?.valueDeclaration
|
|
62
|
-
? checker.getTypeAtLocation(prop?.valueDeclaration)
|
|
63
|
-
: undefined;
|
|
64
|
-
return (
|
|
65
|
-
propType !== undefined &&
|
|
66
|
-
checker.typeToString(propType) === property.type
|
|
67
|
-
);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
const getBinaryProps = (className: string): IClassInfo => ({
|
|
71
|
-
name: className,
|
|
72
|
-
methods: [
|
|
73
|
-
...["indexOf", "lastIndexOf"].map((name) => ({
|
|
74
|
-
name,
|
|
75
|
-
return: "number",
|
|
76
|
-
})),
|
|
77
|
-
...["some", "every"].map((name) => ({
|
|
78
|
-
name,
|
|
79
|
-
return: "boolean",
|
|
80
|
-
})),
|
|
81
|
-
...["join", "toLocaleString"].map((name) => ({
|
|
82
|
-
name,
|
|
83
|
-
return: "string",
|
|
84
|
-
})),
|
|
85
|
-
...["reverse", "slice", "subarray"].map((name) => ({
|
|
86
|
-
name,
|
|
87
|
-
return: className,
|
|
88
|
-
})),
|
|
89
|
-
],
|
|
90
|
-
properties: ["BYTES_PER_ELEMENT", "length", "byteLength", "byteOffset"].map(
|
|
91
|
-
(name) => ({
|
|
92
|
-
name,
|
|
93
|
-
type: "number",
|
|
94
|
-
}),
|
|
95
|
-
),
|
|
96
|
-
});
|
|
97
|
-
const SIMPLES: Map<string, IClassInfo> = new Map([
|
|
98
|
-
[
|
|
99
|
-
"Date",
|
|
100
|
-
{
|
|
101
|
-
methods: ["getTime", "getFullYear", "getMonth", "getMinutes"].map(
|
|
102
|
-
(name) => ({
|
|
103
|
-
name,
|
|
104
|
-
return: "number",
|
|
105
|
-
}),
|
|
106
|
-
),
|
|
107
|
-
},
|
|
108
|
-
],
|
|
109
|
-
[
|
|
110
|
-
"Boolean",
|
|
111
|
-
{
|
|
112
|
-
methods: [
|
|
113
|
-
{
|
|
114
|
-
name: "valueOf",
|
|
115
|
-
return: "boolean",
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
[
|
|
121
|
-
"Number",
|
|
122
|
-
{
|
|
123
|
-
methods: [
|
|
124
|
-
...["toFixed", "toExponential", "toPrecision"].map((name) => ({
|
|
125
|
-
name,
|
|
126
|
-
return: "string",
|
|
127
|
-
})),
|
|
128
|
-
{
|
|
129
|
-
name: "valueOf",
|
|
130
|
-
return: "number",
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
[
|
|
136
|
-
"String",
|
|
137
|
-
{
|
|
138
|
-
methods: [
|
|
139
|
-
"charAt",
|
|
140
|
-
"concat",
|
|
141
|
-
"valueOf",
|
|
142
|
-
"trim",
|
|
143
|
-
"replace",
|
|
144
|
-
"substring",
|
|
145
|
-
].map((name) => ({
|
|
146
|
-
name,
|
|
147
|
-
return: "string",
|
|
148
|
-
})),
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
...[
|
|
152
|
-
"Uint8Array",
|
|
153
|
-
"Uint8ClampedArray",
|
|
154
|
-
"Uint16Array",
|
|
155
|
-
"Uint32Array",
|
|
156
|
-
"BigUint64Array",
|
|
157
|
-
"Int8Array",
|
|
158
|
-
"Int16Array",
|
|
159
|
-
"Int32Array",
|
|
160
|
-
"BigInt64Array",
|
|
161
|
-
"Float32Array",
|
|
162
|
-
"Float64Array",
|
|
163
|
-
].map((name) => [name, getBinaryProps(name)] as const),
|
|
164
|
-
...["ArrayBuffer", "SharedArrayBuffer"].map((className) => {
|
|
165
|
-
const info: IClassInfo = {
|
|
166
|
-
methods: [
|
|
167
|
-
{
|
|
168
|
-
name: "slice",
|
|
169
|
-
return: className,
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
properties: [
|
|
173
|
-
{
|
|
174
|
-
name: "byteLength",
|
|
175
|
-
type: "number",
|
|
176
|
-
},
|
|
177
|
-
],
|
|
178
|
-
};
|
|
179
|
-
return [className, info] as const;
|
|
180
|
-
}),
|
|
181
|
-
[
|
|
182
|
-
"DataView",
|
|
183
|
-
{
|
|
184
|
-
methods: [
|
|
185
|
-
"getFloat32",
|
|
186
|
-
"getFloat64",
|
|
187
|
-
"getInt8",
|
|
188
|
-
"getInt16",
|
|
189
|
-
"getInt32",
|
|
190
|
-
"getUint8",
|
|
191
|
-
"getUint16",
|
|
192
|
-
"getUint32",
|
|
193
|
-
].map((name) => ({
|
|
194
|
-
name,
|
|
195
|
-
return: "number",
|
|
196
|
-
})),
|
|
197
|
-
},
|
|
198
|
-
],
|
|
199
|
-
]);
|
|
200
|
-
const COMPLICATES: Map<string, IClassInfo> = new Map([
|
|
201
|
-
[`'buffer'.global.Buffer`, getBinaryProps("Buffer")],
|
|
202
|
-
]);
|
|
203
|
-
const GENERICS: Array<IClassInfo & { name: string }> = [
|
|
204
|
-
"WeakMap",
|
|
205
|
-
"WeakSet",
|
|
206
|
-
].map((name) => ({
|
|
207
|
-
name,
|
|
208
|
-
methods: ["has", "delete"].map((name) => ({
|
|
209
|
-
name,
|
|
210
|
-
return: "boolean",
|
|
211
|
-
})),
|
|
212
|
-
}));
|
|
213
|
-
const FORBIDDEN: Set<string> = new Set(["Bolean", "Number", "String"]);
|
|
214
|
-
|
|
215
|
-
interface IClassInfo {
|
|
216
|
-
name?: string;
|
|
217
|
-
methods?: IMethod[];
|
|
218
|
-
properties?: IProperty[];
|
|
219
|
-
}
|
|
220
|
-
interface IProperty {
|
|
221
|
-
name: string;
|
|
222
|
-
type: string;
|
|
223
|
-
}
|
|
224
|
-
interface IMethod {
|
|
225
|
-
name: string;
|
|
226
|
-
return: string;
|
|
227
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
4
|
+
|
|
5
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
6
|
+
|
|
7
|
+
import { TypeFactory } from "../TypeFactory";
|
|
8
|
+
|
|
9
|
+
export const iterate_metadata_native =
|
|
10
|
+
(checker: ts.TypeChecker) =>
|
|
11
|
+
(meta: Metadata, type: ts.Type): boolean => {
|
|
12
|
+
const validator = validate(checker)(type);
|
|
13
|
+
const name: string = TypeFactory.getFullName(
|
|
14
|
+
checker,
|
|
15
|
+
type,
|
|
16
|
+
type.getSymbol(),
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const simple = SIMPLES.get(name);
|
|
20
|
+
if (simple && validator(simple)) {
|
|
21
|
+
if (FORBIDDEN.has(name))
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Error on typia.metadata(): typia does not allow "${name}" class type. Use "${name.toLowerCase()}" type instead.`,
|
|
24
|
+
);
|
|
25
|
+
ArrayUtil.set(meta.natives, name, (str) => str);
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const complicate = COMPLICATES.get(name);
|
|
30
|
+
if (complicate && validator(complicate)) {
|
|
31
|
+
ArrayUtil.set(meta.natives, complicate.name ?? name, (str) => str);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
for (const generic of GENERICS)
|
|
36
|
+
if (
|
|
37
|
+
name.substring(0, generic.name.length) === generic.name &&
|
|
38
|
+
validator(generic)
|
|
39
|
+
) {
|
|
40
|
+
ArrayUtil.set(meta.natives, generic.name ?? name, (str) => str);
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const validate =
|
|
47
|
+
(checker: ts.TypeChecker) => (type: ts.Type) => (info: IClassInfo) =>
|
|
48
|
+
(info.methods ?? []).every((method) => {
|
|
49
|
+
const returnType = TypeFactory.getReturnType(
|
|
50
|
+
checker,
|
|
51
|
+
type,
|
|
52
|
+
method.name,
|
|
53
|
+
);
|
|
54
|
+
return (
|
|
55
|
+
returnType !== null &&
|
|
56
|
+
checker.typeToString(returnType) === method.return
|
|
57
|
+
);
|
|
58
|
+
}) &&
|
|
59
|
+
(info.properties ?? []).every((property) => {
|
|
60
|
+
const prop = checker.getPropertyOfType(type, property.name);
|
|
61
|
+
const propType = prop?.valueDeclaration
|
|
62
|
+
? checker.getTypeAtLocation(prop?.valueDeclaration)
|
|
63
|
+
: undefined;
|
|
64
|
+
return (
|
|
65
|
+
propType !== undefined &&
|
|
66
|
+
checker.typeToString(propType) === property.type
|
|
67
|
+
);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const getBinaryProps = (className: string): IClassInfo => ({
|
|
71
|
+
name: className,
|
|
72
|
+
methods: [
|
|
73
|
+
...["indexOf", "lastIndexOf"].map((name) => ({
|
|
74
|
+
name,
|
|
75
|
+
return: "number",
|
|
76
|
+
})),
|
|
77
|
+
...["some", "every"].map((name) => ({
|
|
78
|
+
name,
|
|
79
|
+
return: "boolean",
|
|
80
|
+
})),
|
|
81
|
+
...["join", "toLocaleString"].map((name) => ({
|
|
82
|
+
name,
|
|
83
|
+
return: "string",
|
|
84
|
+
})),
|
|
85
|
+
...["reverse", "slice", "subarray"].map((name) => ({
|
|
86
|
+
name,
|
|
87
|
+
return: className,
|
|
88
|
+
})),
|
|
89
|
+
],
|
|
90
|
+
properties: ["BYTES_PER_ELEMENT", "length", "byteLength", "byteOffset"].map(
|
|
91
|
+
(name) => ({
|
|
92
|
+
name,
|
|
93
|
+
type: "number",
|
|
94
|
+
}),
|
|
95
|
+
),
|
|
96
|
+
});
|
|
97
|
+
const SIMPLES: Map<string, IClassInfo> = new Map([
|
|
98
|
+
[
|
|
99
|
+
"Date",
|
|
100
|
+
{
|
|
101
|
+
methods: ["getTime", "getFullYear", "getMonth", "getMinutes"].map(
|
|
102
|
+
(name) => ({
|
|
103
|
+
name,
|
|
104
|
+
return: "number",
|
|
105
|
+
}),
|
|
106
|
+
),
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"Boolean",
|
|
111
|
+
{
|
|
112
|
+
methods: [
|
|
113
|
+
{
|
|
114
|
+
name: "valueOf",
|
|
115
|
+
return: "boolean",
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
[
|
|
121
|
+
"Number",
|
|
122
|
+
{
|
|
123
|
+
methods: [
|
|
124
|
+
...["toFixed", "toExponential", "toPrecision"].map((name) => ({
|
|
125
|
+
name,
|
|
126
|
+
return: "string",
|
|
127
|
+
})),
|
|
128
|
+
{
|
|
129
|
+
name: "valueOf",
|
|
130
|
+
return: "number",
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
[
|
|
136
|
+
"String",
|
|
137
|
+
{
|
|
138
|
+
methods: [
|
|
139
|
+
"charAt",
|
|
140
|
+
"concat",
|
|
141
|
+
"valueOf",
|
|
142
|
+
"trim",
|
|
143
|
+
"replace",
|
|
144
|
+
"substring",
|
|
145
|
+
].map((name) => ({
|
|
146
|
+
name,
|
|
147
|
+
return: "string",
|
|
148
|
+
})),
|
|
149
|
+
},
|
|
150
|
+
],
|
|
151
|
+
...[
|
|
152
|
+
"Uint8Array",
|
|
153
|
+
"Uint8ClampedArray",
|
|
154
|
+
"Uint16Array",
|
|
155
|
+
"Uint32Array",
|
|
156
|
+
"BigUint64Array",
|
|
157
|
+
"Int8Array",
|
|
158
|
+
"Int16Array",
|
|
159
|
+
"Int32Array",
|
|
160
|
+
"BigInt64Array",
|
|
161
|
+
"Float32Array",
|
|
162
|
+
"Float64Array",
|
|
163
|
+
].map((name) => [name, getBinaryProps(name)] as const),
|
|
164
|
+
...["ArrayBuffer", "SharedArrayBuffer"].map((className) => {
|
|
165
|
+
const info: IClassInfo = {
|
|
166
|
+
methods: [
|
|
167
|
+
{
|
|
168
|
+
name: "slice",
|
|
169
|
+
return: className,
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
properties: [
|
|
173
|
+
{
|
|
174
|
+
name: "byteLength",
|
|
175
|
+
type: "number",
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
return [className, info] as const;
|
|
180
|
+
}),
|
|
181
|
+
[
|
|
182
|
+
"DataView",
|
|
183
|
+
{
|
|
184
|
+
methods: [
|
|
185
|
+
"getFloat32",
|
|
186
|
+
"getFloat64",
|
|
187
|
+
"getInt8",
|
|
188
|
+
"getInt16",
|
|
189
|
+
"getInt32",
|
|
190
|
+
"getUint8",
|
|
191
|
+
"getUint16",
|
|
192
|
+
"getUint32",
|
|
193
|
+
].map((name) => ({
|
|
194
|
+
name,
|
|
195
|
+
return: "number",
|
|
196
|
+
})),
|
|
197
|
+
},
|
|
198
|
+
],
|
|
199
|
+
]);
|
|
200
|
+
const COMPLICATES: Map<string, IClassInfo> = new Map([
|
|
201
|
+
[`'buffer'.global.Buffer`, getBinaryProps("Buffer")],
|
|
202
|
+
]);
|
|
203
|
+
const GENERICS: Array<IClassInfo & { name: string }> = [
|
|
204
|
+
"WeakMap",
|
|
205
|
+
"WeakSet",
|
|
206
|
+
].map((name) => ({
|
|
207
|
+
name,
|
|
208
|
+
methods: ["has", "delete"].map((name) => ({
|
|
209
|
+
name,
|
|
210
|
+
return: "boolean",
|
|
211
|
+
})),
|
|
212
|
+
}));
|
|
213
|
+
const FORBIDDEN: Set<string> = new Set(["Bolean", "Number", "String"]);
|
|
214
|
+
|
|
215
|
+
interface IClassInfo {
|
|
216
|
+
name?: string;
|
|
217
|
+
methods?: IMethod[];
|
|
218
|
+
properties?: IProperty[];
|
|
219
|
+
}
|
|
220
|
+
interface IProperty {
|
|
221
|
+
name: string;
|
|
222
|
+
type: string;
|
|
223
|
+
}
|
|
224
|
+
interface IMethod {
|
|
225
|
+
name: string;
|
|
226
|
+
return: string;
|
|
227
|
+
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
-
|
|
3
|
-
export function $number(value: number): number {
|
|
4
|
-
if (!isFinite(value))
|
|
5
|
-
throw new TypeGuardError({
|
|
6
|
-
method: "typia.stringify",
|
|
7
|
-
expected: "number",
|
|
8
|
-
value,
|
|
9
|
-
message: "Error on typia.stringify(): infinite number.",
|
|
10
|
-
});
|
|
11
|
-
else if (isNaN(value))
|
|
12
|
-
throw new TypeGuardError({
|
|
13
|
-
method: "typia.stringify",
|
|
14
|
-
expected: "number",
|
|
15
|
-
value,
|
|
16
|
-
message: "Error on typia.stringify(): not a valid number.",
|
|
17
|
-
});
|
|
18
|
-
return value;
|
|
19
|
-
}
|
|
1
|
+
import { TypeGuardError } from "../TypeGuardError";
|
|
2
|
+
|
|
3
|
+
export function $number(value: number): number {
|
|
4
|
+
if (!isFinite(value))
|
|
5
|
+
throw new TypeGuardError({
|
|
6
|
+
method: "typia.stringify",
|
|
7
|
+
expected: "number",
|
|
8
|
+
value,
|
|
9
|
+
message: "Error on typia.stringify(): infinite number.",
|
|
10
|
+
});
|
|
11
|
+
else if (isNaN(value))
|
|
12
|
+
throw new TypeGuardError({
|
|
13
|
+
method: "typia.stringify",
|
|
14
|
+
expected: "number",
|
|
15
|
+
value,
|
|
16
|
+
message: "Error on typia.stringify(): not a valid number.",
|
|
17
|
+
});
|
|
18
|
+
return value;
|
|
19
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as typia from "./module";
|
|
2
|
-
|
|
3
|
-
export default typia;
|
|
4
|
-
export * from "./module";
|
|
1
|
+
import * as typia from "./module";
|
|
2
|
+
|
|
3
|
+
export default typia;
|
|
4
|
+
export * from "./module";
|