typia 3.7.1 → 3.7.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.
Files changed (53) hide show
  1. package/README.md +3 -1
  2. package/lib/module.d.ts +33 -0
  3. package/lib/module.js +5 -1
  4. package/lib/module.js.map +1 -1
  5. package/lib/programmers/LiteralsProgrammer.d.ts +5 -0
  6. package/lib/programmers/LiteralsProgrammer.js +75 -0
  7. package/lib/programmers/LiteralsProgrammer.js.map +1 -0
  8. package/lib/transformers/CallExpressionTransformer.js +2 -0
  9. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  10. package/lib/transformers/ImportTransformer.js +8 -1
  11. package/lib/transformers/ImportTransformer.js.map +1 -1
  12. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +6 -3
  13. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  14. package/lib/transformers/features/miscellaneous/CreateRandomTransformer.js +4 -2
  15. package/lib/transformers/features/miscellaneous/CreateRandomTransformer.js.map +1 -1
  16. package/lib/transformers/features/miscellaneous/LiteralsTransformer.d.ts +5 -0
  17. package/lib/transformers/features/miscellaneous/LiteralsTransformer.js +21 -0
  18. package/lib/transformers/features/miscellaneous/LiteralsTransformer.js.map +1 -0
  19. package/lib/transformers/features/miscellaneous/MetadataTransformer.js +4 -2
  20. package/lib/transformers/features/miscellaneous/MetadataTransformer.js.map +1 -1
  21. package/lib/transformers/features/miscellaneous/RandomTransformer.js +4 -2
  22. package/lib/transformers/features/miscellaneous/RandomTransformer.js.map +1 -1
  23. package/package.json +2 -2
  24. package/src/IRandomGenerator.ts +33 -33
  25. package/src/factories/IdentifierFactory.ts +81 -81
  26. package/src/factories/MetadataTagFactory.ts +302 -302
  27. package/src/metadata/ICommentTag.ts +4 -4
  28. package/src/module.ts +43 -0
  29. package/src/programmers/LiteralsProgrammer.ts +65 -0
  30. package/src/programmers/RandomProgrammer.ts +413 -413
  31. package/src/programmers/helpers/RandomJoiner.ts +161 -161
  32. package/src/programmers/helpers/RandomRanger.ts +216 -216
  33. package/src/programmers/internal/application_native.ts +32 -32
  34. package/src/programmers/internal/check_array.ts +30 -30
  35. package/src/programmers/internal/check_array_length.ts +35 -35
  36. package/src/programmers/internal/check_custom.ts +33 -33
  37. package/src/programmers/internal/check_number.ts +177 -177
  38. package/src/programmers/internal/check_object.ts +55 -55
  39. package/src/programmers/internal/check_union_array_like.ts +272 -272
  40. package/src/programmers/internal/feature_object_entries.ts +63 -63
  41. package/src/programmers/internal/get_comment_tags.ts +23 -23
  42. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  43. package/src/programmers/internal/random_custom.ts +30 -30
  44. package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
  45. package/src/programmers/internal/stringify_regular_properties.ts +84 -84
  46. package/src/transformers/CallExpressionTransformer.ts +174 -172
  47. package/src/transformers/ImportTransformer.ts +9 -3
  48. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +8 -9
  49. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -43
  50. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -0
  51. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +5 -6
  52. package/src/transformers/features/miscellaneous/RandomTransformer.ts +6 -8
  53. package/src/typings/Customizable.ts +5 -5
