typia 3.8.0-dev.20230415 → 3.8.0-dev.20230417

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 +35 -228
  2. package/lib/factories/TypiaFileFactory.js +9 -4
  3. package/lib/factories/TypiaFileFactory.js.map +1 -1
  4. package/lib/typings/Customizable.d.ts +2 -2
  5. package/lib/utils/RandomGenerator.d.ts +17 -1
  6. package/lib/utils/RandomGenerator.js.map +1 -1
  7. package/package.json +1 -1
  8. package/src/IRandomGenerator.ts +33 -33
  9. package/src/executable/TypiaGenerateWizard.ts +85 -85
  10. package/src/executable/TypiaSetupWizard.ts +118 -118
  11. package/src/executable/setup/ArgumentParser.ts +45 -45
  12. package/src/executable/setup/CommandExecutor.ts +8 -8
  13. package/src/executable/setup/FileRetriever.ts +22 -22
  14. package/src/executable/setup/PackageManager.ts +71 -71
  15. package/src/executable/setup/PluginConfigurator.ts +59 -59
  16. package/src/executable/typia.ts +52 -52
  17. package/src/factories/IdentifierFactory.ts +59 -59
  18. package/src/factories/MetadataTagFactory.ts +302 -302
  19. package/src/factories/TypiaFileFactory.ts +12 -3
  20. package/src/metadata/ICommentTag.ts +4 -4
  21. package/src/metadata/Metadata.ts +533 -533
  22. package/src/module.ts +2043 -2043
  23. package/src/programmers/AssertProgrammer.ts +284 -284
  24. package/src/programmers/CheckerProgrammer.ts +920 -920
  25. package/src/programmers/LiteralsProgrammer.ts +65 -65
  26. package/src/programmers/RandomProgrammer.ts +413 -413
  27. package/src/programmers/ValidateProgrammer.ts +317 -317
  28. package/src/programmers/helpers/RandomJoiner.ts +161 -161
  29. package/src/programmers/helpers/RandomRanger.ts +216 -216
  30. package/src/programmers/internal/application_native.ts +32 -32
  31. package/src/programmers/internal/check_array.ts +30 -30
  32. package/src/programmers/internal/check_array_length.ts +35 -35
  33. package/src/programmers/internal/check_custom.ts +33 -33
  34. package/src/programmers/internal/check_number.ts +177 -177
  35. package/src/programmers/internal/check_object.ts +55 -55
  36. package/src/programmers/internal/check_string_tags.ts +67 -67
  37. package/src/programmers/internal/check_template.ts +56 -56
  38. package/src/programmers/internal/check_union_array_like.ts +272 -272
  39. package/src/programmers/internal/feature_object_entries.ts +63 -63
  40. package/src/programmers/internal/get_comment_tags.ts +23 -23
  41. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  42. package/src/programmers/internal/random_custom.ts +30 -30
  43. package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
  44. package/src/programmers/internal/stringify_regular_properties.ts +84 -84
  45. package/src/transformers/CallExpressionTransformer.ts +174 -174
  46. package/src/transformers/ImportTransformer.ts +66 -66
  47. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
  48. package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
  49. package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
  50. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
  51. package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
  52. package/src/typings/Customizable.ts +5 -5
  53. package/src/utils/RandomGenerator.ts +93 -96
