@nestia/core 1.0.18 → 1.0.20-dev.20230413

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 (38) hide show
  1. package/README.md +6 -11
  2. package/lib/decorators/EncryptedModule.d.ts +3 -3
  3. package/lib/decorators/EncryptedModule.js.map +1 -1
  4. package/lib/decorators/EncryptedRoute.js +3 -3
  5. package/lib/decorators/EncryptedRoute.js.map +1 -1
  6. package/lib/decorators/TypedRoute.js +2 -2
  7. package/lib/decorators/TypedRoute.js.map +1 -1
  8. package/lib/decorators/internal/route_error.d.ts +1 -2
  9. package/lib/decorators/internal/route_error.js.map +1 -1
  10. package/package.json +9 -12
  11. package/src/decorators/EncryptedModule.ts +3 -3
  12. package/src/decorators/EncryptedRoute.ts +2 -5
  13. package/src/decorators/TypedRoute.ts +2 -5
  14. package/src/decorators/internal/route_error.ts +2 -5
  15. package/lib/executable/core.d.ts +0 -2
  16. package/lib/executable/core.js +0 -124
  17. package/lib/executable/core.js.map +0 -1
  18. package/lib/executable/internal/ArgumentParser.d.ts +0 -9
  19. package/lib/executable/internal/ArgumentParser.js +0 -256
  20. package/lib/executable/internal/ArgumentParser.js.map +0 -1
  21. package/lib/executable/internal/CommandExecutor.d.ts +0 -3
  22. package/lib/executable/internal/CommandExecutor.js +0 -17
  23. package/lib/executable/internal/CommandExecutor.js.map +0 -1
  24. package/lib/executable/internal/FileRetriever.d.ts +0 -5
  25. package/lib/executable/internal/FileRetriever.js +0 -109
  26. package/lib/executable/internal/FileRetriever.js.map +0 -1
  27. package/lib/executable/internal/PackageManager.d.ts +0 -27
  28. package/lib/executable/internal/PackageManager.js +0 -126
  29. package/lib/executable/internal/PackageManager.js.map +0 -1
  30. package/lib/executable/internal/PluginConfigurator.d.ts +0 -5
  31. package/lib/executable/internal/PluginConfigurator.js +0 -145
  32. package/lib/executable/internal/PluginConfigurator.js.map +0 -1
  33. package/src/executable/core.ts +0 -70
  34. package/src/executable/internal/ArgumentParser.ts +0 -156
  35. package/src/executable/internal/CommandExecutor.ts +0 -8
  36. package/src/executable/internal/FileRetriever.ts +0 -33
  37. package/src/executable/internal/PackageManager.ts +0 -92
  38. package/src/executable/internal/PluginConfigurator.ts +0 -130