@@ -1,33 +1,33 @@
1
- import ts from "typescript";
2
-
3
- import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
-
5
- import { FunctionImporter } from "../helpers/FunctionImporeter";
6
- import { ICheckEntry } from "../helpers/ICheckEntry";
7
- import { get_comment_tags } from "./get_comment_tags";
8
-
9
- /**
10
- * @internal
11
- */
12
- export const check_custom =
13
- (type: string, alias?: string) =>
14
- (importer: FunctionImporter) =>
15
- (jsDocTags: IJsDocTagInfo[]) =>
16
- (input: ts.Expression): ICheckEntry.ITag[] =>
17
- get_comment_tags(true)(jsDocTags).map((tag) => {
18
- return {
19
- expected: `${alias ?? type} (@${tag.name}${
20
- tag.value?.length ? ` ${tag.value}` : ""
21
- })`,
22
- expression: ts.factory.createCallExpression(
23
- importer.use("is_custom"),
24
- undefined,
25
- [
26
- ts.factory.createStringLiteral(tag.name),
27
- ts.factory.createStringLiteral(type),
28
- ts.factory.createStringLiteral(tag.value ?? ""),
29
- input,
30
- ],
31
- ),
32
- };
33
- });
1
+ import ts from "typescript";
2
+
3
+ import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
+
5
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
6
+ import { ICheckEntry } from "../helpers/ICheckEntry";
7
+ import { get_comment_tags } from "./get_comment_tags";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export const check_custom =
13
+ (type: string, alias?: string) =>
14
+ (importer: FunctionImporter) =>
15
+ (jsDocTags: IJsDocTagInfo[]) =>
16
+ (input: ts.Expression): ICheckEntry.ITag[] =>
17
+ get_comment_tags(true)(jsDocTags).map((tag) => {
18
+ return {
19
+ expected: `${alias ?? type} (@${tag.name}${
20
+ tag.value?.length ? ` ${tag.value}` : ""
21
+ })`,
22
+ expression: ts.factory.createCallExpression(
23
+ importer.use("is_custom"),
24
+ undefined,
25
+ [
26
+ ts.factory.createStringLiteral(tag.name),
27
+ ts.factory.createStringLiteral(type),
28
+ ts.factory.createStringLiteral(tag.value ?? ""),
29
+ input,
30
+ ],
31
+ ),
32
+ };
33
+ });
@@ -1,177 +1,177 @@
1
- import ts from "typescript";
2
-
3
- import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
- import { IMetadataTag } from "../../metadata/IMetadataTag";
5
-
6
- import { IProject } from "../../transformers/IProject";
7
-
8
- import { FunctionImporter } from "../helpers/FunctionImporeter";
9
- import { ICheckEntry } from "../helpers/ICheckEntry";
10
- import { OptionPredicator } from "../helpers/OptionPredicator";
11
- import { check_custom } from "./check_custom";
12
-
13
- /**
14
- * @internal
15
- */
16
- export const check_number =
17
- (project: IProject, numeric: boolean) =>
18
- (importer: FunctionImporter) =>
19
- (metaTags: IMetadataTag[]) =>
20
- (jsDocTag: IJsDocTagInfo[]) =>
21
- (input: ts.Expression): ICheckEntry => {
22
- const entries: [IMetadataTag, ts.Expression][] = [];
23
- for (const tag of metaTags)
24
- if (tag.kind === "type") {
25
- entries.push([
26
- tag,
27
- ts.factory.createStrictEquality(
28
- ts.factory.createCallExpression(
29
- ts.factory.createIdentifier("parseInt"),
30
- undefined,
31
- [input],
32
- ),
33
- input,
34
- ),
35
- ]);
36
- if (tag.value === "uint")
37
- entries.push([
38
- tag,
39
- ts.factory.createLessThanEquals(
40
- ts.factory.createNumericLiteral(0),
41
- input,
42
- ),
43
- ]);
44
- } else if (tag.kind === "multipleOf")
45
- entries.push([
46
- tag,
47
- ts.factory.createStrictEquality(
48
- ts.factory.createNumericLiteral(0),
49
- ts.factory.createModulo(
50
- input,
51
- ts.factory.createNumericLiteral(tag.value),
52
- ),
53
- ),
54
- ]);
55
- else if (tag.kind === "step") {
56
- const modulo = ts.factory.createModulo(
57
- input,
58
- ts.factory.createNumericLiteral(tag.value),
59
- );
60
- const minimum =
61
- (metaTags.find(
62
- (tag) =>
63
- tag.kind === "minimum" ||
64
- tag.kind === "exclusiveMinimum",
65
- )?.value as number | undefined) ?? undefined;
66
- entries.push([
67
- tag,
68
- ts.factory.createStrictEquality(
69
- ts.factory.createNumericLiteral(0),
70
- minimum !== undefined
71
- ? ts.factory.createSubtract(
72
- modulo,
73
- ts.factory.createNumericLiteral(minimum),
74
- )
75
- : modulo,
76
- ),
77
- ]);
78
- } else if (tag.kind === "minimum")
79
- entries.push([
80
- tag,
81
- ts.factory.createLessThanEquals(
82
- ts.factory.createNumericLiteral(tag.value),
83
- input,
84
- ),
85
- ]);
86
- else if (tag.kind === "maximum")
87
- entries.push([
88
- tag,
89
- ts.factory.createGreaterThanEquals(
90
- ts.factory.createNumericLiteral(tag.value),
91
- input,
92
- ),
93
- ]);
94
- else if (tag.kind === "exclusiveMinimum")
95
- entries.push([
96
- tag,
97
- ts.factory.createLessThan(
98
- ts.factory.createNumericLiteral(tag.value),
99
- input,
100
- ),
101
- ]);
102
- else if (tag.kind === "exclusiveMaximum")
103
- entries.push([
104
- tag,
105
- ts.factory.createGreaterThan(
106
- ts.factory.createNumericLiteral(tag.value),
107
- input,
108
- ),
109
- ]);
110
-
111
- return {
112
- expression: is_number(project, numeric)(metaTags)(input),
113
- tags: [
114
- ...entries.map(([tag, expression]) => ({
115
- expected: `number (@${tag.kind} ${tag.value})`,
116
- expression,
117
- })),
118
- ...check_custom("number")(importer)(jsDocTag)(input),
119
- ],
120
- };
121
- };
122
-
123
- /**
124
- * @internal
125
- */
126
- const is_number =
127
- ({ options }: IProject, numeric: boolean) =>
128
- (metaTags: IMetadataTag[]) =>
129
- (input: ts.Expression) => {
130
- // TYPEOF STATEMENT
131
- const conditions: ts.Expression[] = [
132
- ts.factory.createStrictEquality(
133
- ts.factory.createStringLiteral("number"),
134
- ts.factory.createTypeOfExpression(input),
135
- ),
136
- ];
137
-
138
- // CHECK FINITE AND NAN
139
- const finite: boolean =
140
- (!!metaTags.find(
141
- (tag) =>
142
- tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
143
- ) &&
144
- !!metaTags.find(
145
- (tag) =>
146
- tag.kind === "maximum" ||
147
- tag.kind === "exclusiveMaximum",
148
- )) ||
149
- !!metaTags.find(
150
- (tag) => tag.kind === "step" || tag.kind === "multipleOf",
151
- );
152
-
153
- if (numeric === true && finite === false)
154
- if (OptionPredicator.finite(options))
155
- conditions.push(
156
- ts.factory.createCallExpression(
157
- ts.factory.createIdentifier("Number.isFinite"),
158
- undefined,
159
- [input],
160
- ),
161
- );
162
- else if (OptionPredicator.numeric(options))
163
- conditions.push(
164
- ts.factory.createLogicalNot(
165
- ts.factory.createCallExpression(
166
- ts.factory.createIdentifier("Number.isNaN"),
167
- undefined,
168
- [input],
169
- ),
170
- ),
171
- );
172
-
173
- // COMBINATE
174
- return conditions.length === 1
175
- ? conditions[0]!
176
- : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
177
- };
1
+ import ts from "typescript";
2
+
3
+ import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
4
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
5
+
6
+ import { IProject } from "../../transformers/IProject";
7
+
8
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
9
+ import { ICheckEntry } from "../helpers/ICheckEntry";
10
+ import { OptionPredicator } from "../helpers/OptionPredicator";
11
+ import { check_custom } from "./check_custom";
12
+
13
+ /**
14
+ * @internal
15
+ */
16
+ export const check_number =
17
+ (project: IProject, numeric: boolean) =>
18
+ (importer: FunctionImporter) =>
19
+ (metaTags: IMetadataTag[]) =>
20
+ (jsDocTag: IJsDocTagInfo[]) =>
21
+ (input: ts.Expression): ICheckEntry => {
22
+ const entries: [IMetadataTag, ts.Expression][] = [];
23
+ for (const tag of metaTags)
24
+ if (tag.kind === "type") {
25
+ entries.push([
26
+ tag,
27
+ ts.factory.createStrictEquality(
28
+ ts.factory.createCallExpression(
29
+ ts.factory.createIdentifier("parseInt"),
30
+ undefined,
31
+ [input],
32
+ ),
33
+ input,
34
+ ),
35
+ ]);
36
+ if (tag.value === "uint")
37
+ entries.push([
38
+ tag,
39
+ ts.factory.createLessThanEquals(
40
+ ts.factory.createNumericLiteral(0),
41
+ input,
42
+ ),
43
+ ]);
44
+ } else if (tag.kind === "multipleOf")
45
+ entries.push([
46
+ tag,
47
+ ts.factory.createStrictEquality(
48
+ ts.factory.createNumericLiteral(0),
49
+ ts.factory.createModulo(
50
+ input,
51
+ ts.factory.createNumericLiteral(tag.value),
52
+ ),
53
+ ),
54
+ ]);
55
+ else if (tag.kind === "step") {
56
+ const modulo = ts.factory.createModulo(
57
+ input,
58
+ ts.factory.createNumericLiteral(tag.value),
59
+ );
60
+ const minimum =
61
+ (metaTags.find(
62
+ (tag) =>
63
+ tag.kind === "minimum" ||
64
+ tag.kind === "exclusiveMinimum",
65
+ )?.value as number | undefined) ?? undefined;
66
+ entries.push([
67
+ tag,
68
+ ts.factory.createStrictEquality(
69
+ ts.factory.createNumericLiteral(0),
70
+ minimum !== undefined
71
+ ? ts.factory.createSubtract(
72
+ modulo,
73
+ ts.factory.createNumericLiteral(minimum),
74
+ )
75
+ : modulo,
76
+ ),
77
+ ]);
78
+ } else if (tag.kind === "minimum")
79
+ entries.push([
80
+ tag,
81
+ ts.factory.createLessThanEquals(
82
+ ts.factory.createNumericLiteral(tag.value),
83
+ input,
84
+ ),
85
+ ]);
86
+ else if (tag.kind === "maximum")
87
+ entries.push([
88
+ tag,
89
+ ts.factory.createGreaterThanEquals(
90
+ ts.factory.createNumericLiteral(tag.value),
91
+ input,
92
+ ),
93
+ ]);
94
+ else if (tag.kind === "exclusiveMinimum")
95
+ entries.push([
96
+ tag,
97
+ ts.factory.createLessThan(
98
+ ts.factory.createNumericLiteral(tag.value),
99
+ input,
100
+ ),
101
+ ]);
102
+ else if (tag.kind === "exclusiveMaximum")
103
+ entries.push([
104
+ tag,
105
+ ts.factory.createGreaterThan(
106
+ ts.factory.createNumericLiteral(tag.value),
107
+ input,
108
+ ),
109
+ ]);
110
+
111
+ return {
112
+ expression: is_number(project, numeric)(metaTags)(input),
113
+ tags: [
114
+ ...entries.map(([tag, expression]) => ({
115
+ expected: `number (@${tag.kind} ${tag.value})`,
116
+ expression,
117
+ })),
118
+ ...check_custom("number")(importer)(jsDocTag)(input),
119
+ ],
120
+ };
121
+ };
122
+
123
+ /**
124
+ * @internal
125
+ */
126
+ const is_number =
127
+ ({ options }: IProject, numeric: boolean) =>
128
+ (metaTags: IMetadataTag[]) =>
129
+ (input: ts.Expression) => {
130
+ // TYPEOF STATEMENT
131
+ const conditions: ts.Expression[] = [
132
+ ts.factory.createStrictEquality(
133
+ ts.factory.createStringLiteral("number"),
134
+ ts.factory.createTypeOfExpression(input),
135
+ ),
136
+ ];
137
+
138
+ // CHECK FINITE AND NAN
139
+ const finite: boolean =
140
+ (!!metaTags.find(
141
+ (tag) =>
142
+ tag.kind === "minimum" || tag.kind === "exclusiveMinimum",
143
+ ) &&
144
+ !!metaTags.find(
145
+ (tag) =>
146
+ tag.kind === "maximum" ||
147
+ tag.kind === "exclusiveMaximum",
148
+ )) ||
149
+ !!metaTags.find(
150
+ (tag) => tag.kind === "step" || tag.kind === "multipleOf",
151
+ );
152
+
153
+ if (numeric === true && finite === false)
154
+ if (OptionPredicator.finite(options))
155
+ conditions.push(
156
+ ts.factory.createCallExpression(
157
+ ts.factory.createIdentifier("Number.isFinite"),
158
+ undefined,
159
+ [input],
160
+ ),
161
+ );
162
+ else if (OptionPredicator.numeric(options))
163
+ conditions.push(
164
+ ts.factory.createLogicalNot(
165
+ ts.factory.createCallExpression(
166
+ ts.factory.createIdentifier("Number.isNaN"),
167
+ undefined,
168
+ [input],
169
+ ),
170
+ ),
171
+ );
172
+
173
+ // COMBINATE
174
+ return conditions.length === 1
175
+ ? conditions[0]!
176
+ : conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
177
+ };
@@ -1,55 +1,55 @@
1
- import ts from "typescript";
2
-
3
- import { FunctionImporter } from "../helpers/FunctionImporeter";
4
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
5
- import { check_dynamic_properties } from "./check_dynamic_properties";
6
- import { check_everything } from "./check_everything";
7
-
8
- /**
9
- * @internal
10
- */
11
- export const check_object =
12
- (props: check_object.IProps) =>
13
- (importer: FunctionImporter) =>
14
- (input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
15
- // PREPARE ASSETS
16
- const regular = entries.filter((entry) => entry.key.isSoleLiteral());
17
- const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
18
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
19
-
20
- // REGULAR WITHOUT DYNAMIC PROPERTIES
21
- if (props.equals === false && dynamic.length === 0)
22
- return regular.length === 0 ? props.positive : reduce(props)(flags);
23
-
24
- // CHECK DYNAMIC PROPERTIES
25
- flags.push(
26
- check_dynamic_properties(props)(importer)(input, regular, dynamic),
27
- );
28
- return reduce(props)(flags);
29
- };
30
-
31
- /**
32
- * @internal
33
- */
34
- export namespace check_object {
35
- export interface IProps {
36
- equals: boolean;
37
- assert: boolean;
38
- undefined: boolean;
39
- halt?: (exp: ts.Expression) => ts.Expression;
40
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
41
- positive: ts.Expression;
42
- superfluous: (value: ts.Expression) => ts.Expression;
43
- entries?: ts.Identifier;
44
- }
45
- }
46
-
47
- /**
48
- * @internal
49
- */
50
- const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
51
- props.assert
52
- ? expressions.reduce(props.reduce)
53
- : check_everything(
54
- ts.factory.createArrayLiteralExpression(expressions),
55
- );
1
+ import ts from "typescript";
2
+
3
+ import { FunctionImporter } from "../helpers/FunctionImporeter";
4
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
5
+ import { check_dynamic_properties } from "./check_dynamic_properties";
6
+ import { check_everything } from "./check_everything";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export const check_object =
12
+ (props: check_object.IProps) =>
13
+ (importer: FunctionImporter) =>
14
+ (input: ts.Expression, entries: IExpressionEntry<ts.Expression>[]) => {
15
+ // PREPARE ASSETS
16
+ const regular = entries.filter((entry) => entry.key.isSoleLiteral());
17
+ const dynamic = entries.filter((entry) => !entry.key.isSoleLiteral());
18
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
19
+
20
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
21
+ if (props.equals === false && dynamic.length === 0)
22
+ return regular.length === 0 ? props.positive : reduce(props)(flags);
23
+
24
+ // CHECK DYNAMIC PROPERTIES
25
+ flags.push(
26
+ check_dynamic_properties(props)(importer)(input, regular, dynamic),
27
+ );
28
+ return reduce(props)(flags);
29
+ };
30
+
31
+ /**
32
+ * @internal
33
+ */
34
+ export namespace check_object {
35
+ export interface IProps {
36
+ equals: boolean;
37
+ assert: boolean;
38
+ undefined: boolean;
39
+ halt?: (exp: ts.Expression) => ts.Expression;
40
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
41
+ positive: ts.Expression;
42
+ superfluous: (value: ts.Expression) => ts.Expression;
43
+ entries?: ts.Identifier;
44
+ }
45
+ }
46
+
47
+ /**
48
+ * @internal
49
+ */
50
+ const reduce = (props: check_object.IProps) => (expressions: ts.Expression[]) =>
51
+ props.assert
52
+ ? expressions.reduce(props.reduce)
53
+ : check_everything(
54
+ ts.factory.createArrayLiteralExpression(expressions),
55
+ );