@@ -1,84 +1,84 @@
1
- import ts from "typescript";
2
-
3
- import { TemplateFactory } from "../../factories/TemplateFactory";
4
- import { ValueFactory } from "../../factories/ValueFactory";
5
-
6
- import { Metadata } from "../../metadata/Metadata";
7
-
8
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
9
-
10
- /**
11
- * @internal
12
- */
13
- export function stringify_regular_properties(
14
- regular: IExpressionEntry<ts.Expression>[],
15
- dynamic: IExpressionEntry<ts.Expression>[],
16
- ): ts.Expression[] {
17
- const output: ts.Expression[] = [];
18
-
19
- regular.sort((x, y) => sequence(x.meta) - sequence(y.meta));
20
- regular.forEach((entry, index) => {
21
- // BASE ELEMENTS
22
- const key: string = entry.key.getSoleLiteral()!;
23
- const base: ts.Expression[] = [
24
- ts.factory.createStringLiteral(`${JSON.stringify(key)}:`),
25
- entry.expression,
26
- ];
27
- if (index !== regular.length - 1 || dynamic.length !== 0)
28
- base.push(ts.factory.createStringLiteral(`,`));
29
-
30
- const empty: boolean =
31
- (entry.meta.required === false &&
32
- entry.meta.nullable === false &&
33
- entry.meta.size() === 0) ||
34
- (entry.meta.functional &&
35
- entry.meta.nullable === false &&
36
- entry.meta.size() === 1);
37
-
38
- if (empty === true) return;
39
- else if (
40
- entry.meta.required === false ||
41
- entry.meta.functional === true ||
42
- entry.meta.any === true
43
- )
44
- output.push(
45
- ts.factory.createConditionalExpression(
46
- (() => {
47
- const conditions: ts.BinaryExpression[] = [];
48
- if (entry.meta.required === false || entry.meta.any)
49
- conditions.push(
50
- ts.factory.createStrictEquality(
51
- ts.factory.createIdentifier("undefined"),
52
- entry.input,
53
- ),
54
- );
55
- if (entry.meta.functional || entry.meta.any)
56
- conditions.push(
57
- ts.factory.createStrictEquality(
58
- ts.factory.createStringLiteral("function"),
59
- ValueFactory.TYPEOF(entry.input),
60
- ),
61
- );
62
- return conditions.length === 1
63
- ? conditions[0]!
64
- : conditions.reduce((x, y) =>
65
- ts.factory.createLogicalOr(x, y),
66
- );
67
- })(),
68
- undefined,
69
- ts.factory.createStringLiteral(""),
70
- undefined,
71
- TemplateFactory.generate(base),
72
- ),
73
- );
74
- else output.push(...base);
75
- });
76
- return output;
77
- }
78
-
79
- /**
80
- * @internal
81
- */
82
- function sequence(meta: Metadata): number {
83
- return meta.any || !meta.required || meta.functional ? 0 : 1;
84
- }
1
+ import ts from "typescript";
2
+
3
+ import { TemplateFactory } from "../../factories/TemplateFactory";
4
+ import { ValueFactory } from "../../factories/ValueFactory";
5
+
6
+ import { Metadata } from "../../metadata/Metadata";
7
+
8
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export function stringify_regular_properties(
14
+ regular: IExpressionEntry<ts.Expression>[],
15
+ dynamic: IExpressionEntry<ts.Expression>[],
16
+ ): ts.Expression[] {
17
+ const output: ts.Expression[] = [];
18
+
19
+ regular.sort((x, y) => sequence(x.meta) - sequence(y.meta));
20
+ regular.forEach((entry, index) => {
21
+ // BASE ELEMENTS
22
+ const key: string = entry.key.getSoleLiteral()!;
23
+ const base: ts.Expression[] = [
24
+ ts.factory.createStringLiteral(`${JSON.stringify(key)}:`),
25
+ entry.expression,
26
+ ];
27
+ if (index !== regular.length - 1 || dynamic.length !== 0)
28
+ base.push(ts.factory.createStringLiteral(`,`));
29
+
30
+ const empty: boolean =
31
+ (entry.meta.required === false &&
32
+ entry.meta.nullable === false &&
33
+ entry.meta.size() === 0) ||
34
+ (entry.meta.functional &&
35
+ entry.meta.nullable === false &&
36
+ entry.meta.size() === 1);
37
+
38
+ if (empty === true) return;
39
+ else if (
40
+ entry.meta.required === false ||
41
+ entry.meta.functional === true ||
42
+ entry.meta.any === true
43
+ )
44
+ output.push(
45
+ ts.factory.createConditionalExpression(
46
+ (() => {
47
+ const conditions: ts.BinaryExpression[] = [];
48
+ if (entry.meta.required === false || entry.meta.any)
49
+ conditions.push(
50
+ ts.factory.createStrictEquality(
51
+ ts.factory.createIdentifier("undefined"),
52
+ entry.input,
53
+ ),
54
+ );
55
+ if (entry.meta.functional || entry.meta.any)
56
+ conditions.push(
57
+ ts.factory.createStrictEquality(
58
+ ts.factory.createStringLiteral("function"),
59
+ ValueFactory.TYPEOF(entry.input),
60
+ ),
61
+ );
62
+ return conditions.length === 1
63
+ ? conditions[0]!
64
+ : conditions.reduce((x, y) =>
65
+ ts.factory.createLogicalOr(x, y),
66
+ );
67
+ })(),
68
+ undefined,
69
+ ts.factory.createStringLiteral(""),
70
+ undefined,
71
+ TemplateFactory.generate(base),
72
+ ),
73
+ );
74
+ else output.push(...base);
75
+ });
76
+ return output;
77
+ }
78
+
79
+ /**
80
+ * @internal
81
+ */
82
+ function sequence(meta: Metadata): number {
83
+ return meta.any || !meta.required || meta.functional ? 0 : 1;
84
+ }
@@ -1,174 +1,174 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { IProject } from "./IProject";
5
- import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
6
- import { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
7
- import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
8
- import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
9
- import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
10
- import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
11
- import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
12
- import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
13
- import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
14
- import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
15
- import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
16
- import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
17
- import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
18
- import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
19
- import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
20
- import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
21
- import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
22
- import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
23
- import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
24
- import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
25
- import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
26
- import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
27
- import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
28
- import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
29
- import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
30
- import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
31
- import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
32
- import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
33
- import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
34
- import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
35
- import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
36
- import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
37
- import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
38
- import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
39
- import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
40
- import { AssertTransformer } from "./features/validators/AssertTransformer";
41
- import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
42
- import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
43
- import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
44
- import { IsTransformer } from "./features/validators/IsTransformer";
45
- import { ValidateTransformer } from "./features/validators/ValidateTransformer";
46
-
47
- export namespace CallExpressionTransformer {
48
- export function transform(
49
- project: IProject,
50
- expression: ts.CallExpression,
51
- ): ts.Expression {
52
- //----
53
- // VALIDATIONS
54
- //----
55
- // SIGNATURE DECLARATION
56
- const declaration: ts.Declaration | undefined =
57
- project.checker.getResolvedSignature(expression)?.declaration;
58
- if (!declaration) return expression;
59
-
60
- // FILE PATH
61
- const file: string = path.resolve(declaration.getSourceFile().fileName);
62
- if (
63
- file.indexOf(LIB_PATH) === -1 &&
64
- file !== SRC_PATH &&
65
- file !== CLI_PATH
66
- )
67
- return expression;
68
-
69
- //----
70
- // TRANSFORMATION
71
- //----
72
- // FUNCTION NAME
73
- const { name } = project.checker.getTypeAtLocation(declaration).symbol;
74
-
75
- // FIND TRANSFORMER
76
- const functor: (() => Task) | undefined = FUNCTORS[name];
77
- if (functor === undefined) return expression;
78
-
79
- // RETURNS WITH TRANSFORMATION
80
- return functor()(project, expression.expression, expression);
81
- }
82
- }
83
-
84
- type Task = (
85
- project: IProject,
86
- modulo: ts.LeftHandSideExpression,
87
- expression: ts.CallExpression,
88
- ) => ts.Expression;
89
-
90
- const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
91
- const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
92
- const CLI_PATH = path.resolve(
93
- path.join(__dirname, "..", "..", "..", "src", "module.ts"),
94
- );
95
-
96
- const FUNCTORS: Record<string, () => Task> = {
97
- //----
98
- // SINGLE FUNCTIONS
99
- //----
100
- // BASIC VALIDATORS
101
- assert: () => AssertTransformer.transform(false),
102
- assertType: () => AssertTransformer.transform(false),
103
- is: () => IsTransformer.transform(false),
104
- validate: () => ValidateTransformer.transform(false),
105
-
106
- // STRICT VALIDATORS
107
- assertEquals: () => AssertTransformer.transform(true),
108
- equals: () => IsTransformer.transform(true),
109
- validateEquals: () => ValidateTransformer.transform(true),
110
-
111
- // PARSE FUNCTIONS
112
- isParse: () => IsParseTransformer.transform,
113
- assertParse: () => AssertParseTransformer.transform,
114
- validateParse: () => ValidateParseTransformer.transform,
115
-
116
- // STRINGIFY FUNCTIONS
117
- application: () => ApplicationTransformer.transform,
118
- stringify: () => StringifyTransformer.transform,
119
- assertStringify: () => AssertStringifyTransformer.transform,
120
- isStringify: () => IsStringifyTransformer.transform,
121
- validateStringify: () => ValidateStringifyTransformer.transform,
122
-
123
- // MISC
124
- metadata: () => MetadataTransformer.transform,
125
- random: () => RandomTransformer.transform,
126
- literals: () => LiteralsTransformer.transform,
127
-
128
- clone: () => CloneTransformer.transform,
129
- assertClone: () => AssertCloneTransformer.transform,
130
- isClone: () => IsCloneTransformer.transform,
131
- validateClone: () => ValidateCloneTransformer.transform,
132
-
133
- prune: () => PruneTransformer.transform,
134
- assertPrune: () => AssertPruneTransformer.transform,
135
- isPrune: () => IsPruneTransformer.transform,
136
- validatePrune: () => ValidatePruneTransformer.transform,
137
-
138
- //----
139
- // FACTORY FUNCTIONS
140
- //----
141
- // BASIC VALIDATORS
142
- createAssert: () => CreateAssertTransformer.transform(false),
143
- createAssertType: () => CreateAssertTransformer.transform(false),
144
- createIs: () => CreateIsTransformer.transform(false),
145
- createValidate: () => CreateValidateTransformer.transform(false),
146
-
147
- // STRICT VALIDATORS
148
- createAssertEquals: () => CreateAssertTransformer.transform(true),
149
- createEquals: () => CreateIsTransformer.transform(true),
150
- createValidateEquals: () => CreateValidateTransformer.transform(true),
151
-
152
- // PARSE FUNCTIONS
153
- createIsParse: () => CreateIsParseTransformer.transform,
154
- createAssertParse: () => CreateAssertParseTransformer.transform,
155
- createValidateParse: () => CreateValidateParseTransformer.transform,
156
-
157
- // STRINGIFY FUNCTIONS
158
- createStringify: () => CreateStringifyTransformer.transform,
159
- createAssertStringify: () => CreateAssertStringifyTransformer.transform,
160
- createIsStringify: () => CreateIsStringifyTransformer.transform,
161
- createValidateStringify: () => CreateValidateStringifyTransformer.transform,
162
-
163
- // MISC
164
- createRandom: () => CreateRandomTransformer.transform,
165
- createClone: () => CreateCloneTransformer.transform,
166
- createAssertClone: () => CreateAssertCloneTransformer.transform,
167
- createIsClone: () => CreateIsCloneTransformer.transform,
168
- createValidateClone: () => CreateValidateCloneTransformer.transform,
169
-
170
- createPrune: () => CreatePruneTransformer.transform,
171
- createAssertPrune: () => CreateAssertPruneTransformer.transform,
172
- createIsPrune: () => CreateIsPruneTransformer.transform,
173
- createValidatePrune: () => CreateValidatePruneTransformer.transform,
174
- };
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { IProject } from "./IProject";
5
+ import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
6
+ import { AssertCloneTransformer } from "./features/miscellaneous/AssertCloneTransformer";
7
+ import { AssertPruneTransformer } from "./features/miscellaneous/AssertPruneTransformer";
8
+ import { CloneTransformer } from "./features/miscellaneous/CloneTransformer";
9
+ import { CreateAssertCloneTransformer } from "./features/miscellaneous/CreateAssertCloneTransformer";
10
+ import { CreateAssertPruneTransformer } from "./features/miscellaneous/CreateAssertPruneTransformer";
11
+ import { CreateCloneTransformer } from "./features/miscellaneous/CreateCloneTransformer";
12
+ import { CreateIsCloneTransformer } from "./features/miscellaneous/CreateIsCloneTransformer";
13
+ import { CreateIsPruneTransformer } from "./features/miscellaneous/CreateIsPruneTransformer";
14
+ import { CreatePruneTransformer } from "./features/miscellaneous/CreatePruneTransformer";
15
+ import { CreateRandomTransformer } from "./features/miscellaneous/CreateRandomTransformer";
16
+ import { CreateValidateCloneTransformer } from "./features/miscellaneous/CreateValidateCloneTransformer";
17
+ import { CreateValidatePruneTransformer } from "./features/miscellaneous/CreateValidatePruneTransformer";
18
+ import { IsCloneTransformer } from "./features/miscellaneous/IsCloneTransformer";
19
+ import { IsPruneTransformer } from "./features/miscellaneous/IsPruneTransformer";
20
+ import { LiteralsTransformer } from "./features/miscellaneous/LiteralsTransformer";
21
+ import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
22
+ import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
23
+ import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
24
+ import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
25
+ import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
26
+ import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
27
+ import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
28
+ import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
29
+ import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
30
+ import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
31
+ import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
32
+ import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
33
+ import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
34
+ import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
35
+ import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
36
+ import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
37
+ import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
38
+ import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
39
+ import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
40
+ import { AssertTransformer } from "./features/validators/AssertTransformer";
41
+ import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
42
+ import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
43
+ import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
44
+ import { IsTransformer } from "./features/validators/IsTransformer";
45
+ import { ValidateTransformer } from "./features/validators/ValidateTransformer";
46
+
47
+ export namespace CallExpressionTransformer {
48
+ export function transform(
49
+ project: IProject,
50
+ expression: ts.CallExpression,
51
+ ): ts.Expression {
52
+ //----
53
+ // VALIDATIONS
54
+ //----
55
+ // SIGNATURE DECLARATION
56
+ const declaration: ts.Declaration | undefined =
57
+ project.checker.getResolvedSignature(expression)?.declaration;
58
+ if (!declaration) return expression;
59
+
60
+ // FILE PATH
61
+ const file: string = path.resolve(declaration.getSourceFile().fileName);
62
+ if (
63
+ file.indexOf(LIB_PATH) === -1 &&
64
+ file !== SRC_PATH &&
65
+ file !== CLI_PATH
66
+ )
67
+ return expression;
68
+
69
+ //----
70
+ // TRANSFORMATION
71
+ //----
72
+ // FUNCTION NAME
73
+ const { name } = project.checker.getTypeAtLocation(declaration).symbol;
74
+
75
+ // FIND TRANSFORMER
76
+ const functor: (() => Task) | undefined = FUNCTORS[name];
77
+ if (functor === undefined) return expression;
78
+
79
+ // RETURNS WITH TRANSFORMATION
80
+ return functor()(project, expression.expression, expression);
81
+ }
82
+ }
83
+
84
+ type Task = (
85
+ project: IProject,
86
+ modulo: ts.LeftHandSideExpression,
87
+ expression: ts.CallExpression,
88
+ ) => ts.Expression;
89
+
90
+ const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
91
+ const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
92
+ const CLI_PATH = path.resolve(
93
+ path.join(__dirname, "..", "..", "..", "src", "module.ts"),
94
+ );
95
+
96
+ const FUNCTORS: Record<string, () => Task> = {
97
+ //----
98
+ // SINGLE FUNCTIONS
99
+ //----
100
+ // BASIC VALIDATORS
101
+ assert: () => AssertTransformer.transform(false),
102
+ assertType: () => AssertTransformer.transform(false),
103
+ is: () => IsTransformer.transform(false),
104
+ validate: () => ValidateTransformer.transform(false),
105
+
106
+ // STRICT VALIDATORS
107
+ assertEquals: () => AssertTransformer.transform(true),
108
+ equals: () => IsTransformer.transform(true),
109
+ validateEquals: () => ValidateTransformer.transform(true),
110
+
111
+ // PARSE FUNCTIONS
112
+ isParse: () => IsParseTransformer.transform,
113
+ assertParse: () => AssertParseTransformer.transform,
114
+ validateParse: () => ValidateParseTransformer.transform,
115
+
116
+ // STRINGIFY FUNCTIONS
117
+ application: () => ApplicationTransformer.transform,
118
+ stringify: () => StringifyTransformer.transform,
119
+ assertStringify: () => AssertStringifyTransformer.transform,
120
+ isStringify: () => IsStringifyTransformer.transform,
121
+ validateStringify: () => ValidateStringifyTransformer.transform,
122
+
123
+ // MISC
124
+ metadata: () => MetadataTransformer.transform,
125
+ random: () => RandomTransformer.transform,
126
+ literals: () => LiteralsTransformer.transform,
127
+
128
+ clone: () => CloneTransformer.transform,
129
+ assertClone: () => AssertCloneTransformer.transform,
130
+ isClone: () => IsCloneTransformer.transform,
131
+ validateClone: () => ValidateCloneTransformer.transform,
132
+
133
+ prune: () => PruneTransformer.transform,
134
+ assertPrune: () => AssertPruneTransformer.transform,
135
+ isPrune: () => IsPruneTransformer.transform,
136
+ validatePrune: () => ValidatePruneTransformer.transform,
137
+
138
+ //----
139
+ // FACTORY FUNCTIONS
140
+ //----
141
+ // BASIC VALIDATORS
142
+ createAssert: () => CreateAssertTransformer.transform(false),
143
+ createAssertType: () => CreateAssertTransformer.transform(false),
144
+ createIs: () => CreateIsTransformer.transform(false),
145
+ createValidate: () => CreateValidateTransformer.transform(false),
146
+
147
+ // STRICT VALIDATORS
148
+ createAssertEquals: () => CreateAssertTransformer.transform(true),
149
+ createEquals: () => CreateIsTransformer.transform(true),
150
+ createValidateEquals: () => CreateValidateTransformer.transform(true),
151
+
152
+ // PARSE FUNCTIONS
153
+ createIsParse: () => CreateIsParseTransformer.transform,
154
+ createAssertParse: () => CreateAssertParseTransformer.transform,
155
+ createValidateParse: () => CreateValidateParseTransformer.transform,
156
+
157
+ // STRINGIFY FUNCTIONS
158
+ createStringify: () => CreateStringifyTransformer.transform,
159
+ createAssertStringify: () => CreateAssertStringifyTransformer.transform,
160
+ createIsStringify: () => CreateIsStringifyTransformer.transform,
161
+ createValidateStringify: () => CreateValidateStringifyTransformer.transform,
162
+
163
+ // MISC
164
+ createRandom: () => CreateRandomTransformer.transform,
165
+ createClone: () => CreateCloneTransformer.transform,
166
+ createAssertClone: () => CreateAssertCloneTransformer.transform,
167
+ createIsClone: () => CreateIsCloneTransformer.transform,
168
+ createValidateClone: () => CreateValidateCloneTransformer.transform,
169
+
170
+ createPrune: () => CreatePruneTransformer.transform,
171
+ createAssertPrune: () => CreateAssertPruneTransformer.transform,
172
+ createIsPrune: () => CreateIsPruneTransformer.transform,
173
+ createValidatePrune: () => CreateValidatePruneTransformer.transform,
174
+ };
@@ -1,66 +1,66 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- export namespace ImportTransformer {
5
- export const transform =
6
- (from: string) =>
7
- (to: string) =>
8
- (context: ts.TransformationContext) =>
9
- (file: ts.SourceFile) =>
10
- transform_file(from)(to)(context)(file);
11
-
12
- const transform_file =
13
- (top: string) =>
14
- (to: string) =>
15
- (context: ts.TransformationContext) =>
16
- (file: ts.SourceFile): ts.SourceFile => {
17
- if (file.isDeclarationFile) return file;
18
-
19
- const from: string = get_directory_path(
20
- path.resolve(file.getSourceFile().fileName),
21
- );
22
- to = from.replace(top, to);
23
-
24
- return ts.visitEachChild(
25
- file,
26
- (node) => transform_node(top)(from)(to)(node),
27
- context,
28
- );
29
- };
30
-
31
- const transform_node =
32
- (top: string) => (from: string) => (to: string) => (node: ts.Node) => {
33
- if (
34
- !ts.isImportDeclaration(node) ||
35
- !ts.isStringLiteral(node.moduleSpecifier)
36
- )
37
- return node;
38
-
39
- const text: string = node.moduleSpecifier.text;
40
- if (text[0] !== ".") return node;
41
-
42
- const location: string = path.resolve(from, text);
43
- if (location.indexOf(top) === 0) return node;
44
-
45
- const replaced: string = (() => {
46
- const simple: string = path
47
- .relative(to, location)
48
- .split(path.sep)
49
- .join("/");
50
- return simple[0] === "." ? simple : `./${simple}`;
51
- })();
52
-
53
- return ts.factory.createImportDeclaration(
54
- undefined,
55
- node.importClause,
56
- ts.factory.createStringLiteral(replaced),
57
- node.assertClause,
58
- );
59
- };
60
- }
61
-
62
- const get_directory_path = (file: string): string => {
63
- const splitted: string[] = path.resolve(file).split(path.sep);
64
- splitted.pop();
65
- return path.resolve(splitted.join(path.sep));
66
- };
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ export namespace ImportTransformer {
5
+ export const transform =
6
+ (from: string) =>
7
+ (to: string) =>
8
+ (context: ts.TransformationContext) =>
9
+ (file: ts.SourceFile) =>
10
+ transform_file(from)(to)(context)(file);
11
+
12
+ const transform_file =
13
+ (top: string) =>
14
+ (to: string) =>
15
+ (context: ts.TransformationContext) =>
16
+ (file: ts.SourceFile): ts.SourceFile => {
17
+ if (file.isDeclarationFile) return file;
18
+
19
+ const from: string = get_directory_path(
20
+ path.resolve(file.getSourceFile().fileName),
21
+ );
22
+ to = from.replace(top, to);
23
+
24
+ return ts.visitEachChild(
25
+ file,
26
+ (node) => transform_node(top)(from)(to)(node),
27
+ context,
28
+ );
29
+ };
30
+
31
+ const transform_node =
32
+ (top: string) => (from: string) => (to: string) => (node: ts.Node) => {
33
+ if (
34
+ !ts.isImportDeclaration(node) ||
35
+ !ts.isStringLiteral(node.moduleSpecifier)
36
+ )
37
+ return node;
38
+
39
+ const text: string = node.moduleSpecifier.text;
40
+ if (text[0] !== ".") return node;
41
+
42
+ const location: string = path.resolve(from, text);
43
+ if (location.indexOf(top) === 0) return node;
44
+
45
+ const replaced: string = (() => {
46
+ const simple: string = path
47
+ .relative(to, location)
48
+ .split(path.sep)
49
+ .join("/");
50
+ return simple[0] === "." ? simple : `./${simple}`;
51
+ })();
52
+
53
+ return ts.factory.createImportDeclaration(
54
+ undefined,
55
+ node.importClause,
56
+ ts.factory.createStringLiteral(replaced),
57
+ node.assertClause,
58
+ );
59
+ };
60
+ }
61
+
62
+ const get_directory_path = (file: string): string => {
63
+ const splitted: string[] = path.resolve(file).split(path.sep);
64
+ splitted.pop();
65
+ return path.resolve(splitted.join(path.sep));
66
+ };