@@ -1,145 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.PluginConfigurator = void 0;
43
- var fs_1 = __importDefault(require("fs"));
44
- var path_1 = __importDefault(require("path"));
45
- var FileRetriever_1 = require("./FileRetriever");
46
- var PluginConfigurator;
47
- (function (PluginConfigurator) {
48
- function configure(pack, args) {
49
- return __awaiter(this, void 0, void 0, function () {
50
- var installed, error;
51
- var _this = this;
52
- return __generator(this, function (_a) {
53
- switch (_a.label) {
54
- case 0:
55
- installed = pack.install({
56
- dev: true,
57
- modulo: "comment-json",
58
- version: "4.2.3",
59
- silent: true,
60
- });
61
- return [4 /*yield*/, (function () { return __awaiter(_this, void 0, void 0, function () {
62
- var exp_1;
63
- return __generator(this, function (_a) {
64
- switch (_a.label) {
65
- case 0:
66
- _a.trys.push([0, 2, , 3]);
67
- return [4 /*yield*/, _Configure(pack, args)];
68
- case 1:
69
- _a.sent();
70
- return [2 /*return*/, null];
71
- case 2:
72
- exp_1 = _a.sent();
73
- return [2 /*return*/, exp_1];
74
- case 3: return [2 /*return*/];
75
- }
76
- });
77
- }); })()];
78
- case 1:
79
- error = _a.sent();
80
- // REMOVE IT
81
- if (installed)
82
- pack.erase({
83
- modulo: "comment-json",
84
- silent: true,
85
- });
86
- if (error !== null)
87
- throw error;
88
- return [2 /*return*/];
89
- }
90
- });
91
- });
92
- }
93
- PluginConfigurator.configure = configure;
94
- function _Configure(pack, args) {
95
- return __awaiter(this, void 0, void 0, function () {
96
- var Comment, config, _a, _b, compilerOptions, plugins, strict, core, typia;
97
- return __generator(this, function (_c) {
98
- switch (_c.label) {
99
- case 0: return [4 /*yield*/, FileRetriever_1.FileRetriever.require(path_1.default.join("node_modules", "comment-json"))(pack.directory)];
100
- case 1:
101
- Comment = _c.sent();
102
- _b = (_a = Comment).parse;
103
- return [4 /*yield*/, fs_1.default.promises.readFile(args.project, "utf8")];
104
- case 2:
105
- config = _b.apply(_a, [_c.sent()]);
106
- compilerOptions = config.compilerOptions;
107
- if (compilerOptions === undefined)
108
- throw new Error("".concat(args.project, " file does not have \"compilerOptions\" property."));
109
- plugins = (function () {
110
- var plugins = compilerOptions.plugins;
111
- if (plugins === undefined)
112
- return (compilerOptions.plugins = []);
113
- else if (!Array.isArray(plugins))
114
- throw new Error("\"plugins\" property of ".concat(args.project, " must be array type."));
115
- return plugins;
116
- })();
117
- strict = compilerOptions.strict === true;
118
- core = plugins.find(function (p) {
119
- return typeof p === "object" &&
120
- p !== null &&
121
- p.transform === "@nestia/core/lib/transform";
122
- });
123
- typia = plugins.find(function (p) {
124
- return typeof p === "object" &&
125
- p !== null &&
126
- p.transform === "typia/lib/transform";
127
- });
128
- if (strict && !!core && !!typia)
129
- return [2 /*return*/];
130
- // DO CONFIGURE
131
- compilerOptions.strict = true;
132
- if (core === undefined)
133
- plugins.push(Comment.parse("{\n \"transform\": \"@nestia/core/lib/transform\",\n /**\n * Validate request body.\n * \n * - \"assert\": Use typia.assert() function\n * - \"is\": Use typia.is() function\n * - \"validate\": Use typia.validate() function\n */\n \"validate\": \"assert\",\n\n /**\n * Validate JSON typed response body.\n * \n * - \"assert\": Use typia.assertStringify() function\n * - \"is\": Use typia.isStringify() function\n * - \"validate\": Use typia.validateStringify() function\n * - \"stringify\": Use typia.stringify() function, but dangerous\n * - null: Just use JSON.stringify() function, without boosting\n */\n \"stringify\": \"assert\"\n }"));
134
- if (typia === undefined)
135
- plugins.push(Comment.parse("{ \"transform\": \"typia/lib/transform\" }"));
136
- return [4 /*yield*/, fs_1.default.promises.writeFile(args.project, Comment.stringify(config, null, 2))];
137
- case 3:
138
- _c.sent();
139
- return [2 /*return*/];
140
- }
141
- });
142
- });
143
- }
144
- })(PluginConfigurator = exports.PluginConfigurator || (exports.PluginConfigurator = {}));
145
- //# sourceMappingURL=PluginConfigurator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PluginConfigurator.js","sourceRoot":"","sources":["../../../src/executable/internal/PluginConfigurator.ts"],"names":[],"mappings":"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"}
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
- import { ArgumentParser } from "./internal/ArgumentParser";
3
- import { CommandExecutor } from "./internal/CommandExecutor";
4
- import { PackageManager } from "./internal/PackageManager";
5
- import { PluginConfigurator } from "./internal/PluginConfigurator";
6
-
7
- const USAGE = `Wrong command has been detected. Use like below:
8
-
9
- npx @nestia/core setup \\
10
- --compiler (ttypescript|ts-patch) \\
11
- --manager (npm|pnpm|yarn) \\
12
- --project {tsconfig.json file path}
13
-
14
- - npx @nestia/core setup
15
- - npx @nestia/core setup --compiler ts-patch
16
- - npx @nestia/core setup --manager pnpm
17
- - npx @nestia/core setup --project tsconfig.test.json`;
18
-
19
- function halt(desc: string): never {
20
- console.error(desc);
21
- process.exit(-1);
22
- }
23
-
24
- async function setup(): Promise<void> {
25
- console.log("----------------------------------------");
26
- console.log(" Nestia Setup Wizard");
27
- console.log("----------------------------------------");
28
-
29
- // LOAD PACKAGE.JSON INFO
30
- const pack: PackageManager = await PackageManager.mount();
31
-
32
- // TAKE ARGUMENTS
33
- const args: ArgumentParser.IArguments = await ArgumentParser.parse(pack);
34
-
35
- // INSTALL TYPESCRIPT
36
- pack.install({ dev: true, modulo: "typescript", version: "4.9.5" });
37
- args.project ??= (() => {
38
- CommandExecutor.run("npx tsc --init", false);
39
- return (args.project = "tsconfig.json");
40
- })();
41
- pack.install({ dev: true, modulo: "ts-node" });
42
-
43
- // INSTALL COMPILER
44
- pack.install({ dev: true, modulo: args.compiler });
45
- if (args.compiler === "ts-patch") {
46
- await pack.save((data) => {
47
- data.scripts ??= {};
48
- if (typeof data.scripts.prepare === "string")
49
- data.scripts.prepare =
50
- "ts-patch install && " + data.scripts.prepare;
51
- else data.scripts.prepare = "ts-patch install";
52
- });
53
- CommandExecutor.run("npm run prepare", false);
54
- }
55
-
56
- // INSTALL AND CONFIGURE TYPIA
57
- pack.install({ dev: false, modulo: "typia" });
58
- pack.install({ dev: false, modulo: "@nestia/core" });
59
- await PluginConfigurator.configure(pack, args);
60
- }
61
-
62
- async function main(): Promise<void> {
63
- const type: string | undefined = process.argv[2];
64
- if (type === "setup") await setup();
65
- else halt(USAGE);
66
- }
67
- main().catch((exp) => {
68
- console.error(exp);
69
- process.exit(-1);
70
- });
@@ -1,156 +0,0 @@
1
- import type CommanderModule from "commander";
2
- import fs from "fs";
3
- import type * as InquirerModule from "inquirer";
4
- import path from "path";
5
-
6
- import { FileRetriever } from "./FileRetriever";
7
- import { PackageManager } from "./PackageManager";
8
-
9
- export namespace ArgumentParser {
10
- export interface IArguments {
11
- compiler: "ts-patch" | "ttypescript";
12
- manager: "npm" | "pnpm" | "yarn";
13
- project: string | null;
14
- }
15
-
16
- export async function parse(pack: PackageManager): Promise<IArguments> {
17
- // INSTALL TEMPORARY PACKAGES
18
- const newbie = {
19
- commander: pack.install({
20
- dev: true,
21
- modulo: "commander",
22
- version: "10.0.0",
23
- silent: true,
24
- }),
25
- inquirer: pack.install({
26
- dev: true,
27
- modulo: "inquirer",
28
- version: "8.2.5",
29
- silent: true,
30
- }),
31
- };
32
-
33
- // TAKE OPTIONS
34
- const output: IArguments | Error = await (async () => {
35
- try {
36
- return await _Parse(pack);
37
- } catch (error) {
38
- return error as Error;
39
- }
40
- })();
41
-
42
- // REMOVE TEMPORARY PACKAGES
43
- if (newbie.commander) pack.erase({ modulo: "commander", silent: true });
44
- if (newbie.inquirer) pack.erase({ modulo: "inquirer", silent: true });
45
-
46
- // RETURNS
47
- if (output instanceof Error) throw output;
48
- return output;
49
- }
50
-
51
- async function _Parse(pack: PackageManager): Promise<IArguments> {
52
- // PREPARE ASSETS
53
- const { createPromptModule }: typeof InquirerModule =
54
- await FileRetriever.require(path.join("node_modules", "inquirer"))(
55
- pack.directory,
56
- );
57
- const { program }: typeof CommanderModule = await FileRetriever.require(
58
- path.join("node_modules", "commander"),
59
- )(pack.directory);
60
-
61
- program.option("--compiler [compiler]", "compiler type");
62
- program.option("--manager [manager", "package manager");
63
- program.option("--project [project]", "tsconfig.json file location");
64
-
65
- // INTERNAL PROCEDURES
66
- const questioned = { value: false };
67
- const action = (
68
- closure: (options: Partial<IArguments>) => Promise<IArguments>,
69
- ) => {
70
- return new Promise<IArguments>((resolve, reject) => {
71
- program.action(async (options) => {
72
- try {
73
- resolve(await closure(options));
74
- } catch (exp) {
75
- reject(exp);
76
- }
77
- });
78
- program.parseAsync().catch(reject);
79
- });
80
- };
81
- const select =
82
- (name: string) =>
83
- (message: string) =>
84
- async <Choice extends string>(
85
- choices: Choice[],
86
- ): Promise<Choice> => {
87
- questioned.value = true;
88
- return (
89
- await createPromptModule()({
90
- type: "list",
91
- name: name,
92
- message: message,
93
- choices: choices,
94
- })
95
- )[name];
96
- };
97
- const configure = async () => {
98
- const fileList: string[] = await (
99
- await fs.promises.readdir(process.cwd())
100
- )
101
- .filter(
102
- (str) =>
103
- str.substring(0, 8) === "tsconfig" &&
104
- str.substring(str.length - 5) === ".json",
105
- )
106
- .sort((x, y) =>
107
- x === "tsconfig.json"
108
- ? -1
109
- : y === "tsconfig.json"
110
- ? 1
111
- : x < y
112
- ? -1
113
- : 1,
114
- );
115
- if (fileList.length === 0) {
116
- if (process.cwd() !== pack.directory)
117
- throw new Error(`Unable to find "tsconfig.json" file.`);
118
- return null;
119
- } else if (fileList.length === 1) return fileList[0];
120
- return select("tsconfig")("TS Config File")(fileList);
121
- };
122
-
123
- // DO CONSTRUCT
124
- return action(async (options) => {
125
- if (options.compiler === undefined) {
126
- console.log(COMPILER_DESCRIPTION);
127
- options.compiler = await select("compiler")(`Compiler`)(
128
- pack.data.scripts?.build === "nest build"
129
- ? ["ts-patch" as const, "ttypescript" as const]
130
- : ["ttypescript" as const, "ts-patch" as const],
131
- );
132
- }
133
- options.manager ??= await select("manager")("Package Manager")([
134
- "npm" as const,
135
- "pnpm" as const,
136
- "yarn" as const,
137
- ]);
138
- pack.manager = options.manager;
139
- options.project ??= await configure();
140
-
141
- if (questioned.value) console.log("");
142
- return options as IArguments;
143
- });
144
- }
145
- }
146
-
147
- const COMPILER_DESCRIPTION = [
148
- `About compiler, if you adapt "ttypescript", you should use "ttsc" instead.`,
149
- ``,
150
- `Otherwise, you choose "ts-patch", you can use the original "tsc" command.`,
151
- `However, the "ts-patch" hacks "node_modules/typescript" source code.`,
152
- `Also, whenever update "typescript", you've to run "npm run prepare" command.`,
153
- ``,
154
- `By the way, when using "@nest/cli", you must just choose "ts-patch".`,
155
- ``,
156
- ].join("\n");
@@ -1,8 +0,0 @@
1
- import cp from "child_process";
2
-
3
- export namespace CommandExecutor {
4
- export function run(str: string, silent: boolean): void {
5
- if (silent === false) console.log(str);
6
- cp.execSync(str, { stdio: "ignore" });
7
- }
8
- }
@@ -1,33 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export namespace FileRetriever {
5
- export const directory =
6
- (name: string) =>
7
- (dir: string, depth: number = 0): string | null => {
8
- const location: string = path.join(dir, name);
9
- if (fs.existsSync(location)) return dir;
10
- else if (depth > 2) return null;
11
- return directory(name)(path.join(dir, ".."), depth + 1);
12
- };
13
-
14
- export const file =
15
- (name: string) =>
16
- (directory: string, depth: number = 0): string | null => {
17
- const location: string = path.join(directory, name);
18
- if (fs.existsSync(location)) return location;
19
- else if (depth > 2) return null;
20
- return file(name)(path.join(directory, ".."), depth + 1);
21
- };
22
-
23
- export const require =
24
- (name: string) =>
25
- async (directory: string, depth: number = 0) => {
26
- const location: string | null = file(name)(directory, depth);
27
- if (location === null)
28
- throw new Error(
29
- `Unable to find installed module. Please report to the nestia - https://github.com/samchon/nestia/issues`,
30
- );
31
- return import(location);
32
- };
33
- }
@@ -1,92 +0,0 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { CommandExecutor } from "./CommandExecutor";
5
- import { FileRetriever } from "./FileRetriever";
6
-
7
- export class PackageManager {
8
- public manager: string = "npm";
9
- public get file(): string {
10
- return path.join(this.directory, "package.json");
11
- }
12
-
13
- public static async mount(): Promise<PackageManager> {
14
- const location: string | null = await FileRetriever.directory(
15
- "package.json",
16
- )(process.cwd());
17
- if (location === null)
18
- throw new Error(`Unable to find "package.json" file`);
19
-
20
- return new PackageManager(
21
- location,
22
- await this.load(path.join(location, "package.json")),
23
- );
24
- }
25
-
26
- public async save(modifier: (data: Package.Data) => void): Promise<void> {
27
- const content: string = await fs.promises.readFile(this.file, "utf8");
28
- this.data = JSON.parse(content);
29
- modifier(this.data);
30
-
31
- return fs.promises.writeFile(
32
- this.file,
33
- JSON.stringify(this.data, null, 2),
34
- "utf8",
35
- );
36
- }
37
-
38
- public install(props: {
39
- dev: boolean;
40
- silent?: boolean;
41
- modulo: string;
42
- version?: string;
43
- }): boolean {
44
- const container = props.dev
45
- ? this.data.devDependencies
46
- : this.data.dependencies;
47
- if (
48
- !!container?.[props.modulo] &&
49
- FileRetriever.file(path.join("node_modules", props.modulo))(
50
- this.directory,
51
- ) !== null
52
- )
53
- return false;
54
-
55
- const middle: string =
56
- this.manager === "yarn"
57
- ? `add${props.dev ? " -D" : ""}`
58
- : `install ${props.dev ? "--save-dev" : "--save"}`;
59
- CommandExecutor.run(
60
- `${this.manager} ${middle} ${props.modulo}${
61
- props.version ? `@${props.version}` : ""
62
- }`,
63
- !!props.silent,
64
- );
65
- return true;
66
- }
67
-
68
- public erase(props: { modulo: string; silent?: boolean }): void {
69
- const middle: string = this.manager === "yarn" ? "remove" : "uninstall";
70
- CommandExecutor.run(
71
- `${this.manager} ${middle} ${props.modulo}`,
72
- !!props.silent,
73
- );
74
- }
75
-
76
- private constructor(
77
- public readonly directory: string,
78
- public data: Package.Data,
79
- ) {}
80
-
81
- private static async load(file: string): Promise<Package.Data> {
82
- const content: string = await fs.promises.readFile(file, "utf8");
83
- return JSON.parse(content);
84
- }
85
- }
86
- export namespace Package {
87
- export interface Data {
88
- scripts?: Record<string, string>;
89
- dependencies?: Record<string, string>;
90
- devDependencies?: Record<string, string>;
91
- }
92
- }
@@ -1,130 +0,0 @@
1
- import type Comment from "comment-json";
2
- import fs from "fs";
3
- import path from "path";
4
-
5
- import { ArgumentParser } from "./ArgumentParser";
6
- import { FileRetriever } from "./FileRetriever";
7
- import { PackageManager } from "./PackageManager";
8
-
9
- export namespace PluginConfigurator {
10
- export async function configure(
11
- pack: PackageManager,
12
- args: ArgumentParser.IArguments,
13
- ): Promise<void> {
14
- // INSTALL COMMENT-JSON
15
- const installed: boolean = pack.install({
16
- dev: true,
17
- modulo: "comment-json",
18
- version: "4.2.3",
19
- silent: true,
20
- });
21
-
22
- // DO CONFIGURE
23
- const error: Error | null = await (async () => {
24
- try {
25
- await _Configure(pack, args);
26
- return null;
27
- } catch (exp) {
28
- return exp as Error;
29
- }
30
- })();
31
-
32
- // REMOVE IT
33
- if (installed)
34
- pack.erase({
35
- modulo: "comment-json",
36
- silent: true,
37
- });
38
- if (error !== null) throw error;
39
- }
40
-
41
- async function _Configure(
42
- pack: PackageManager,
43
- args: ArgumentParser.IArguments,
44
- ): Promise<void> {
45
- // GET COMPILER-OPTIONS
46
- const Comment: typeof import("comment-json") =
47
- await FileRetriever.require(
48
- path.join("node_modules", "comment-json"),
49
- )(pack.directory);
50
-
51
- const config: Comment.CommentObject = Comment.parse(
52
- await fs.promises.readFile(args.project!, "utf8"),
53
- ) as Comment.CommentObject;
54
- const compilerOptions = config.compilerOptions as
55
- | Comment.CommentObject
56
- | undefined;
57
- if (compilerOptions === undefined)
58
- throw new Error(
59
- `${args.project} file does not have "compilerOptions" property.`,
60
- );
61
-
62
- // PREPARE PLUGINS
63
- const plugins: Comment.CommentArray<Comment.CommentObject> = (() => {
64
- const plugins = compilerOptions.plugins as
65
- | Comment.CommentArray<Comment.CommentObject>
66
- | undefined;
67
- if (plugins === undefined)
68
- return (compilerOptions.plugins = [] as any);
69
- else if (!Array.isArray(plugins))
70
- throw new Error(
71
- `"plugins" property of ${args.project} must be array type.`,
72
- );
73
- return plugins;
74
- })();
75
-
76
- // CHECK WHETHER CONFIGURED
77
- const strict: boolean = compilerOptions.strict === true;
78
- const core: Comment.CommentObject | undefined = plugins.find(
79
- (p) =>
80
- typeof p === "object" &&
81
- p !== null &&
82
- p.transform === "@nestia/core/lib/transform",
83
- );
84
- const typia: Comment.CommentObject | undefined = plugins.find(
85
- (p) =>
86
- typeof p === "object" &&
87
- p !== null &&
88
- p.transform === "typia/lib/transform",
89
- );
90
- if (strict && !!core && !!typia) return;
91
-
92
- // DO CONFIGURE
93
- compilerOptions.strict = true;
94
- if (core === undefined)
95
- plugins.push(
96
- Comment.parse(`{
97
- "transform": "@nestia/core/lib/transform",
98
- /**
99
- * Validate request body.
100
- *
101
- * - "assert": Use typia.assert() function
102
- * - "is": Use typia.is() function
103
- * - "validate": Use typia.validate() function
104
- */
105
- "validate": "assert",
106
-
107
- /**
108
- * Validate JSON typed response body.
109
- *
110
- * - "assert": Use typia.assertStringify() function
111
- * - "is": Use typia.isStringify() function
112
- * - "validate": Use typia.validateStringify() function
113
- * - "stringify": Use typia.stringify() function, but dangerous
114
- * - null: Just use JSON.stringify() function, without boosting
115
- */
116
- "stringify": "assert"
117
- }`) as Comment.CommentObject,
118
- );
119
- if (typia === undefined)
120
- plugins.push(
121
- Comment.parse(
122
- `{ "transform": "typia/lib/transform" }`,
123
- ) as Comment.CommentObject,
124
- );
125
- await fs.promises.writeFile(
126
- args.project!,
127
- Comment.stringify(config, null, 2),
128
- );
129
- }
130
- }