typia 4.1.4 → 4.1.5-dev.20230711

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.
@@ -1,60 +1,62 @@
1
- import ts from "typescript";
2
-
3
- import { MetadataCollection } from "../factories/MetadataCollection";
4
- import { MetadataFactory } from "../factories/MetadataFactory";
5
-
6
- import { Metadata } from "../metadata/Metadata";
7
-
8
- import { IProject } from "../transformers/IProject";
9
-
10
- import { Atomic } from "../typings/Atomic";
11
-
12
- import { ArrayUtil } from "../utils/ArrayUtil";
13
-
14
- export namespace LiteralsProgrammer {
15
- export const write = (project: IProject) => (type: ts.Type) => {
16
- const meta: Metadata = MetadataFactory.analyze(project.checker)({
17
- resolve: true,
18
- constant: true,
19
- absorb: true,
20
- validate: (meta) => {
21
- const length: number =
22
- meta.constants
23
- .map((c) => c.values.length)
24
- .reduce((a, b) => a + b, 0) +
25
- meta.atomics.filter((type) => type === "boolean").length;
26
- if (0 === length) throw new Error(ErrorMessages.NO);
27
- else if (meta.size() !== length)
28
- throw new Error(ErrorMessages.ONLY);
29
- },
30
- })(new MetadataCollection())(type);
31
- const values: Set<Atomic.Type> = new Set([
32
- ...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
33
- ...(meta.atomics.filter((type) => type === "boolean").length
34
- ? [true, false]
35
- : []),
36
- ]);
37
- return ts.factory.createAsExpression(
38
- ts.factory.createArrayLiteralExpression(
39
- [...values].map((v) =>
40
- typeof v === "boolean"
41
- ? v
42
- ? ts.factory.createTrue()
43
- : ts.factory.createFalse()
44
- : typeof v === "number"
45
- ? ts.factory.createNumericLiteral(v)
46
- : typeof v === "bigint"
47
- ? ts.factory.createBigIntLiteral(v.toString())
48
- : ts.factory.createStringLiteral(v),
49
- ),
50
- true,
51
- ),
52
- ts.factory.createTypeReferenceNode("const"),
53
- );
54
- };
55
- }
56
-
57
- enum ErrorMessages {
58
- NO = "Error on typia.literals(): no literal type found.",
59
- ONLY = "Error on typia.literals(): only literal type allowed.",
60
- }
1
+ import ts from "typescript";
2
+
3
+ import { MetadataCollection } from "../factories/MetadataCollection";
4
+ import { MetadataFactory } from "../factories/MetadataFactory";
5
+
6
+ import { Metadata } from "../metadata/Metadata";
7
+
8
+ import { IProject } from "../transformers/IProject";
9
+
10
+ import { Atomic } from "../typings/Atomic";
11
+
12
+ import { ArrayUtil } from "../utils/ArrayUtil";
13
+
14
+ export namespace LiteralsProgrammer {
15
+ export const write = (project: IProject) => (type: ts.Type) => {
16
+ const meta: Metadata = MetadataFactory.analyze(project.checker)({
17
+ resolve: true,
18
+ constant: true,
19
+ absorb: true,
20
+ validate: (meta) => {
21
+ const length: number =
22
+ meta.constants
23
+ .map((c) => c.values.length)
24
+ .reduce((a, b) => a + b, 0) +
25
+ meta.atomics.filter((type) => type === "boolean").length;
26
+ if (0 === length) throw new Error(ErrorMessages.NO);
27
+ else if (meta.size() !== length)
28
+ throw new Error(ErrorMessages.ONLY);
29
+ },
30
+ })(new MetadataCollection())(type);
31
+ const values: Set<Atomic.Type | null> = new Set([
32
+ ...ArrayUtil.flat<Atomic.Type>(meta.constants.map((c) => c.values)),
33
+ ...(meta.atomics.filter((type) => type === "boolean").length
34
+ ? [true, false]
35
+ : []),
36
+ ...meta.nullable ? [null] : []
37
+ ]);
38
+ return ts.factory.createAsExpression(
39
+ ts.factory.createArrayLiteralExpression(
40
+ [...values].map((v) =>
41
+ v === null ? ts.factory.createNull()
42
+ : typeof v === "boolean"
43
+ ? v
44
+ ? ts.factory.createTrue()
45
+ : ts.factory.createFalse()
46
+ : typeof v === "number"
47
+ ? ts.factory.createNumericLiteral(v)
48
+ : typeof v === "bigint"
49
+ ? ts.factory.createBigIntLiteral(v.toString())
50
+ : ts.factory.createStringLiteral(v),
51
+ ),
52
+ true,
53
+ ),
54
+ ts.factory.createTypeReferenceNode("const"),
55
+ );
56
+ };
57
+ }
58
+
59
+ enum ErrorMessages {
60
+ NO = "Error on typia.literals(): no literal type found.",
61
+ ONLY = "Error on typia.literals(): only literal type allowed.",
62
+ }
@@ -1,74 +1,74 @@
1
- import { IJsonSchema } from "../../module";
2
- import { application_default } from "./application_default";
3
-
4
- /**
5
- * @internal
6
- */
7
- export const application_number = (
8
- attribute: IJsonSchema.IAttribute,
9
- ): IJsonSchema.INumber | IJsonSchema.IInteger => {
10
- const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
11
- ...attribute,
12
- type: "number" as "number" | "integer",
13
- };
14
- for (const tag of attribute["x-typia-metaTags"] ?? []) {
15
- // CHECK TYPE
16
- if (
17
- tag.kind === "type" &&
18
- (tag.value === "int" ||
19
- tag.value === "uint" ||
20
- tag.value === "{int}" ||
21
- tag.value === "{uint}")
22
- )
23
- output.type = "integer";
24
- // RANGE TAG
25
- else if (tag.kind === "minimum") output.minimum = tag.value;
26
- else if (tag.kind === "maximum") output.maximum = tag.value;
27
- else if (tag.kind === "exclusiveMinimum") {
28
- output.minimum = tag.value;
29
- output.exclusiveMinimum = true;
30
- } else if (tag.kind === "exclusiveMaximum") {
31
- output.maximum = tag.value;
32
- output.exclusiveMaximum = true;
33
- }
34
- // MULTIPLE-OF
35
- else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
36
- }
37
-
38
- // WHEN UNSIGNED INT
39
- if (
40
- output.type === "integer" &&
41
- (attribute["x-typia-metaTags"] ?? []).find(
42
- (tag) => tag.kind === "type" && tag.value === "uint",
43
- )
44
- )
45
- if (
46
- output.minimum === undefined ||
47
- (output.exclusiveMaximum !== true && output.minimum < 0)
48
- )
49
- output.minimum = 0;
50
- else if (output.exclusiveMinimum === true && output.minimum < -1) {
51
- output.maximum = 0;
52
- delete output.exclusiveMinimum;
53
- }
54
-
55
- // DEFAULT CONFIGURATION
56
- output.default = application_default(attribute)((str) => {
57
- const value: number = Number(str);
58
- const conditions: boolean[] = [!Number.isNaN(value)];
59
- if (output.minimum !== undefined)
60
- if (output.exclusiveMinimum === true)
61
- conditions.push(value > output.minimum);
62
- else conditions.push(value >= output.minimum);
63
- if (output.maximum !== undefined)
64
- if (output.exclusiveMaximum === true)
65
- conditions.push(value < output.maximum);
66
- else conditions.push(value <= output.maximum);
67
- if (output.multipleOf !== undefined)
68
- conditions.push(value % output.multipleOf === 0);
69
- return conditions.every((cond) => cond);
70
- })((str) => Number(str));
71
-
72
- // RETURNS
73
- return output;
74
- };
1
+ import { IJsonSchema } from "../../module";
2
+ import { application_default } from "./application_default";
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ export const application_number = (
8
+ attribute: IJsonSchema.IAttribute,
9
+ ): IJsonSchema.INumber | IJsonSchema.IInteger => {
10
+ const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
11
+ ...attribute,
12
+ type: "number" as "number" | "integer",
13
+ };
14
+ for (const tag of attribute["x-typia-metaTags"] ?? []) {
15
+ // CHECK TYPE
16
+ if (
17
+ tag.kind === "type" &&
18
+ (tag.value === "int" ||
19
+ tag.value === "uint" ||
20
+ tag.value === "{int}" ||
21
+ tag.value === "{uint}")
22
+ )
23
+ output.type = "integer";
24
+ // RANGE TAG
25
+ else if (tag.kind === "minimum") output.minimum = tag.value;
26
+ else if (tag.kind === "maximum") output.maximum = tag.value;
27
+ else if (tag.kind === "exclusiveMinimum") {
28
+ output.minimum = tag.value;
29
+ output.exclusiveMinimum = true;
30
+ } else if (tag.kind === "exclusiveMaximum") {
31
+ output.maximum = tag.value;
32
+ output.exclusiveMaximum = true;
33
+ }
34
+ // MULTIPLE-OF
35
+ else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
36
+ }
37
+
38
+ // WHEN UNSIGNED INT
39
+ if (
40
+ output.type === "integer" &&
41
+ (attribute["x-typia-metaTags"] ?? []).find(
42
+ (tag) => tag.kind === "type" && tag.value === "uint",
43
+ )
44
+ )
45
+ if (
46
+ output.minimum === undefined ||
47
+ (output.exclusiveMaximum !== true && output.minimum < 0)
48
+ )
49
+ output.minimum = 0;
50
+ else if (output.exclusiveMinimum === true && output.minimum < -1) {
51
+ output.maximum = 0;
52
+ delete output.exclusiveMinimum;
53
+ }
54
+
55
+ // DEFAULT CONFIGURATION
56
+ output.default = application_default(attribute)((str) => {
57
+ const value: number = Number(str);
58
+ const conditions: boolean[] = [!Number.isNaN(value)];
59
+ if (output.minimum !== undefined)
60
+ if (output.exclusiveMinimum === true)
61
+ conditions.push(value > output.minimum);
62
+ else conditions.push(value >= output.minimum);
63
+ if (output.maximum !== undefined)
64
+ if (output.exclusiveMaximum === true)
65
+ conditions.push(value < output.maximum);
66
+ else conditions.push(value <= output.maximum);
67
+ if (output.multipleOf !== undefined)
68
+ conditions.push(value % output.multipleOf === 0);
69
+ return conditions.every((cond) => cond);
70
+ })((str) => Number(str));
71
+
72
+ // RETURNS
73
+ return output;
74
+ };
@@ -1,179 +1,179 @@
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 const transform =
49
- (project: IProject) =>
50
- (expression: ts.CallExpression): 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(
61
- declaration.getSourceFile().fileName,
62
- );
63
- if (
64
- file.indexOf(LIB_PATH) === -1 &&
65
- file !== SRC_PATH &&
66
- file !== CLI_PATH
67
- )
68
- return expression;
69
-
70
- //----
71
- // TRANSFORMATION
72
- //----
73
- // FUNCTION NAME
74
- const { name } =
75
- project.checker.getTypeAtLocation(declaration).symbol;
76
-
77
- // FIND TRANSFORMER
78
- const functor: (() => Task) | undefined = FUNCTORS[name];
79
- if (functor === undefined) return expression;
80
-
81
- // console.log(expression.getSourceFile().fileName);
82
-
83
- // RETURNS WITH TRANSFORMATION
84
- return functor()(project)(expression.expression)(expression);
85
- };
86
- }
87
-
88
- type Task = (
89
- project: IProject,
90
- ) => (
91
- modulo: ts.LeftHandSideExpression,
92
- ) => (expression: ts.CallExpression) => ts.Expression;
93
-
94
- const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
95
- const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
96
- const CLI_PATH = path.resolve(
97
- path.join(__dirname, "..", "..", "..", "src", "module.ts"),
98
- );
99
-
100
- const FUNCTORS: Record<string, () => Task> = {
101
- //----
102
- // SINGLE FUNCTIONS
103
- //----
104
- // BASIC VALIDATORS
105
- assert: () => AssertTransformer.transform(false),
106
- assertType: () => AssertTransformer.transform(false),
107
- is: () => IsTransformer.transform(false),
108
- validate: () => ValidateTransformer.transform(false),
109
-
110
- // STRICT VALIDATORS
111
- assertEquals: () => AssertTransformer.transform(true),
112
- equals: () => IsTransformer.transform(true),
113
- validateEquals: () => ValidateTransformer.transform(true),
114
-
115
- // PARSE FUNCTIONS
116
- isParse: () => IsParseTransformer.transform,
117
- assertParse: () => AssertParseTransformer.transform,
118
- validateParse: () => ValidateParseTransformer.transform,
119
-
120
- // STRINGIFY FUNCTIONS
121
- application: () => (project) => () =>
122
- ApplicationTransformer.transform(project),
123
- stringify: () => StringifyTransformer.transform,
124
- assertStringify: () => AssertStringifyTransformer.transform,
125
- isStringify: () => IsStringifyTransformer.transform,
126
- validateStringify: () => ValidateStringifyTransformer.transform,
127
-
128
- // MISC
129
- metadata: () => (project) => () => MetadataTransformer.transform(project),
130
- random: () => RandomTransformer.transform,
131
- literals: () => (project) => () => LiteralsTransformer.transform(project),
132
-
133
- clone: () => CloneTransformer.transform,
134
- assertClone: () => AssertCloneTransformer.transform,
135
- isClone: () => IsCloneTransformer.transform,
136
- validateClone: () => ValidateCloneTransformer.transform,
137
-
138
- prune: () => PruneTransformer.transform,
139
- assertPrune: () => AssertPruneTransformer.transform,
140
- isPrune: () => IsPruneTransformer.transform,
141
- validatePrune: () => ValidatePruneTransformer.transform,
142
-
143
- //----
144
- // FACTORY FUNCTIONS
145
- //----
146
- // BASIC VALIDATORS
147
- createAssert: () => CreateAssertTransformer.transform(false),
148
- createAssertType: () => CreateAssertTransformer.transform(false),
149
- createIs: () => CreateIsTransformer.transform(false),
150
- createValidate: () => CreateValidateTransformer.transform(false),
151
-
152
- // STRICT VALIDATORS
153
- createAssertEquals: () => CreateAssertTransformer.transform(true),
154
- createEquals: () => CreateIsTransformer.transform(true),
155
- createValidateEquals: () => CreateValidateTransformer.transform(true),
156
-
157
- // PARSE FUNCTIONS
158
- createIsParse: () => CreateIsParseTransformer.transform,
159
- createAssertParse: () => CreateAssertParseTransformer.transform,
160
- createValidateParse: () => CreateValidateParseTransformer.transform,
161
-
162
- // STRINGIFY FUNCTIONS
163
- createStringify: () => CreateStringifyTransformer.transform,
164
- createAssertStringify: () => CreateAssertStringifyTransformer.transform,
165
- createIsStringify: () => CreateIsStringifyTransformer.transform,
166
- createValidateStringify: () => CreateValidateStringifyTransformer.transform,
167
-
168
- // MISC
169
- createRandom: () => CreateRandomTransformer.transform,
170
- createClone: () => CreateCloneTransformer.transform,
171
- createAssertClone: () => CreateAssertCloneTransformer.transform,
172
- createIsClone: () => CreateIsCloneTransformer.transform,
173
- createValidateClone: () => CreateValidateCloneTransformer.transform,
174
-
175
- createPrune: () => CreatePruneTransformer.transform,
176
- createAssertPrune: () => CreateAssertPruneTransformer.transform,
177
- createIsPrune: () => CreateIsPruneTransformer.transform,
178
- createValidatePrune: () => CreateValidatePruneTransformer.transform,
179
- };
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 const transform =
49
+ (project: IProject) =>
50
+ (expression: ts.CallExpression): 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(
61
+ declaration.getSourceFile().fileName,
62
+ );
63
+ if (
64
+ file.indexOf(LIB_PATH) === -1 &&
65
+ file !== SRC_PATH &&
66
+ file !== CLI_PATH
67
+ )
68
+ return expression;
69
+
70
+ //----
71
+ // TRANSFORMATION
72
+ //----
73
+ // FUNCTION NAME
74
+ const { name } =
75
+ project.checker.getTypeAtLocation(declaration).symbol;
76
+
77
+ // FIND TRANSFORMER
78
+ const functor: (() => Task) | undefined = FUNCTORS[name];
79
+ if (functor === undefined) return expression;
80
+
81
+ // console.log(expression.getSourceFile().fileName);
82
+
83
+ // RETURNS WITH TRANSFORMATION
84
+ return functor()(project)(expression.expression)(expression);
85
+ };
86
+ }
87
+
88
+ type Task = (
89
+ project: IProject,
90
+ ) => (
91
+ modulo: ts.LeftHandSideExpression,
92
+ ) => (expression: ts.CallExpression) => ts.Expression;
93
+
94
+ const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
95
+ const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
96
+ const CLI_PATH = path.resolve(
97
+ path.join(__dirname, "..", "..", "..", "src", "module.ts"),
98
+ );
99
+
100
+ const FUNCTORS: Record<string, () => Task> = {
101
+ //----
102
+ // SINGLE FUNCTIONS
103
+ //----
104
+ // BASIC VALIDATORS
105
+ assert: () => AssertTransformer.transform(false),
106
+ assertType: () => AssertTransformer.transform(false),
107
+ is: () => IsTransformer.transform(false),
108
+ validate: () => ValidateTransformer.transform(false),
109
+
110
+ // STRICT VALIDATORS
111
+ assertEquals: () => AssertTransformer.transform(true),
112
+ equals: () => IsTransformer.transform(true),
113
+ validateEquals: () => ValidateTransformer.transform(true),
114
+
115
+ // PARSE FUNCTIONS
116
+ isParse: () => IsParseTransformer.transform,
117
+ assertParse: () => AssertParseTransformer.transform,
118
+ validateParse: () => ValidateParseTransformer.transform,
119
+
120
+ // STRINGIFY FUNCTIONS
121
+ application: () => (project) => () =>
122
+ ApplicationTransformer.transform(project),
123
+ stringify: () => StringifyTransformer.transform,
124
+ assertStringify: () => AssertStringifyTransformer.transform,
125
+ isStringify: () => IsStringifyTransformer.transform,
126
+ validateStringify: () => ValidateStringifyTransformer.transform,
127
+
128
+ // MISC
129
+ metadata: () => (project) => () => MetadataTransformer.transform(project),
130
+ random: () => RandomTransformer.transform,
131
+ literals: () => (project) => () => LiteralsTransformer.transform(project),
132
+
133
+ clone: () => CloneTransformer.transform,
134
+ assertClone: () => AssertCloneTransformer.transform,
135
+ isClone: () => IsCloneTransformer.transform,
136
+ validateClone: () => ValidateCloneTransformer.transform,
137
+
138
+ prune: () => PruneTransformer.transform,
139
+ assertPrune: () => AssertPruneTransformer.transform,
140
+ isPrune: () => IsPruneTransformer.transform,
141
+ validatePrune: () => ValidatePruneTransformer.transform,
142
+
143
+ //----
144
+ // FACTORY FUNCTIONS
145
+ //----
146
+ // BASIC VALIDATORS
147
+ createAssert: () => CreateAssertTransformer.transform(false),
148
+ createAssertType: () => CreateAssertTransformer.transform(false),
149
+ createIs: () => CreateIsTransformer.transform(false),
150
+ createValidate: () => CreateValidateTransformer.transform(false),
151
+
152
+ // STRICT VALIDATORS
153
+ createAssertEquals: () => CreateAssertTransformer.transform(true),
154
+ createEquals: () => CreateIsTransformer.transform(true),
155
+ createValidateEquals: () => CreateValidateTransformer.transform(true),
156
+
157
+ // PARSE FUNCTIONS
158
+ createIsParse: () => CreateIsParseTransformer.transform,
159
+ createAssertParse: () => CreateAssertParseTransformer.transform,
160
+ createValidateParse: () => CreateValidateParseTransformer.transform,
161
+
162
+ // STRINGIFY FUNCTIONS
163
+ createStringify: () => CreateStringifyTransformer.transform,
164
+ createAssertStringify: () => CreateAssertStringifyTransformer.transform,
165
+ createIsStringify: () => CreateIsStringifyTransformer.transform,
166
+ createValidateStringify: () => CreateValidateStringifyTransformer.transform,
167
+
168
+ // MISC
169
+ createRandom: () => CreateRandomTransformer.transform,
170
+ createClone: () => CreateCloneTransformer.transform,
171
+ createAssertClone: () => CreateAssertCloneTransformer.transform,
172
+ createIsClone: () => CreateIsCloneTransformer.transform,
173
+ createValidateClone: () => CreateValidateCloneTransformer.transform,
174
+
175
+ createPrune: () => CreatePruneTransformer.transform,
176
+ createAssertPrune: () => CreateAssertPruneTransformer.transform,
177
+ createIsPrune: () => CreateIsPruneTransformer.transform,
178
+ createValidatePrune: () => CreateValidatePruneTransformer.transform,
179
+ };