typia 3.7.1-dev.20230406 → 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 -2
  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,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,172 +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 { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
21
- import { PruneTransformer } from "./features/miscellaneous/PruneTransformer";
22
- import { RandomTransformer } from "./features/miscellaneous/RandomTransformer";
23
- import { ValidateCloneTransformer } from "./features/miscellaneous/ValidateCloneTransformer";
24
- import { ValidatePruneTransformer } from "./features/miscellaneous/ValidatePruneTransformer";
25
- import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
26
- import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
27
- import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
28
- import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
29
- import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
30
- import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
31
- import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
32
- import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
33
- import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
34
- import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
35
- import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
36
- import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
37
- import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
38
- import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
39
- import { AssertTransformer } from "./features/validators/AssertTransformer";
40
- import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
41
- import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
42
- import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
43
- import { IsTransformer } from "./features/validators/IsTransformer";
44
- import { ValidateTransformer } from "./features/validators/ValidateTransformer";
45
-
46
- export namespace CallExpressionTransformer {
47
- export function transform(
48
- project: IProject,
49
- expression: ts.CallExpression,
50
- ): ts.Expression {
51
- //----
52
- // VALIDATIONS
53
- //----
54
- // SIGNATURE DECLARATION
55
- const declaration: ts.Declaration | undefined =
56
- project.checker.getResolvedSignature(expression)?.declaration;
57
- if (!declaration) return expression;
58
-
59
- // FILE PATH
60
- const file: string = path.resolve(declaration.getSourceFile().fileName);
61
- if (
62
- file.indexOf(LIB_PATH) === -1 &&
63
- file !== SRC_PATH &&
64
- file !== CLI_PATH
65
- )
66
- return expression;
67
-
68
- //----
69
- // TRANSFORMATION
70
- //----
71
- // FUNCTION NAME
72
- const { name } = project.checker.getTypeAtLocation(declaration).symbol;
73
-
74
- // FIND TRANSFORMER
75
- const functor: (() => Task) | undefined = FUNCTORS[name];
76
- if (functor === undefined) return expression;
77
-
78
- // RETURNS WITH TRANSFORMATION
79
- return functor()(project, expression.expression, expression);
80
- }
81
- }
82
-
83
- type Task = (
84
- project: IProject,
85
- modulo: ts.LeftHandSideExpression,
86
- expression: ts.CallExpression,
87
- ) => ts.Expression;
88
-
89
- const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
90
- const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
91
- const CLI_PATH = path.resolve(
92
- path.join(__dirname, "..", "..", "..", "src", "module.ts"),
93
- );
94
-
95
- const FUNCTORS: Record<string, () => Task> = {
96
- //----
97
- // SINGLE FUNCTIONS
98
- //----
99
- // BASIC VALIDATORS
100
- assert: () => AssertTransformer.transform(false),
101
- assertType: () => AssertTransformer.transform(false),
102
- is: () => IsTransformer.transform(false),
103
- validate: () => ValidateTransformer.transform(false),
104
-
105
- // STRICT VALIDATORS
106
- assertEquals: () => AssertTransformer.transform(true),
107
- equals: () => IsTransformer.transform(true),
108
- validateEquals: () => ValidateTransformer.transform(true),
109
-
110
- // PARSE FUNCTIONS
111
- isParse: () => IsParseTransformer.transform,
112
- assertParse: () => AssertParseTransformer.transform,
113
- validateParse: () => ValidateParseTransformer.transform,
114
-
115
- // STRINGIFY FUNCTIONS
116
- application: () => ApplicationTransformer.transform,
117
- stringify: () => StringifyTransformer.transform,
118
- assertStringify: () => AssertStringifyTransformer.transform,
119
- isStringify: () => IsStringifyTransformer.transform,
120
- validateStringify: () => ValidateStringifyTransformer.transform,
121
-
122
- // MISC
123
- metadata: () => MetadataTransformer.transform,
124
- random: () => RandomTransformer.transform,
125
-
126
- clone: () => CloneTransformer.transform,
127
- assertClone: () => AssertCloneTransformer.transform,
128
- isClone: () => IsCloneTransformer.transform,
129
- validateClone: () => ValidateCloneTransformer.transform,
130
-
131
- prune: () => PruneTransformer.transform,
132
- assertPrune: () => AssertPruneTransformer.transform,
133
- isPrune: () => IsPruneTransformer.transform,
134
- validatePrune: () => ValidatePruneTransformer.transform,
135
-
136
- //----
137
- // FACTORY FUNCTIONS
138
- //----
139
- // BASIC VALIDATORS
140
- createAssert: () => CreateAssertTransformer.transform(false),
141
- createAssertType: () => CreateAssertTransformer.transform(false),
142
- createIs: () => CreateIsTransformer.transform(false),
143
- createValidate: () => CreateValidateTransformer.transform(false),
144
-
145
- // STRICT VALIDATORS
146
- createAssertEquals: () => CreateAssertTransformer.transform(true),
147
- createEquals: () => CreateIsTransformer.transform(true),
148
- createValidateEquals: () => CreateValidateTransformer.transform(true),
149
-
150
- // PARSE FUNCTIONS
151
- createIsParse: () => CreateIsParseTransformer.transform,
152
- createAssertParse: () => CreateAssertParseTransformer.transform,
153
- createValidateParse: () => CreateValidateParseTransformer.transform,
154
-
155
- // STRINGIFY FUNCTIONS
156
- createStringify: () => CreateStringifyTransformer.transform,
157
- createAssertStringify: () => CreateAssertStringifyTransformer.transform,
158
- createIsStringify: () => CreateIsStringifyTransformer.transform,
159
- createValidateStringify: () => CreateValidateStringifyTransformer.transform,
160
-
161
- // MISC
162
- createRandom: () => CreateRandomTransformer.transform,
163
- createClone: () => CreateCloneTransformer.transform,
164
- createAssertClone: () => CreateAssertCloneTransformer.transform,
165
- createIsClone: () => CreateIsCloneTransformer.transform,
166
- createValidateClone: () => CreateValidateCloneTransformer.transform,
167
-
168
- createPrune: () => CreatePruneTransformer.transform,
169
- createAssertPrune: () => CreateAssertPruneTransformer.transform,
170
- createIsPrune: () => CreateIsPruneTransformer.transform,
171
- createValidatePrune: () => CreateValidatePruneTransformer.transform,
172
- };
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
+ };
@@ -42,12 +42,18 @@ export namespace ImportTransformer {
42
42
  const location: string = path.resolve(from, text);
43
43
  if (location.indexOf(top) === 0) return node;
44
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
+
45
53
  return ts.factory.createImportDeclaration(
46
54
  undefined,
47
55
  node.importClause,
48
- ts.factory.createStringLiteral(
49
- path.relative(to, location).split(path.sep).join("/"),
50
- ),
56
+ ts.factory.createStringLiteral(replaced),
51
57
  node.assertClause,
52
58
  );
53
59
  };
