@nestia/core 1.0.18 → 1.1.0-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.
- package/README.md +7 -34
- package/lib/decorators/DynamicModule.d.ts +23 -23
- package/lib/decorators/DynamicModule.js +103 -103
- package/lib/decorators/EncryptedBody.d.ts +23 -23
- package/lib/decorators/EncryptedBody.js +125 -125
- package/lib/decorators/EncryptedController.d.ts +31 -31
- package/lib/decorators/EncryptedController.js +41 -41
- package/lib/decorators/EncryptedModule.d.ts +49 -49
- package/lib/decorators/EncryptedModule.js +161 -161
- package/lib/decorators/EncryptedRoute.d.ts +78 -78
- package/lib/decorators/EncryptedRoute.js +216 -216
- package/lib/decorators/PlainBody.d.ts +22 -22
- package/lib/decorators/PlainBody.js +82 -82
- package/lib/decorators/TypedBody.d.ts +16 -16
- package/lib/decorators/TypedBody.js +94 -94
- package/lib/decorators/TypedParam.d.ts +25 -25
- package/lib/decorators/TypedParam.js +61 -61
- package/lib/decorators/TypedQuery.d.ts +14 -14
- package/lib/decorators/TypedQuery.js +99 -99
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.d.ts +72 -72
- package/lib/decorators/TypedRoute.js +185 -185
- package/lib/decorators/internal/EncryptedConstant.d.ts +1 -1
- package/lib/decorators/internal/EncryptedConstant.js +7 -7
- package/lib/decorators/internal/TransformError.d.ts +1 -1
- package/lib/decorators/internal/TransformError.js +10 -10
- package/lib/decorators/internal/get_path_and_stringify.d.ts +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +78 -78
- package/lib/decorators/internal/headers_to_object.d.ts +3 -3
- package/lib/decorators/internal/headers_to_object.js +49 -49
- package/lib/decorators/internal/load_controller.d.ts +2 -2
- package/lib/decorators/internal/load_controller.js +151 -152
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.d.ts +3 -3
- package/lib/decorators/internal/route_error.js +86 -86
- package/lib/decorators/internal/validate_request_body.d.ts +2 -2
- package/lib/decorators/internal/validate_request_body.js +57 -57
- package/lib/index.d.ts +3 -3
- package/lib/index.js +31 -31
- package/lib/module.d.ts +12 -12
- package/lib/module.js +28 -28
- package/lib/options/INestiaTransformOptions.d.ts +4 -4
- package/lib/options/INestiaTransformOptions.js +2 -2
- package/lib/options/INestiaTransformProject.d.ts +5 -5
- package/lib/options/INestiaTransformProject.js +2 -2
- package/lib/options/IRequestBodyValidator.d.ts +16 -16
- package/lib/options/IRequestBodyValidator.js +2 -2
- package/lib/options/IResponseBodyStringifier.d.ts +20 -20
- package/lib/options/IResponseBodyStringifier.js +2 -2
- package/lib/programmers/TypedBodyProgrammer.d.ts +5 -5
- package/lib/programmers/TypedBodyProgrammer.js +45 -45
- package/lib/programmers/TypedQueryProgrammer.d.ts +5 -5
- package/lib/programmers/TypedQueryProgrammer.js +260 -165
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.d.ts +5 -5
- package/lib/programmers/TypedRouteProgrammer.js +47 -47
- package/lib/transform.d.ts +3 -3
- package/lib/transform.js +20 -20
- package/lib/transformers/FileTransformer.d.ts +5 -5
- package/lib/transformers/FileTransformer.js +32 -32
- package/lib/transformers/MethodDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/MethodDecoratorTransformer.js +87 -87
- package/lib/transformers/MethodTransformer.d.ts +5 -5
- package/lib/transformers/MethodTransformer.js +54 -54
- package/lib/transformers/MethodTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +5 -5
- package/lib/transformers/NodeTransformer.js +20 -20
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +5 -5
- package/lib/transformers/ParameterDecoratorTransformer.js +53 -53
- package/lib/transformers/ParameterTransformer.d.ts +5 -5
- package/lib/transformers/ParameterTransformer.js +33 -33
- package/lib/transformers/ParameterTransformer.js.map +1 -1
- package/lib/typings/Creator.d.ts +3 -3
- package/lib/typings/Creator.js +2 -2
- package/lib/utils/ExceptionManager.d.ts +64 -64
- package/lib/utils/ExceptionManager.js +112 -112
- package/lib/utils/Singleton.d.ts +1 -1
- package/lib/utils/Singleton.js +23 -23
- package/package.json +8 -9
- package/src/decorators/TypedQuery.ts +10 -8
- package/src/programmers/TypedQueryProgrammer.ts +104 -33
- package/src/transformers/MethodTransformer.ts +1 -1
- package/src/transformers/ParameterTransformer.ts +1 -1
- 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,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
|
-
}
|