typia 4.0.0-dev.20230519-3 → 4.0.0-dev.20230527
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/transform.js +1 -1
- package/lib/transform.js.map +1 -1
- package/lib/utils/TsSymbolUtil.js +2 -1
- package/lib/utils/TsSymbolUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/CustomValidatorMap.ts +126 -126
- package/src/IRandomGenerator.ts +33 -33
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +123 -123
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +133 -133
- package/src/executable/setup/ArgumentParser.ts +45 -45
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +22 -22
- package/src/executable/setup/PackageManager.ts +71 -71
- package/src/executable/setup/PluginConfigurator.ts +70 -70
- package/src/executable/typia.ts +52 -52
- package/src/factories/CommentFactory.ts +14 -14
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +62 -62
- package/src/factories/LiteralFactory.ts +57 -57
- package/src/factories/MetadataCollection.ts +123 -123
- package/src/factories/MetadataFactory.ts +53 -53
- package/src/factories/MetadataTagFactory.ts +295 -295
- package/src/factories/StatementFactory.ts +20 -20
- package/src/factories/TemplateFactory.ts +64 -64
- package/src/factories/TypeFactory.ts +145 -145
- package/src/factories/ValueFactory.ts +15 -15
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +152 -152
- package/src/factories/internal/metadata/explore_metadata.ts +93 -93
- package/src/factories/internal/metadata/iterate_metadata.ts +63 -63
- package/src/factories/internal/metadata/iterate_metadata_array.ts +32 -32
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +62 -62
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +217 -217
- package/src/factories/internal/metadata/iterate_metadata_object.ts +51 -51
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_set.ts +36 -36
- package/src/factories/internal/metadata/iterate_metadata_template.ts +40 -40
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +51 -51
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/functional/$any.ts +2 -2
- package/src/functional/$dictionary.ts +25 -25
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +2 -2
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +3 -3
- package/src/functional/$is_datetime.ts +2 -2
- package/src/functional/$is_email.ts +4 -4
- package/src/functional/$is_ipv4.ts +4 -4
- package/src/functional/$is_ipv6.ts +4 -4
- package/src/functional/$is_url.ts +4 -4
- package/src/functional/$is_uuid.ts +4 -4
- package/src/functional/$join.ts +46 -46
- package/src/functional/$number.ts +12 -12
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +5 -5
- package/src/functional/Namespace.ts +127 -127
- package/src/index.ts +4 -4
- package/src/metadata/ICommentTag.ts +4 -4
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +26 -26
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/IMetadataTag.ts +105 -105
- package/src/metadata/Metadata.ts +539 -539
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +127 -127
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +2038 -2038
- package/src/programmers/ApplicationProgrammer.ts +48 -48
- package/src/programmers/AssertCloneProgrammer.ts +68 -68
- package/src/programmers/AssertParseProgrammer.ts +66 -66
- package/src/programmers/AssertProgrammer.ts +274 -274
- package/src/programmers/AssertPruneProgrammer.ts +73 -73
- package/src/programmers/AssertStringifyProgrammer.ts +66 -66
- package/src/programmers/CheckerProgrammer.ts +897 -897
- package/src/programmers/CloneProgrammer.ts +387 -387
- package/src/programmers/FeatureProgrammer.ts +510 -510
- package/src/programmers/IsCloneProgrammer.ts +79 -79
- package/src/programmers/IsParseProgrammer.ts +72 -72
- package/src/programmers/IsProgrammer.ts +223 -223
- package/src/programmers/IsPruneProgrammer.ts +83 -83
- package/src/programmers/IsStringifyProgrammer.ts +77 -77
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/PruneProgrammer.ts +348 -348
- package/src/programmers/RandomProgrammer.ts +444 -444
- package/src/programmers/StringifyProgrammer.ts +758 -758
- package/src/programmers/TypiaProgrammer.ts +141 -141
- package/src/programmers/ValidateCloneProgrammer.ts +93 -93
- package/src/programmers/ValidateParseProgrammer.ts +78 -78
- package/src/programmers/ValidateProgrammer.ts +317 -317
- package/src/programmers/ValidatePruneProgrammer.ts +86 -86
- package/src/programmers/ValidateStringifyProgrammer.ts +93 -93
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +138 -138
- package/src/programmers/helpers/FunctionImporeter.ts +56 -56
- package/src/programmers/helpers/ICheckEntry.ts +12 -12
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/PruneJoiner.ts +156 -156
- package/src/programmers/helpers/RandomJoiner.ts +165 -165
- package/src/programmers/helpers/RandomRanger.ts +218 -218
- package/src/programmers/helpers/StringifyJoinder.ts +118 -118
- package/src/programmers/helpers/StringifyPredicator.ts +12 -12
- package/src/programmers/helpers/UnionExplorer.ts +281 -281
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +21 -21
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_array.ts +32 -32
- package/src/programmers/internal/application_boolean.ts +15 -15
- package/src/programmers/internal/application_constant.ts +26 -26
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +33 -33
- package/src/programmers/internal/application_native.ts +36 -36
- package/src/programmers/internal/application_number.ts +71 -71
- package/src/programmers/internal/application_object.ts +162 -162
- package/src/programmers/internal/application_schema.ts +198 -198
- package/src/programmers/internal/application_string.ts +44 -44
- package/src/programmers/internal/application_templates.ts +25 -25
- package/src/programmers/internal/application_tuple.ts +27 -27
- package/src/programmers/internal/check_array.ts +31 -31
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_bigint.ts +95 -95
- package/src/programmers/internal/check_custom.ts +32 -32
- package/src/programmers/internal/check_dynamic_properties.ts +198 -198
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +22 -22
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +65 -65
- package/src/programmers/internal/check_string.ts +27 -27
- package/src/programmers/internal/check_string_tags.ts +68 -68
- package/src/programmers/internal/check_template.ts +57 -57
- package/src/programmers/internal/check_union_array_like.ts +273 -273
- package/src/programmers/internal/check_union_tuple.ts +34 -34
- package/src/programmers/internal/decode_union_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +64 -64
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/prune_object_properties.ts +63 -63
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +173 -173
- package/src/programmers/internal/stringify_native.ts +7 -7
- package/src/programmers/internal/stringify_regular_properties.ts +89 -89
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +13 -13
- package/src/schemas/IJsonComponents.ts +33 -33
- package/src/schemas/IJsonSchema.ts +134 -134
- package/src/transform.ts +39 -39
- package/src/transformers/CallExpressionTransformer.ts +183 -183
- package/src/transformers/FileTransformer.ts +50 -50
- package/src/transformers/IProject.ts +18 -18
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ImportTransformer.ts +74 -74
- package/src/transformers/NodeTransformer.ts +13 -13
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +107 -107
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +43 -43
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +31 -31
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +56 -56
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +12 -12
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +12 -12
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +13 -13
- package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/validators/IsTransformer.ts +11 -11
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +101 -101
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +44 -44
- package/src/utils/Escaper.ts +45 -45
- package/src/utils/MapUtil.ts +12 -12
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/RandomGenerator.ts +81 -81
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/TsNodeUtil.ts +17 -17
- package/src/utils/TsSymbolUtil.ts +153 -152
- package/src/utils/TsTypeUtil.ts +38 -38
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
import comments from "comment-json";
|
|
2
|
-
import fs from "fs";
|
|
3
|
-
|
|
4
|
-
import { TypiaSetupWizard } from "../TypiaSetupWizard";
|
|
5
|
-
|
|
6
|
-
export namespace PluginConfigurator {
|
|
7
|
-
export async function configure(
|
|
8
|
-
args: TypiaSetupWizard.IArguments,
|
|
9
|
-
): Promise<void> {
|
|
10
|
-
// GET COMPILER-OPTIONS
|
|
11
|
-
const config: comments.CommentObject = comments.parse(
|
|
12
|
-
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
-
) as comments.CommentObject;
|
|
14
|
-
const compilerOptions = config.compilerOptions as
|
|
15
|
-
| comments.CommentObject
|
|
16
|
-
| undefined;
|
|
17
|
-
if (compilerOptions === undefined)
|
|
18
|
-
throw new Error(
|
|
19
|
-
`${args.project} file does not have "compilerOptions" property.`,
|
|
20
|
-
);
|
|
21
|
-
|
|
22
|
-
// PREPARE PLUGINS
|
|
23
|
-
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
24
|
-
const plugins = compilerOptions.plugins as
|
|
25
|
-
| comments.CommentArray<comments.CommentObject>
|
|
26
|
-
| undefined;
|
|
27
|
-
if (plugins === undefined)
|
|
28
|
-
return (compilerOptions.plugins = [] as any);
|
|
29
|
-
else if (!Array.isArray(plugins))
|
|
30
|
-
throw new Error(
|
|
31
|
-
`"plugins" property of ${args.project} must be array type.`,
|
|
32
|
-
);
|
|
33
|
-
return plugins;
|
|
34
|
-
})();
|
|
35
|
-
|
|
36
|
-
const strict: boolean | undefined = compilerOptions.strict as
|
|
37
|
-
| boolean
|
|
38
|
-
| undefined;
|
|
39
|
-
const strictNullChecks: boolean | undefined =
|
|
40
|
-
compilerOptions.strictNullChecks as boolean | undefined;
|
|
41
|
-
const oldbie: comments.CommentObject | undefined = plugins.find(
|
|
42
|
-
(p) =>
|
|
43
|
-
typeof p === "object" &&
|
|
44
|
-
p !== null &&
|
|
45
|
-
p.transform === "typia/lib/transform",
|
|
46
|
-
);
|
|
47
|
-
if (
|
|
48
|
-
strictNullChecks !== false &&
|
|
49
|
-
(strict === true || strictNullChecks === true) &&
|
|
50
|
-
oldbie !== undefined
|
|
51
|
-
)
|
|
52
|
-
return;
|
|
53
|
-
|
|
54
|
-
// DO CONFIGURE
|
|
55
|
-
compilerOptions.strictNullChecks = true;
|
|
56
|
-
if (strict === undefined && strictNullChecks === undefined)
|
|
57
|
-
compilerOptions.strict = true;
|
|
58
|
-
if (oldbie === undefined)
|
|
59
|
-
plugins.push(
|
|
60
|
-
comments.parse(`
|
|
61
|
-
{
|
|
62
|
-
"transform": "typia/lib/transform"
|
|
63
|
-
}`) as comments.CommentObject,
|
|
64
|
-
);
|
|
65
|
-
await fs.promises.writeFile(
|
|
66
|
-
args.project!,
|
|
67
|
-
comments.stringify(config, null, 2),
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
import comments from "comment-json";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
|
|
4
|
+
import { TypiaSetupWizard } from "../TypiaSetupWizard";
|
|
5
|
+
|
|
6
|
+
export namespace PluginConfigurator {
|
|
7
|
+
export async function configure(
|
|
8
|
+
args: TypiaSetupWizard.IArguments,
|
|
9
|
+
): Promise<void> {
|
|
10
|
+
// GET COMPILER-OPTIONS
|
|
11
|
+
const config: comments.CommentObject = comments.parse(
|
|
12
|
+
await fs.promises.readFile(args.project!, "utf8"),
|
|
13
|
+
) as comments.CommentObject;
|
|
14
|
+
const compilerOptions = config.compilerOptions as
|
|
15
|
+
| comments.CommentObject
|
|
16
|
+
| undefined;
|
|
17
|
+
if (compilerOptions === undefined)
|
|
18
|
+
throw new Error(
|
|
19
|
+
`${args.project} file does not have "compilerOptions" property.`,
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
// PREPARE PLUGINS
|
|
23
|
+
const plugins: comments.CommentArray<comments.CommentObject> = (() => {
|
|
24
|
+
const plugins = compilerOptions.plugins as
|
|
25
|
+
| comments.CommentArray<comments.CommentObject>
|
|
26
|
+
| undefined;
|
|
27
|
+
if (plugins === undefined)
|
|
28
|
+
return (compilerOptions.plugins = [] as any);
|
|
29
|
+
else if (!Array.isArray(plugins))
|
|
30
|
+
throw new Error(
|
|
31
|
+
`"plugins" property of ${args.project} must be array type.`,
|
|
32
|
+
);
|
|
33
|
+
return plugins;
|
|
34
|
+
})();
|
|
35
|
+
|
|
36
|
+
const strict: boolean | undefined = compilerOptions.strict as
|
|
37
|
+
| boolean
|
|
38
|
+
| undefined;
|
|
39
|
+
const strictNullChecks: boolean | undefined =
|
|
40
|
+
compilerOptions.strictNullChecks as boolean | undefined;
|
|
41
|
+
const oldbie: comments.CommentObject | undefined = plugins.find(
|
|
42
|
+
(p) =>
|
|
43
|
+
typeof p === "object" &&
|
|
44
|
+
p !== null &&
|
|
45
|
+
p.transform === "typia/lib/transform",
|
|
46
|
+
);
|
|
47
|
+
if (
|
|
48
|
+
strictNullChecks !== false &&
|
|
49
|
+
(strict === true || strictNullChecks === true) &&
|
|
50
|
+
oldbie !== undefined
|
|
51
|
+
)
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
// DO CONFIGURE
|
|
55
|
+
compilerOptions.strictNullChecks = true;
|
|
56
|
+
if (strict === undefined && strictNullChecks === undefined)
|
|
57
|
+
compilerOptions.strict = true;
|
|
58
|
+
if (oldbie === undefined)
|
|
59
|
+
plugins.push(
|
|
60
|
+
comments.parse(`
|
|
61
|
+
{
|
|
62
|
+
"transform": "typia/lib/transform"
|
|
63
|
+
}`) as comments.CommentObject,
|
|
64
|
+
);
|
|
65
|
+
await fs.promises.writeFile(
|
|
66
|
+
args.project!,
|
|
67
|
+
comments.stringify(config, null, 2),
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
package/src/executable/typia.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
const USAGE = `Wrong command has been detected. Use like below:
|
|
3
|
-
|
|
4
|
-
npx typia setup \\
|
|
5
|
-
--manager (npm|pnpm|yarn) \\
|
|
6
|
-
--project {tsconfig.json file path}
|
|
7
|
-
|
|
8
|
-
- npx typia setup
|
|
9
|
-
- npx typia setup --manager pnpm
|
|
10
|
-
- npx typia setup --project tsconfig.test.json
|
|
11
|
-
|
|
12
|
-
npx typia generate
|
|
13
|
-
--input {directory} \\
|
|
14
|
-
--output {directory}
|
|
15
|
-
|
|
16
|
-
--npx typia generate --input src/templates --output src/functinoal
|
|
17
|
-
`;
|
|
18
|
-
|
|
19
|
-
const halt = (desc: string): never => {
|
|
20
|
-
console.error(desc);
|
|
21
|
-
process.exit(-1);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const main = async (): Promise<void> => {
|
|
25
|
-
try {
|
|
26
|
-
await import("comment-json");
|
|
27
|
-
await import("inquirer");
|
|
28
|
-
await import("commander");
|
|
29
|
-
} catch {
|
|
30
|
-
halt(`typia has not been installed. Run "npm i typia" before.`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const type: string | undefined = process.argv[2];
|
|
34
|
-
if (type === "setup") {
|
|
35
|
-
const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
|
|
36
|
-
await TypiaSetupWizard.setup();
|
|
37
|
-
} else if (type === "generate") {
|
|
38
|
-
try {
|
|
39
|
-
await import("typescript");
|
|
40
|
-
} catch {
|
|
41
|
-
halt(
|
|
42
|
-
`typescript has not been installed. Run "npm i -D typescript" before.`,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
|
|
46
|
-
await TypiaGenerateWizard.generate();
|
|
47
|
-
} else halt(USAGE);
|
|
48
|
-
};
|
|
49
|
-
main().catch((exp) => {
|
|
50
|
-
console.error(exp);
|
|
51
|
-
process.exit(-1);
|
|
52
|
-
});
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const USAGE = `Wrong command has been detected. Use like below:
|
|
3
|
+
|
|
4
|
+
npx typia setup \\
|
|
5
|
+
--manager (npm|pnpm|yarn) \\
|
|
6
|
+
--project {tsconfig.json file path}
|
|
7
|
+
|
|
8
|
+
- npx typia setup
|
|
9
|
+
- npx typia setup --manager pnpm
|
|
10
|
+
- npx typia setup --project tsconfig.test.json
|
|
11
|
+
|
|
12
|
+
npx typia generate
|
|
13
|
+
--input {directory} \\
|
|
14
|
+
--output {directory}
|
|
15
|
+
|
|
16
|
+
--npx typia generate --input src/templates --output src/functinoal
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
const halt = (desc: string): never => {
|
|
20
|
+
console.error(desc);
|
|
21
|
+
process.exit(-1);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const main = async (): Promise<void> => {
|
|
25
|
+
try {
|
|
26
|
+
await import("comment-json");
|
|
27
|
+
await import("inquirer");
|
|
28
|
+
await import("commander");
|
|
29
|
+
} catch {
|
|
30
|
+
halt(`typia has not been installed. Run "npm i typia" before.`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const type: string | undefined = process.argv[2];
|
|
34
|
+
if (type === "setup") {
|
|
35
|
+
const { TypiaSetupWizard } = await import("./TypiaSetupWizard");
|
|
36
|
+
await TypiaSetupWizard.setup();
|
|
37
|
+
} else if (type === "generate") {
|
|
38
|
+
try {
|
|
39
|
+
await import("typescript");
|
|
40
|
+
} catch {
|
|
41
|
+
halt(
|
|
42
|
+
`typescript has not been installed. Run "npm i -D typescript" before.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
const { TypiaGenerateWizard } = await import("./TypiaGenerateWizard");
|
|
46
|
+
await TypiaGenerateWizard.generate();
|
|
47
|
+
} else halt(USAGE);
|
|
48
|
+
};
|
|
49
|
+
main().catch((exp) => {
|
|
50
|
+
console.error(exp);
|
|
51
|
+
process.exit(-1);
|
|
52
|
+
});
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { SymbolDisplayPart } from "typescript";
|
|
2
|
-
|
|
3
|
-
export namespace CommentFactory {
|
|
4
|
-
export const string = (comments: SymbolDisplayPart[]): string =>
|
|
5
|
-
comments
|
|
6
|
-
.map((part) => part.text)
|
|
7
|
-
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
-
.join("");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @deprecated
|
|
12
|
-
*/
|
|
13
|
-
export const generate = string;
|
|
14
|
-
}
|
|
1
|
+
import { SymbolDisplayPart } from "typescript";
|
|
2
|
+
|
|
3
|
+
export namespace CommentFactory {
|
|
4
|
+
export const string = (comments: SymbolDisplayPart[]): string =>
|
|
5
|
+
comments
|
|
6
|
+
.map((part) => part.text)
|
|
7
|
+
.map((str) => str.split("\r\n").join("\n"))
|
|
8
|
+
.join("");
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated
|
|
12
|
+
*/
|
|
13
|
+
export const generate = string;
|
|
14
|
+
}
|
|
@@ -1,77 +1,77 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsclibrary";
|
|
2
|
-
|
|
3
|
-
export namespace ExpressionFactory {
|
|
4
|
-
export const isRequired =
|
|
5
|
-
(tsc: typeof ts) =>
|
|
6
|
-
(input: ts.Expression): ts.Expression =>
|
|
7
|
-
tsc.factory.createStrictInequality(
|
|
8
|
-
tsc.factory.createIdentifier("undefined"),
|
|
9
|
-
input,
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
export const isArray =
|
|
13
|
-
(tsc: typeof ts) =>
|
|
14
|
-
(input: ts.Expression): ts.Expression =>
|
|
15
|
-
tsc.factory.createCallExpression(
|
|
16
|
-
tsc.factory.createIdentifier("Array.isArray"),
|
|
17
|
-
undefined,
|
|
18
|
-
[input],
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
export const isObject =
|
|
22
|
-
(tsc: typeof ts) =>
|
|
23
|
-
(options: { checkNull: boolean; checkArray: boolean }) =>
|
|
24
|
-
(input: ts.Expression): ts.Expression => {
|
|
25
|
-
const conditions: ts.Expression[] = [
|
|
26
|
-
tsc.factory.createStrictEquality(
|
|
27
|
-
tsc.factory.createStringLiteral("object"),
|
|
28
|
-
tsc.factory.createTypeOfExpression(input),
|
|
29
|
-
),
|
|
30
|
-
];
|
|
31
|
-
if (options.checkNull === true)
|
|
32
|
-
conditions.push(
|
|
33
|
-
tsc.factory.createStrictInequality(
|
|
34
|
-
tsc.factory.createNull(),
|
|
35
|
-
input,
|
|
36
|
-
),
|
|
37
|
-
);
|
|
38
|
-
if (options.checkArray === true)
|
|
39
|
-
conditions.push(
|
|
40
|
-
tsc.factory.createStrictEquality(
|
|
41
|
-
tsc.factory.createFalse(),
|
|
42
|
-
tsc.factory.createCallExpression(
|
|
43
|
-
tsc.factory.createIdentifier("Array.isArray"),
|
|
44
|
-
undefined,
|
|
45
|
-
[input],
|
|
46
|
-
),
|
|
47
|
-
),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
return conditions.length === 1
|
|
51
|
-
? conditions[0]!
|
|
52
|
-
: conditions.reduce((x, y) =>
|
|
53
|
-
tsc.factory.createLogicalAnd(x, y),
|
|
54
|
-
);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const isInstanceOf =
|
|
58
|
-
(tsc: typeof ts) =>
|
|
59
|
-
(type: string) =>
|
|
60
|
-
(input: ts.Expression): ts.Expression => {
|
|
61
|
-
return tsc.factory.createBinaryExpression(
|
|
62
|
-
input,
|
|
63
|
-
tsc.factory.createToken(tsc.SyntaxKind.InstanceOfKeyword),
|
|
64
|
-
tsc.factory.createIdentifier(type),
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const coalesce =
|
|
69
|
-
(tsc: typeof ts) =>
|
|
70
|
-
(x: ts.Expression) =>
|
|
71
|
-
(y: ts.Expression): ts.Expression =>
|
|
72
|
-
tsc.factory.createBinaryExpression(
|
|
73
|
-
x,
|
|
74
|
-
tsc.factory.createToken(tsc.SyntaxKind.QuestionQuestionToken),
|
|
75
|
-
y,
|
|
76
|
-
);
|
|
77
|
-
}
|
|
1
|
+
import type ts from "typescript/lib/tsclibrary";
|
|
2
|
+
|
|
3
|
+
export namespace ExpressionFactory {
|
|
4
|
+
export const isRequired =
|
|
5
|
+
(tsc: typeof ts) =>
|
|
6
|
+
(input: ts.Expression): ts.Expression =>
|
|
7
|
+
tsc.factory.createStrictInequality(
|
|
8
|
+
tsc.factory.createIdentifier("undefined"),
|
|
9
|
+
input,
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const isArray =
|
|
13
|
+
(tsc: typeof ts) =>
|
|
14
|
+
(input: ts.Expression): ts.Expression =>
|
|
15
|
+
tsc.factory.createCallExpression(
|
|
16
|
+
tsc.factory.createIdentifier("Array.isArray"),
|
|
17
|
+
undefined,
|
|
18
|
+
[input],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const isObject =
|
|
22
|
+
(tsc: typeof ts) =>
|
|
23
|
+
(options: { checkNull: boolean; checkArray: boolean }) =>
|
|
24
|
+
(input: ts.Expression): ts.Expression => {
|
|
25
|
+
const conditions: ts.Expression[] = [
|
|
26
|
+
tsc.factory.createStrictEquality(
|
|
27
|
+
tsc.factory.createStringLiteral("object"),
|
|
28
|
+
tsc.factory.createTypeOfExpression(input),
|
|
29
|
+
),
|
|
30
|
+
];
|
|
31
|
+
if (options.checkNull === true)
|
|
32
|
+
conditions.push(
|
|
33
|
+
tsc.factory.createStrictInequality(
|
|
34
|
+
tsc.factory.createNull(),
|
|
35
|
+
input,
|
|
36
|
+
),
|
|
37
|
+
);
|
|
38
|
+
if (options.checkArray === true)
|
|
39
|
+
conditions.push(
|
|
40
|
+
tsc.factory.createStrictEquality(
|
|
41
|
+
tsc.factory.createFalse(),
|
|
42
|
+
tsc.factory.createCallExpression(
|
|
43
|
+
tsc.factory.createIdentifier("Array.isArray"),
|
|
44
|
+
undefined,
|
|
45
|
+
[input],
|
|
46
|
+
),
|
|
47
|
+
),
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return conditions.length === 1
|
|
51
|
+
? conditions[0]!
|
|
52
|
+
: conditions.reduce((x, y) =>
|
|
53
|
+
tsc.factory.createLogicalAnd(x, y),
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const isInstanceOf =
|
|
58
|
+
(tsc: typeof ts) =>
|
|
59
|
+
(type: string) =>
|
|
60
|
+
(input: ts.Expression): ts.Expression => {
|
|
61
|
+
return tsc.factory.createBinaryExpression(
|
|
62
|
+
input,
|
|
63
|
+
tsc.factory.createToken(tsc.SyntaxKind.InstanceOfKeyword),
|
|
64
|
+
tsc.factory.createIdentifier(type),
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const coalesce =
|
|
69
|
+
(tsc: typeof ts) =>
|
|
70
|
+
(x: ts.Expression) =>
|
|
71
|
+
(y: ts.Expression): ts.Expression =>
|
|
72
|
+
tsc.factory.createBinaryExpression(
|
|
73
|
+
x,
|
|
74
|
+
tsc.factory.createToken(tsc.SyntaxKind.QuestionQuestionToken),
|
|
75
|
+
y,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsclibrary";
|
|
2
|
-
|
|
3
|
-
import { Escaper } from "../utils/Escaper";
|
|
4
|
-
|
|
5
|
-
export namespace IdentifierFactory {
|
|
6
|
-
export const identifier = (tsc: typeof ts) => (name: string) =>
|
|
7
|
-
Escaper.variable(name)
|
|
8
|
-
? tsc.factory.createIdentifier(name)
|
|
9
|
-
: tsc.factory.createStringLiteral(name);
|
|
10
|
-
|
|
11
|
-
export const access =
|
|
12
|
-
(tsc: typeof ts) => (target: ts.Expression) => (property: string) => {
|
|
13
|
-
const postfix = identifier(tsc)(property);
|
|
14
|
-
return tsc.isStringLiteral(postfix)
|
|
15
|
-
? tsc.factory.createElementAccessExpression(target, postfix)
|
|
16
|
-
: tsc.factory.createPropertyAccessExpression(target, postfix);
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const postfix = (str: string): string =>
|
|
20
|
-
Escaper.variable(str)
|
|
21
|
-
? `".${str}"`
|
|
22
|
-
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
-
|
|
24
|
-
export const parameter =
|
|
25
|
-
(tsc: typeof ts) =>
|
|
26
|
-
(
|
|
27
|
-
name: string | ts.BindingName,
|
|
28
|
-
type?: ts.TypeNode,
|
|
29
|
-
init?:
|
|
30
|
-
| ts.Expression
|
|
31
|
-
| ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
|
|
32
|
-
) => {
|
|
33
|
-
// instead of ts.version >= "4.8"
|
|
34
|
-
if (tsc.getDecorators !== undefined)
|
|
35
|
-
return tsc.factory.createParameterDeclaration(
|
|
36
|
-
undefined,
|
|
37
|
-
undefined,
|
|
38
|
-
name,
|
|
39
|
-
init?.kind === tsc.SyntaxKind.QuestionToken
|
|
40
|
-
? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
|
|
41
|
-
: undefined,
|
|
42
|
-
type,
|
|
43
|
-
init && init.kind !== tsc.SyntaxKind.QuestionToken
|
|
44
|
-
? init
|
|
45
|
-
: undefined,
|
|
46
|
-
);
|
|
47
|
-
// eslint-disable-next-line
|
|
48
|
-
return (tsc.factory.createParameterDeclaration as any)(
|
|
49
|
-
undefined,
|
|
50
|
-
undefined,
|
|
51
|
-
undefined,
|
|
52
|
-
name,
|
|
53
|
-
init?.kind === tsc.SyntaxKind.QuestionToken
|
|
54
|
-
? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
|
|
55
|
-
: undefined,
|
|
56
|
-
type,
|
|
57
|
-
init && init.kind !== tsc.SyntaxKind.QuestionToken
|
|
58
|
-
? init
|
|
59
|
-
: undefined,
|
|
60
|
-
);
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
import type ts from "typescript/lib/tsclibrary";
|
|
2
|
+
|
|
3
|
+
import { Escaper } from "../utils/Escaper";
|
|
4
|
+
|
|
5
|
+
export namespace IdentifierFactory {
|
|
6
|
+
export const identifier = (tsc: typeof ts) => (name: string) =>
|
|
7
|
+
Escaper.variable(name)
|
|
8
|
+
? tsc.factory.createIdentifier(name)
|
|
9
|
+
: tsc.factory.createStringLiteral(name);
|
|
10
|
+
|
|
11
|
+
export const access =
|
|
12
|
+
(tsc: typeof ts) => (target: ts.Expression) => (property: string) => {
|
|
13
|
+
const postfix = identifier(tsc)(property);
|
|
14
|
+
return tsc.isStringLiteral(postfix)
|
|
15
|
+
? tsc.factory.createElementAccessExpression(target, postfix)
|
|
16
|
+
: tsc.factory.createPropertyAccessExpression(target, postfix);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const postfix = (str: string): string =>
|
|
20
|
+
Escaper.variable(str)
|
|
21
|
+
? `".${str}"`
|
|
22
|
+
: `"[${JSON.stringify(str).split('"').join('\\"')}]"`;
|
|
23
|
+
|
|
24
|
+
export const parameter =
|
|
25
|
+
(tsc: typeof ts) =>
|
|
26
|
+
(
|
|
27
|
+
name: string | ts.BindingName,
|
|
28
|
+
type?: ts.TypeNode,
|
|
29
|
+
init?:
|
|
30
|
+
| ts.Expression
|
|
31
|
+
| ts.PunctuationToken<ts.SyntaxKind.QuestionToken>,
|
|
32
|
+
) => {
|
|
33
|
+
// instead of ts.version >= "4.8"
|
|
34
|
+
if (tsc.getDecorators !== undefined)
|
|
35
|
+
return tsc.factory.createParameterDeclaration(
|
|
36
|
+
undefined,
|
|
37
|
+
undefined,
|
|
38
|
+
name,
|
|
39
|
+
init?.kind === tsc.SyntaxKind.QuestionToken
|
|
40
|
+
? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
|
|
41
|
+
: undefined,
|
|
42
|
+
type,
|
|
43
|
+
init && init.kind !== tsc.SyntaxKind.QuestionToken
|
|
44
|
+
? init
|
|
45
|
+
: undefined,
|
|
46
|
+
);
|
|
47
|
+
// eslint-disable-next-line
|
|
48
|
+
return (tsc.factory.createParameterDeclaration as any)(
|
|
49
|
+
undefined,
|
|
50
|
+
undefined,
|
|
51
|
+
undefined,
|
|
52
|
+
name,
|
|
53
|
+
init?.kind === tsc.SyntaxKind.QuestionToken
|
|
54
|
+
? tsc.factory.createToken(tsc.SyntaxKind.QuestionToken)
|
|
55
|
+
: undefined,
|
|
56
|
+
type,
|
|
57
|
+
init && init.kind !== tsc.SyntaxKind.QuestionToken
|
|
58
|
+
? init
|
|
59
|
+
: undefined,
|
|
60
|
+
);
|
|
61
|
+
};
|
|
62
|
+
}
|