@@ -18,7 +18,7 @@ export namespace ApplicationTransformer {
18
18
  expression: ts.CallExpression,
19
19
  ): ts.Expression {
20
20
  if (!expression.typeArguments?.length)
21
- throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
21
+ throw new Error(NO_GENERIC_ARGUMENT);
22
22
 
23
23
  //----
24
24
  // GET ARGUMENTS
@@ -34,7 +34,7 @@ export namespace ApplicationTransformer {
34
34
  checker.getTypeFromTypeNode(child as ts.TypeNode),
35
35
  );
36
36
  if (types.some((t) => t.isTypeParameter()))
37
- throw new Error(ErrorMessages.GENERIC_ARGUMENT);
37
+ throw new Error(GENERIC_ARGUMENT);
38
38
 
39
39
  // ADDITIONAL PARAMETERS
40
40
  const purpose: "swagger" | "ajv" = get_parameter(
@@ -68,7 +68,7 @@ export namespace ApplicationTransformer {
68
68
  constant: true,
69
69
  validate: (meta) => {
70
70
  if (meta.atomics.find((str) => str === "bigint"))
71
- throw new Error(ErrorMessages.NO_BIGIT);
71
+ throw new Error(NO_BIGIT);
72
72
  },
73
73
  }),
74
74
  );
@@ -112,9 +112,8 @@ export namespace ApplicationTransformer {
112
112
  }
113
113
  }
114
114
 
115
- const enum ErrorMessages {
116
- NO_GENERIC_ARGUMENT = "Error on typia.application(): no generic argument.",
117
- GENERIC_ARGUMENT = "Error on typia.application(): non-specified generic argument(s).",
118
- NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
119
- NO_ZERO_LENGTH_TUPLE = "Error on typia.application(): swagger does not support zero length tuple type.",
120
- }
115
+ const NO_GENERIC_ARGUMENT =
116
+ "Error on typia.application(): no generic argument.";
117
+ const GENERIC_ARGUMENT =
118
+ "Error on typia.application(): non-specified generic argument(s).";
119
+ const NO_BIGIT = "Error on typia.application(): does not allow bigint type.";