typia 5.2.1 → 5.2.2-dev.20231012
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/executable/TypiaSetupWizard.js +8 -8
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/MetadataCollection.js +4 -3
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/package.json +2 -2
- package/src/CamelCase.ts +116 -116
- package/src/PascalCase.ts +116 -116
- package/src/Primitive.ts +135 -135
- package/src/Resolved.ts +116 -116
- package/src/SnakeCase.ts +156 -156
- package/src/executable/TypiaSetupWizard.ts +9 -11
- package/src/factories/MetadataCollection.ts +6 -1
- package/src/factories/internal/metadata/emplace_metadata_object.ts +150 -150
- package/src/functional/$clone.ts +4 -4
- package/src/functional/$convention.ts +40 -40
- package/src/functional/Namespace.ts +164 -164
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +662 -662
- package/src/notations.ts +855 -855
- package/src/programmers/IsProgrammer.ts +252 -252
- package/src/programmers/TypiaProgrammer.ts +169 -169
- package/src/programmers/helpers/NotationJoiner.ts +146 -146
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/json/JsonStringifyProgrammer.ts +964 -964
- package/src/programmers/misc/MiscCloneProgrammer.ts +790 -790
- package/src/programmers/misc/MiscPruneProgrammer.ts +552 -552
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +72 -72
- package/src/programmers/notations/NotationGeneralProgrammer.ts +720 -720
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +79 -79
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +88 -88
- package/src/protobuf.ts +887 -887
- package/src/transformers/CallExpressionTransformer.ts +380 -380
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/features/json/JsonAssertParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonAssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonCreateAssertParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateIsStringifyTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonCreateValidateParseTransformer.ts +12 -12
- package/src/transformers/features/json/JsonCreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/json/JsonIsParseTransformer.ts +9 -9
- package/src/transformers/features/json/JsonIsStringifyTransformer.ts +10 -10
- package/src/transformers/features/json/JsonStringifyTransformer.ts +9 -9
- package/src/transformers/features/json/JsonValidateParseTransformer.ts +10 -10
- package/src/transformers/features/json/JsonValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscAssertPruneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateAssertCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateAssertPruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreatePruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscCreateValidateCloneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscCreateValidatePruneTransformer.ts +12 -12
- package/src/transformers/features/misc/MiscIsCloneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscIsPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscPruneTransformer.ts +9 -9
- package/src/transformers/features/misc/MiscValidateCloneTransformer.ts +10 -10
- package/src/transformers/features/misc/MiscValidatePruneTransformer.ts +10 -10
- package/src/transformers/features/notations/NotationAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateAssertGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationCreateValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/notations/NotationGeneralTransformer.ts +11 -11
- package/src/transformers/features/notations/NotationIsGeneralTransformer.ts +15 -15
- package/src/transformers/features/notations/NotationValidateGeneralTransformer.ts +17 -17
- package/src/transformers/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateDecodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateEncodeTransformer.ts +9 -9
- package/src/transformers/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +12 -12
- package/src/transformers/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +12 -12
- package/src/utils/NamingConvention.ts +91 -91
- package/src/utils/StringUtil.ts +4 -4
|
@@ -1,169 +1,169 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { ImportTransformer } from "../transformers/ImportTransformer";
|
|
6
|
-
|
|
7
|
-
import transform from "../transform";
|
|
8
|
-
|
|
9
|
-
export namespace TypiaProgrammer {
|
|
10
|
-
export interface IProps {
|
|
11
|
-
input: string;
|
|
12
|
-
output: string;
|
|
13
|
-
project: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const build = async (
|
|
17
|
-
props: TypiaProgrammer.IProps,
|
|
18
|
-
): Promise<void> => {
|
|
19
|
-
props.input = path.resolve(props.input);
|
|
20
|
-
props.output = path.resolve(props.output);
|
|
21
|
-
|
|
22
|
-
if ((await is_directory(props.input)) === false)
|
|
23
|
-
throw new URIError(
|
|
24
|
-
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
25
|
-
);
|
|
26
|
-
else if (fs.existsSync(props.output) === false)
|
|
27
|
-
await fs.promises.mkdir(props.output, { recursive: true });
|
|
28
|
-
else if ((await is_directory(props.output)) === false) {
|
|
29
|
-
const parent: string = path.join(props.output, "..");
|
|
30
|
-
if ((await is_directory(parent)) === false)
|
|
31
|
-
throw new URIError(
|
|
32
|
-
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
33
|
-
);
|
|
34
|
-
await fs.promises.mkdir(props.output);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// CREATE PROGRAM
|
|
38
|
-
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
|
|
39
|
-
ts.readConfigFile(props.project, ts.sys.readFile).config,
|
|
40
|
-
{
|
|
41
|
-
fileExists: ts.sys.fileExists,
|
|
42
|
-
readFile: ts.sys.readFile,
|
|
43
|
-
readDirectory: ts.sys.readDirectory,
|
|
44
|
-
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
45
|
-
},
|
|
46
|
-
path.dirname(props.project),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
const program: ts.Program = ts.createProgram(
|
|
50
|
-
await (async () => {
|
|
51
|
-
const container: string[] = [];
|
|
52
|
-
await gather(props)(container)(props.input)(props.output);
|
|
53
|
-
return container;
|
|
54
|
-
})(),
|
|
55
|
-
compilerOptions,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
// DO TRANSFORM
|
|
59
|
-
const diagnostics: ts.Diagnostic[] = [];
|
|
60
|
-
const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
|
|
61
|
-
program
|
|
62
|
-
.getSourceFiles()
|
|
63
|
-
.filter(
|
|
64
|
-
(file) =>
|
|
65
|
-
!file.isDeclarationFile &&
|
|
66
|
-
path.resolve(file.fileName).indexOf(props.input) !== -1,
|
|
67
|
-
),
|
|
68
|
-
[
|
|
69
|
-
ImportTransformer.transform(props.input)(props.output),
|
|
70
|
-
transform(
|
|
71
|
-
program,
|
|
72
|
-
((compilerOptions.plugins as any[]) ?? []).find(
|
|
73
|
-
(p: any) =>
|
|
74
|
-
p.transform === "typia/lib/transform" ||
|
|
75
|
-
p.transform === "../src/transform.ts",
|
|
76
|
-
) ?? {},
|
|
77
|
-
{
|
|
78
|
-
addDiagnostic: (diag) => diagnostics.push(diag),
|
|
79
|
-
},
|
|
80
|
-
),
|
|
81
|
-
],
|
|
82
|
-
program.getCompilerOptions(),
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// TRACE ERRORS
|
|
86
|
-
for (const diag of diagnostics) {
|
|
87
|
-
const file: string = diag.file
|
|
88
|
-
? path.relative(diag.file.fileName, process.cwd())
|
|
89
|
-
: "(unknown file)";
|
|
90
|
-
const category: string =
|
|
91
|
-
diag.category === ts.DiagnosticCategory.Warning
|
|
92
|
-
? "warning"
|
|
93
|
-
: diag.category === ts.DiagnosticCategory.Error
|
|
94
|
-
? "error"
|
|
95
|
-
: diag.category === ts.DiagnosticCategory.Suggestion
|
|
96
|
-
? "suggestion"
|
|
97
|
-
: diag.category === ts.DiagnosticCategory.Message
|
|
98
|
-
? "message"
|
|
99
|
-
: "unkown";
|
|
100
|
-
const [line, pos] = diag.file
|
|
101
|
-
? (() => {
|
|
102
|
-
const lines: string[] = diag
|
|
103
|
-
.file!.text.substring(0, diag.start)
|
|
104
|
-
.split("\n");
|
|
105
|
-
if (lines.length === 0) return [0, 0];
|
|
106
|
-
return [lines.length, lines.at(-1)!.length + 1];
|
|
107
|
-
})()
|
|
108
|
-
: [0, 0];
|
|
109
|
-
console.error(
|
|
110
|
-
`${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
if (diagnostics.length) process.exit(-1);
|
|
114
|
-
|
|
115
|
-
// ARCHIVE TRANSFORMED FILES
|
|
116
|
-
const printer: ts.Printer = ts.createPrinter({
|
|
117
|
-
newLine: ts.NewLineKind.LineFeed,
|
|
118
|
-
});
|
|
119
|
-
for (const file of result.transformed) {
|
|
120
|
-
const to: string = path
|
|
121
|
-
.resolve(file.fileName)
|
|
122
|
-
.replace(props.input, props.output);
|
|
123
|
-
|
|
124
|
-
const content: string = printer.printFile(file);
|
|
125
|
-
await fs.promises.writeFile(to, emend(content), "utf8");
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
const emend = (content: string): string => {
|
|
130
|
-
if (
|
|
131
|
-
content.indexOf("typia.") === -1 ||
|
|
132
|
-
content.indexOf("import typia") !== -1 ||
|
|
133
|
-
content.indexOf("import * as typia") !== -1
|
|
134
|
-
)
|
|
135
|
-
return content;
|
|
136
|
-
return `import typia from "typia";\n\n${content}`;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const is_directory = async (current: string): Promise<boolean> => {
|
|
140
|
-
const stat: fs.Stats = await fs.promises.stat(current);
|
|
141
|
-
return stat.isDirectory();
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
const gather =
|
|
145
|
-
(props: IProps) =>
|
|
146
|
-
(container: string[]) =>
|
|
147
|
-
(from: string) =>
|
|
148
|
-
async (to: string) => {
|
|
149
|
-
if (from === props.output) return;
|
|
150
|
-
else if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
|
|
151
|
-
|
|
152
|
-
for (const file of await fs.promises.readdir(from)) {
|
|
153
|
-
const next: string = path.join(from, file);
|
|
154
|
-
const stat: fs.Stats = await fs.promises.stat(next);
|
|
155
|
-
|
|
156
|
-
if (stat.isDirectory()) {
|
|
157
|
-
await gather(props)(container)(next)(path.join(to, file));
|
|
158
|
-
continue;
|
|
159
|
-
} else if (is_supported_extension(file)) container.push(next);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const is_supported_extension = (filename: string): boolean => {
|
|
164
|
-
return (
|
|
165
|
-
(filename.endsWith(".ts") && !filename.endsWith(".d.ts")) ||
|
|
166
|
-
(filename.endsWith(".tsx") && !filename.endsWith(".d.tsx"))
|
|
167
|
-
);
|
|
168
|
-
};
|
|
169
|
-
}
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { ImportTransformer } from "../transformers/ImportTransformer";
|
|
6
|
+
|
|
7
|
+
import transform from "../transform";
|
|
8
|
+
|
|
9
|
+
export namespace TypiaProgrammer {
|
|
10
|
+
export interface IProps {
|
|
11
|
+
input: string;
|
|
12
|
+
output: string;
|
|
13
|
+
project: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const build = async (
|
|
17
|
+
props: TypiaProgrammer.IProps,
|
|
18
|
+
): Promise<void> => {
|
|
19
|
+
props.input = path.resolve(props.input);
|
|
20
|
+
props.output = path.resolve(props.output);
|
|
21
|
+
|
|
22
|
+
if ((await is_directory(props.input)) === false)
|
|
23
|
+
throw new URIError(
|
|
24
|
+
"Error on TypiaGenerator.generate(): input path is not a directory.",
|
|
25
|
+
);
|
|
26
|
+
else if (fs.existsSync(props.output) === false)
|
|
27
|
+
await fs.promises.mkdir(props.output, { recursive: true });
|
|
28
|
+
else if ((await is_directory(props.output)) === false) {
|
|
29
|
+
const parent: string = path.join(props.output, "..");
|
|
30
|
+
if ((await is_directory(parent)) === false)
|
|
31
|
+
throw new URIError(
|
|
32
|
+
"Error on TypiaGenerator.generate(): output path is not a directory.",
|
|
33
|
+
);
|
|
34
|
+
await fs.promises.mkdir(props.output);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// CREATE PROGRAM
|
|
38
|
+
const { options: compilerOptions } = ts.parseJsonConfigFileContent(
|
|
39
|
+
ts.readConfigFile(props.project, ts.sys.readFile).config,
|
|
40
|
+
{
|
|
41
|
+
fileExists: ts.sys.fileExists,
|
|
42
|
+
readFile: ts.sys.readFile,
|
|
43
|
+
readDirectory: ts.sys.readDirectory,
|
|
44
|
+
useCaseSensitiveFileNames: ts.sys.useCaseSensitiveFileNames,
|
|
45
|
+
},
|
|
46
|
+
path.dirname(props.project),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const program: ts.Program = ts.createProgram(
|
|
50
|
+
await (async () => {
|
|
51
|
+
const container: string[] = [];
|
|
52
|
+
await gather(props)(container)(props.input)(props.output);
|
|
53
|
+
return container;
|
|
54
|
+
})(),
|
|
55
|
+
compilerOptions,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
// DO TRANSFORM
|
|
59
|
+
const diagnostics: ts.Diagnostic[] = [];
|
|
60
|
+
const result: ts.TransformationResult<ts.SourceFile> = ts.transform(
|
|
61
|
+
program
|
|
62
|
+
.getSourceFiles()
|
|
63
|
+
.filter(
|
|
64
|
+
(file) =>
|
|
65
|
+
!file.isDeclarationFile &&
|
|
66
|
+
path.resolve(file.fileName).indexOf(props.input) !== -1,
|
|
67
|
+
),
|
|
68
|
+
[
|
|
69
|
+
ImportTransformer.transform(props.input)(props.output),
|
|
70
|
+
transform(
|
|
71
|
+
program,
|
|
72
|
+
((compilerOptions.plugins as any[]) ?? []).find(
|
|
73
|
+
(p: any) =>
|
|
74
|
+
p.transform === "typia/lib/transform" ||
|
|
75
|
+
p.transform === "../src/transform.ts",
|
|
76
|
+
) ?? {},
|
|
77
|
+
{
|
|
78
|
+
addDiagnostic: (diag) => diagnostics.push(diag),
|
|
79
|
+
},
|
|
80
|
+
),
|
|
81
|
+
],
|
|
82
|
+
program.getCompilerOptions(),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// TRACE ERRORS
|
|
86
|
+
for (const diag of diagnostics) {
|
|
87
|
+
const file: string = diag.file
|
|
88
|
+
? path.relative(diag.file.fileName, process.cwd())
|
|
89
|
+
: "(unknown file)";
|
|
90
|
+
const category: string =
|
|
91
|
+
diag.category === ts.DiagnosticCategory.Warning
|
|
92
|
+
? "warning"
|
|
93
|
+
: diag.category === ts.DiagnosticCategory.Error
|
|
94
|
+
? "error"
|
|
95
|
+
: diag.category === ts.DiagnosticCategory.Suggestion
|
|
96
|
+
? "suggestion"
|
|
97
|
+
: diag.category === ts.DiagnosticCategory.Message
|
|
98
|
+
? "message"
|
|
99
|
+
: "unkown";
|
|
100
|
+
const [line, pos] = diag.file
|
|
101
|
+
? (() => {
|
|
102
|
+
const lines: string[] = diag
|
|
103
|
+
.file!.text.substring(0, diag.start)
|
|
104
|
+
.split("\n");
|
|
105
|
+
if (lines.length === 0) return [0, 0];
|
|
106
|
+
return [lines.length, lines.at(-1)!.length + 1];
|
|
107
|
+
})()
|
|
108
|
+
: [0, 0];
|
|
109
|
+
console.error(
|
|
110
|
+
`${file}:${line}:${pos} - ${category} TS${diag.code}: ${diag.messageText}`,
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
if (diagnostics.length) process.exit(-1);
|
|
114
|
+
|
|
115
|
+
// ARCHIVE TRANSFORMED FILES
|
|
116
|
+
const printer: ts.Printer = ts.createPrinter({
|
|
117
|
+
newLine: ts.NewLineKind.LineFeed,
|
|
118
|
+
});
|
|
119
|
+
for (const file of result.transformed) {
|
|
120
|
+
const to: string = path
|
|
121
|
+
.resolve(file.fileName)
|
|
122
|
+
.replace(props.input, props.output);
|
|
123
|
+
|
|
124
|
+
const content: string = printer.printFile(file);
|
|
125
|
+
await fs.promises.writeFile(to, emend(content), "utf8");
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const emend = (content: string): string => {
|
|
130
|
+
if (
|
|
131
|
+
content.indexOf("typia.") === -1 ||
|
|
132
|
+
content.indexOf("import typia") !== -1 ||
|
|
133
|
+
content.indexOf("import * as typia") !== -1
|
|
134
|
+
)
|
|
135
|
+
return content;
|
|
136
|
+
return `import typia from "typia";\n\n${content}`;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const is_directory = async (current: string): Promise<boolean> => {
|
|
140
|
+
const stat: fs.Stats = await fs.promises.stat(current);
|
|
141
|
+
return stat.isDirectory();
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const gather =
|
|
145
|
+
(props: IProps) =>
|
|
146
|
+
(container: string[]) =>
|
|
147
|
+
(from: string) =>
|
|
148
|
+
async (to: string) => {
|
|
149
|
+
if (from === props.output) return;
|
|
150
|
+
else if (fs.existsSync(to) === false) await fs.promises.mkdir(to);
|
|
151
|
+
|
|
152
|
+
for (const file of await fs.promises.readdir(from)) {
|
|
153
|
+
const next: string = path.join(from, file);
|
|
154
|
+
const stat: fs.Stats = await fs.promises.stat(next);
|
|
155
|
+
|
|
156
|
+
if (stat.isDirectory()) {
|
|
157
|
+
await gather(props)(container)(next)(path.join(to, file));
|
|
158
|
+
continue;
|
|
159
|
+
} else if (is_supported_extension(file)) container.push(next);
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const is_supported_extension = (filename: string): boolean => {
|
|
164
|
+
return (
|
|
165
|
+
(filename.endsWith(".ts") && !filename.endsWith(".d.ts")) ||
|
|
166
|
+
(filename.endsWith(".tsx") && !filename.endsWith(".d.tsx"))
|
|
167
|
+
);
|
|
168
|
+
};
|
|
169
|
+
}
|
|
@@ -1,146 +1,146 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
import { Escaper } from "../../utils/Escaper";
|
|
8
|
-
|
|
9
|
-
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
-
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
-
|
|
12
|
-
export namespace NotationJoiner {
|
|
13
|
-
export const object =
|
|
14
|
-
(rename: (str: string) => string) =>
|
|
15
|
-
(
|
|
16
|
-
input: ts.Expression,
|
|
17
|
-
entries: IExpressionEntry<ts.Expression>[],
|
|
18
|
-
): ts.ConciseBody => {
|
|
19
|
-
if (entries.length === 0) return ts.factory.createIdentifier("{}");
|
|
20
|
-
|
|
21
|
-
const regular = entries.filter((e) => e.key.isSoleLiteral());
|
|
22
|
-
const dynamic = entries.filter((e) => !e.key.isSoleLiteral());
|
|
23
|
-
const literal = ts.factory.createObjectLiteralExpression(
|
|
24
|
-
regular.map((entry) => {
|
|
25
|
-
const str: string = rename(entry.key.getSoleLiteral()!);
|
|
26
|
-
return ts.factory.createPropertyAssignment(
|
|
27
|
-
Escaper.variable(str)
|
|
28
|
-
? str
|
|
29
|
-
: ts.factory.createStringLiteral(str),
|
|
30
|
-
entry.expression,
|
|
31
|
-
);
|
|
32
|
-
}),
|
|
33
|
-
true,
|
|
34
|
-
);
|
|
35
|
-
if (dynamic.length === 0) return literal;
|
|
36
|
-
|
|
37
|
-
const key = ts.factory.createIdentifier("key");
|
|
38
|
-
const output = ts.factory.createIdentifier("output");
|
|
39
|
-
|
|
40
|
-
const statements: ts.Statement[] = [];
|
|
41
|
-
if (regular.length !== 0)
|
|
42
|
-
statements.push(
|
|
43
|
-
ts.factory.createIfStatement(
|
|
44
|
-
ts.factory.createCallExpression(
|
|
45
|
-
IdentifierFactory.access(
|
|
46
|
-
ts.factory.createArrayLiteralExpression(
|
|
47
|
-
regular.map((r) =>
|
|
48
|
-
ts.factory.createStringLiteral(
|
|
49
|
-
r.key.getSoleLiteral()!,
|
|
50
|
-
),
|
|
51
|
-
),
|
|
52
|
-
),
|
|
53
|
-
)("some"),
|
|
54
|
-
undefined,
|
|
55
|
-
[
|
|
56
|
-
ts.factory.createArrowFunction(
|
|
57
|
-
undefined,
|
|
58
|
-
undefined,
|
|
59
|
-
[IdentifierFactory.parameter("regular")],
|
|
60
|
-
undefined,
|
|
61
|
-
undefined,
|
|
62
|
-
ts.factory.createStrictEquality(
|
|
63
|
-
ts.factory.createIdentifier("regular"),
|
|
64
|
-
ts.factory.createIdentifier("key"),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
],
|
|
68
|
-
),
|
|
69
|
-
ts.factory.createContinueStatement(),
|
|
70
|
-
),
|
|
71
|
-
);
|
|
72
|
-
statements.push(
|
|
73
|
-
...dynamic.map((entry) =>
|
|
74
|
-
ts.factory.createIfStatement(
|
|
75
|
-
ts.factory.createCallExpression(
|
|
76
|
-
ts.factory.createIdentifier(
|
|
77
|
-
`RegExp(/${metadata_to_pattern(true)(
|
|
78
|
-
entry.key,
|
|
79
|
-
)}/).test`,
|
|
80
|
-
),
|
|
81
|
-
undefined,
|
|
82
|
-
[key],
|
|
83
|
-
),
|
|
84
|
-
ts.factory.createBlock([
|
|
85
|
-
ts.factory.createExpressionStatement(
|
|
86
|
-
ts.factory.createBinaryExpression(
|
|
87
|
-
ts.factory.createElementAccessExpression(
|
|
88
|
-
output,
|
|
89
|
-
key,
|
|
90
|
-
),
|
|
91
|
-
ts.factory.createToken(
|
|
92
|
-
ts.SyntaxKind.EqualsToken,
|
|
93
|
-
),
|
|
94
|
-
entry.expression,
|
|
95
|
-
),
|
|
96
|
-
),
|
|
97
|
-
ts.factory.createContinueStatement(),
|
|
98
|
-
]),
|
|
99
|
-
),
|
|
100
|
-
),
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
return ts.factory.createBlock([
|
|
104
|
-
StatementFactory.constant(
|
|
105
|
-
"output",
|
|
106
|
-
ts.factory.createAsExpression(
|
|
107
|
-
literal,
|
|
108
|
-
TypeFactory.keyword("any"),
|
|
109
|
-
),
|
|
110
|
-
),
|
|
111
|
-
ts.factory.createForOfStatement(
|
|
112
|
-
undefined,
|
|
113
|
-
StatementFactory.entry("key")("value"),
|
|
114
|
-
ts.factory.createCallExpression(
|
|
115
|
-
ts.factory.createIdentifier("Object.entries"),
|
|
116
|
-
undefined,
|
|
117
|
-
[input],
|
|
118
|
-
),
|
|
119
|
-
ts.factory.createBlock(statements),
|
|
120
|
-
),
|
|
121
|
-
ts.factory.createReturnStatement(output),
|
|
122
|
-
]);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const tuple = (
|
|
126
|
-
children: ts.Expression[],
|
|
127
|
-
rest: ts.Expression | null,
|
|
128
|
-
): ts.Expression => {
|
|
129
|
-
return ts.factory.createAsExpression(
|
|
130
|
-
ts.factory.createArrayLiteralExpression(
|
|
131
|
-
rest === null
|
|
132
|
-
? children
|
|
133
|
-
: [...children, ts.factory.createSpreadElement(rest)],
|
|
134
|
-
true,
|
|
135
|
-
),
|
|
136
|
-
TypeFactory.keyword("any"),
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
export const array = (input: ts.Expression, arrow: ts.Expression) =>
|
|
141
|
-
ts.factory.createCallExpression(
|
|
142
|
-
ts.factory.createPropertyAccessExpression(input, "map"),
|
|
143
|
-
undefined,
|
|
144
|
-
[arrow],
|
|
145
|
-
);
|
|
146
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { Escaper } from "../../utils/Escaper";
|
|
8
|
+
|
|
9
|
+
import { metadata_to_pattern } from "../internal/metadata_to_pattern";
|
|
10
|
+
import { IExpressionEntry } from "./IExpressionEntry";
|
|
11
|
+
|
|
12
|
+
export namespace NotationJoiner {
|
|
13
|
+
export const object =
|
|
14
|
+
(rename: (str: string) => string) =>
|
|
15
|
+
(
|
|
16
|
+
input: ts.Expression,
|
|
17
|
+
entries: IExpressionEntry<ts.Expression>[],
|
|
18
|
+
): ts.ConciseBody => {
|
|
19
|
+
if (entries.length === 0) return ts.factory.createIdentifier("{}");
|
|
20
|
+
|
|
21
|
+
const regular = entries.filter((e) => e.key.isSoleLiteral());
|
|
22
|
+
const dynamic = entries.filter((e) => !e.key.isSoleLiteral());
|
|
23
|
+
const literal = ts.factory.createObjectLiteralExpression(
|
|
24
|
+
regular.map((entry) => {
|
|
25
|
+
const str: string = rename(entry.key.getSoleLiteral()!);
|
|
26
|
+
return ts.factory.createPropertyAssignment(
|
|
27
|
+
Escaper.variable(str)
|
|
28
|
+
? str
|
|
29
|
+
: ts.factory.createStringLiteral(str),
|
|
30
|
+
entry.expression,
|
|
31
|
+
);
|
|
32
|
+
}),
|
|
33
|
+
true,
|
|
34
|
+
);
|
|
35
|
+
if (dynamic.length === 0) return literal;
|
|
36
|
+
|
|
37
|
+
const key = ts.factory.createIdentifier("key");
|
|
38
|
+
const output = ts.factory.createIdentifier("output");
|
|
39
|
+
|
|
40
|
+
const statements: ts.Statement[] = [];
|
|
41
|
+
if (regular.length !== 0)
|
|
42
|
+
statements.push(
|
|
43
|
+
ts.factory.createIfStatement(
|
|
44
|
+
ts.factory.createCallExpression(
|
|
45
|
+
IdentifierFactory.access(
|
|
46
|
+
ts.factory.createArrayLiteralExpression(
|
|
47
|
+
regular.map((r) =>
|
|
48
|
+
ts.factory.createStringLiteral(
|
|
49
|
+
r.key.getSoleLiteral()!,
|
|
50
|
+
),
|
|
51
|
+
),
|
|
52
|
+
),
|
|
53
|
+
)("some"),
|
|
54
|
+
undefined,
|
|
55
|
+
[
|
|
56
|
+
ts.factory.createArrowFunction(
|
|
57
|
+
undefined,
|
|
58
|
+
undefined,
|
|
59
|
+
[IdentifierFactory.parameter("regular")],
|
|
60
|
+
undefined,
|
|
61
|
+
undefined,
|
|
62
|
+
ts.factory.createStrictEquality(
|
|
63
|
+
ts.factory.createIdentifier("regular"),
|
|
64
|
+
ts.factory.createIdentifier("key"),
|
|
65
|
+
),
|
|
66
|
+
),
|
|
67
|
+
],
|
|
68
|
+
),
|
|
69
|
+
ts.factory.createContinueStatement(),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
72
|
+
statements.push(
|
|
73
|
+
...dynamic.map((entry) =>
|
|
74
|
+
ts.factory.createIfStatement(
|
|
75
|
+
ts.factory.createCallExpression(
|
|
76
|
+
ts.factory.createIdentifier(
|
|
77
|
+
`RegExp(/${metadata_to_pattern(true)(
|
|
78
|
+
entry.key,
|
|
79
|
+
)}/).test`,
|
|
80
|
+
),
|
|
81
|
+
undefined,
|
|
82
|
+
[key],
|
|
83
|
+
),
|
|
84
|
+
ts.factory.createBlock([
|
|
85
|
+
ts.factory.createExpressionStatement(
|
|
86
|
+
ts.factory.createBinaryExpression(
|
|
87
|
+
ts.factory.createElementAccessExpression(
|
|
88
|
+
output,
|
|
89
|
+
key,
|
|
90
|
+
),
|
|
91
|
+
ts.factory.createToken(
|
|
92
|
+
ts.SyntaxKind.EqualsToken,
|
|
93
|
+
),
|
|
94
|
+
entry.expression,
|
|
95
|
+
),
|
|
96
|
+
),
|
|
97
|
+
ts.factory.createContinueStatement(),
|
|
98
|
+
]),
|
|
99
|
+
),
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return ts.factory.createBlock([
|
|
104
|
+
StatementFactory.constant(
|
|
105
|
+
"output",
|
|
106
|
+
ts.factory.createAsExpression(
|
|
107
|
+
literal,
|
|
108
|
+
TypeFactory.keyword("any"),
|
|
109
|
+
),
|
|
110
|
+
),
|
|
111
|
+
ts.factory.createForOfStatement(
|
|
112
|
+
undefined,
|
|
113
|
+
StatementFactory.entry("key")("value"),
|
|
114
|
+
ts.factory.createCallExpression(
|
|
115
|
+
ts.factory.createIdentifier("Object.entries"),
|
|
116
|
+
undefined,
|
|
117
|
+
[input],
|
|
118
|
+
),
|
|
119
|
+
ts.factory.createBlock(statements),
|
|
120
|
+
),
|
|
121
|
+
ts.factory.createReturnStatement(output),
|
|
122
|
+
]);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const tuple = (
|
|
126
|
+
children: ts.Expression[],
|
|
127
|
+
rest: ts.Expression | null,
|
|
128
|
+
): ts.Expression => {
|
|
129
|
+
return ts.factory.createAsExpression(
|
|
130
|
+
ts.factory.createArrayLiteralExpression(
|
|
131
|
+
rest === null
|
|
132
|
+
? children
|
|
133
|
+
: [...children, ts.factory.createSpreadElement(rest)],
|
|
134
|
+
true,
|
|
135
|
+
),
|
|
136
|
+
TypeFactory.keyword("any"),
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
export const array = (input: ts.Expression, arrow: ts.Expression) =>
|
|
141
|
+
ts.factory.createCallExpression(
|
|
142
|
+
ts.factory.createPropertyAccessExpression(input, "map"),
|
|
143
|
+
undefined,
|
|
144
|
+
[arrow],
|
|
145
|
+
);
|
|
146
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { ITransformOptions } from "../../transformers/ITransformOptions";
|
|
2
|
-
|
|
3
|
-
export namespace OptionPredicator {
|
|
4
|
-
export const numeric = (options: ITransformOptions): boolean =>
|
|
5
|
-
finite(options) || options.numeric === true;
|
|
6
|
-
|
|
7
|
-
export const functional = (options: ITransformOptions): boolean =>
|
|
8
|
-
options.functional === true;
|
|
9
|
-
|
|
10
|
-
export const finite = (options: ITransformOptions): boolean =>
|
|
11
|
-
options.finite === true;
|
|
12
|
-
|
|
13
|
-
export const undefined = (options: ITransformOptions): boolean =>
|
|
14
|
-
options.undefined !== false;
|
|
15
|
-
}
|
|
1
|
+
import { ITransformOptions } from "../../transformers/ITransformOptions";
|
|
2
|
+
|
|
3
|
+
export namespace OptionPredicator {
|
|
4
|
+
export const numeric = (options: ITransformOptions): boolean =>
|
|
5
|
+
finite(options) || options.numeric === true;
|
|
6
|
+
|
|
7
|
+
export const functional = (options: ITransformOptions): boolean =>
|
|
8
|
+
options.functional === true;
|
|
9
|
+
|
|
10
|
+
export const finite = (options: ITransformOptions): boolean =>
|
|
11
|
+
options.finite === true;
|
|
12
|
+
|
|
13
|
+
export const undefined = (options: ITransformOptions): boolean =>
|
|
14
|
+
options.undefined !== false;
|
|
15
|
+
}
|