@nestia/core 1.0.17 → 1.0.19
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/README.md +6 -11
- package/lib/decorators/EncryptedBody.js +1 -1
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js +2 -2
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/TypedBody.js +1 -1
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedRoute.js +2 -2
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/package.json +2 -5
- package/src/decorators/EncryptedBody.ts +1 -1
- package/src/decorators/EncryptedRoute.ts +2 -2
- package/src/decorators/TypedBody.ts +1 -1
- package/src/decorators/TypedRoute.ts +2 -2
- package/lib/executable/core.d.ts +0 -2
- package/lib/executable/core.js +0 -124
- package/lib/executable/core.js.map +0 -1
- package/lib/executable/internal/ArgumentParser.d.ts +0 -9
- package/lib/executable/internal/ArgumentParser.js +0 -256
- package/lib/executable/internal/ArgumentParser.js.map +0 -1
- package/lib/executable/internal/CommandExecutor.d.ts +0 -3
- package/lib/executable/internal/CommandExecutor.js +0 -17
- package/lib/executable/internal/CommandExecutor.js.map +0 -1
- package/lib/executable/internal/FileRetriever.d.ts +0 -5
- package/lib/executable/internal/FileRetriever.js +0 -109
- package/lib/executable/internal/FileRetriever.js.map +0 -1
- package/lib/executable/internal/PackageManager.d.ts +0 -27
- package/lib/executable/internal/PackageManager.js +0 -126
- package/lib/executable/internal/PackageManager.js.map +0 -1
- package/lib/executable/internal/PluginConfigurator.d.ts +0 -5
- package/lib/executable/internal/PluginConfigurator.js +0 -145
- package/lib/executable/internal/PluginConfigurator.js.map +0 -1
- package/src/executable/core.ts +0 -70
- package/src/executable/internal/ArgumentParser.ts +0 -156
- package/src/executable/internal/CommandExecutor.ts +0 -8
- package/src/executable/internal/FileRetriever.ts +0 -33
- package/src/executable/internal/PackageManager.ts +0 -92
- package/src/executable/internal/PluginConfigurator.ts +0 -130
|
@@ -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,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
|
-
}
|