nestia 3.0.15 → 3.0.16-dev.20220930

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 (64) hide show
  1. package/lib/IConfiguration.d.ts +110 -110
  2. package/lib/IConfiguration.js +2 -2
  3. package/lib/NestiaApplication.d.ts +11 -11
  4. package/lib/NestiaApplication.js +155 -155
  5. package/lib/analyses/ControllerAnalyzer.d.ts +6 -6
  6. package/lib/analyses/ControllerAnalyzer.js +105 -105
  7. package/lib/analyses/GenericAnalyzer.d.ts +5 -5
  8. package/lib/analyses/GenericAnalyzer.js +40 -40
  9. package/lib/analyses/ImportAnalyzer.d.ts +13 -13
  10. package/lib/analyses/ImportAnalyzer.js +83 -83
  11. package/lib/analyses/PathAnalyzer.d.ts +5 -5
  12. package/lib/analyses/PathAnalyzer.js +50 -50
  13. package/lib/analyses/ReflectAnalyzer.d.ts +4 -4
  14. package/lib/analyses/ReflectAnalyzer.js +229 -229
  15. package/lib/analyses/SourceFinder.d.ts +4 -4
  16. package/lib/analyses/SourceFinder.js +69 -69
  17. package/lib/executable/internal/CompilerOptions.d.ts +11 -11
  18. package/lib/executable/internal/CompilerOptions.js +17 -17
  19. package/lib/executable/internal/NestiaCommand.d.ts +4 -4
  20. package/lib/executable/internal/NestiaCommand.js +127 -127
  21. package/lib/executable/internal/NestiaConfig.d.ts +4 -4
  22. package/lib/executable/internal/NestiaConfig.js +521 -521
  23. package/lib/executable/internal/nestia.config.getter.d.ts +1 -1
  24. package/lib/executable/internal/nestia.config.getter.js +23 -23
  25. package/lib/executable/nestia.d.ts +2 -2
  26. package/lib/executable/nestia.js +54 -54
  27. package/lib/generates/FileGenerator.d.ts +5 -5
  28. package/lib/generates/FileGenerator.js +136 -136
  29. package/lib/generates/FunctionGenerator.d.ts +5 -5
  30. package/lib/generates/FunctionGenerator.js +203 -203
  31. package/lib/generates/SdkGenerator.d.ts +7 -7
  32. package/lib/generates/SdkGenerator.js +46 -46
  33. package/lib/generates/SwaggerGenerator.d.ts +6 -6
  34. package/lib/generates/SwaggerGenerator.js +235 -235
  35. package/lib/index.d.ts +2 -2
  36. package/lib/index.js +27 -27
  37. package/lib/module.d.ts +2 -2
  38. package/lib/module.js +18 -18
  39. package/lib/structures/IController.d.ts +23 -23
  40. package/lib/structures/IController.js +2 -2
  41. package/lib/structures/IRoute.d.ts +24 -24
  42. package/lib/structures/IRoute.js +2 -2
  43. package/lib/structures/ISwagger.d.ts +48 -48
  44. package/lib/structures/ISwagger.js +2 -2
  45. package/lib/structures/ITypeTuple.d.ts +5 -5
  46. package/lib/structures/ITypeTuple.js +2 -2
  47. package/lib/structures/MethodType.d.ts +4 -4
  48. package/lib/structures/MethodType.js +13 -13
  49. package/lib/structures/ParamCategory.d.ts +1 -1
  50. package/lib/structures/ParamCategory.js +2 -2
  51. package/lib/structures/TypeEntry.d.ts +9 -9
  52. package/lib/structures/TypeEntry.js +20 -20
  53. package/lib/utils/ArrayUtil.d.ts +5 -5
  54. package/lib/utils/ArrayUtil.js +38 -38
  55. package/lib/utils/DirectoryUtil.d.ts +5 -5
  56. package/lib/utils/DirectoryUtil.js +61 -61
  57. package/lib/utils/ImportDictionary.d.ts +6 -6
  58. package/lib/utils/ImportDictionary.js +49 -49
  59. package/lib/utils/MapUtil.d.ts +3 -3
  60. package/lib/utils/MapUtil.js +15 -15
  61. package/lib/utils/StripEnums.d.ts +3 -3
  62. package/lib/utils/StripEnums.js +2 -2
  63. package/package.json +1 -1
  64. package/preliminaries/nestia.config.ts +70 -70
@@ -1,110 +1,110 @@
1
- import ts from "typescript";
2
- import type { StripEnums } from "./utils/StripEnums";
3
- /**
4
- * Definition for the `nestia.config.ts` file.
5
- *
6
- * @author Jeongho Nam - https://github.com/samchon
7
- */
8
- export interface IConfiguration {
9
- /**
10
- * List of files or directories containing the NestJS controller classes.
11
- */
12
- input: string | string[] | IConfiguration.IInput;
13
- /**
14
- * Output directory that SDK would be placed in.
15
- *
16
- * If not configured, you can't build the SDK library.
17
- */
18
- output?: string;
19
- /**
20
- * Compiler options for the TypeScript.
21
- *
22
- * If you've omitted this property or the assigned property cannot fully cover the
23
- * `tsconfig.json`, the properties from the `tsconfig.json` would be assigned to here.
24
- * Otherwise, this property has been configured and it's detailed values are different
25
- * with the `tsconfig.json`, this property values would be used instead.
26
- *
27
- * ```typescript
28
- * import ts from "typescript";
29
- *
30
- * const tsconfig: ts.TsConfig;
31
- * const nestiaConfig: IConfiguration;
32
- *
33
- * const compilerOptions: ts.CompilerOptions = {
34
- * ...tsconfig.compilerOptions,
35
- * ...(nestiaConfig.compilerOptions || {})
36
- * }
37
- * ```
38
- */
39
- compilerOptions?: StripEnums<ts.CompilerOptions>;
40
- /**
41
- * Whether to assert parameter types or not.
42
- *
43
- * If you configure this property to be `true`, all of the function parameters would be
44
- * checked through the [typescript-json](https://github.com/samchon/typescript-json#runtime-type-checkers).
45
- * This option would make your SDK library slower, but would enahcne the type safety even
46
- * in the runtime level.
47
- *
48
- * @default false
49
- */
50
- assert?: boolean;
51
- /**
52
- * Whether to optimize JSON string conversion 2x faster or not.
53
- *
54
- * If you configure this property to be `true`, the SDK library would utilize the
55
- * [typescript-json](https://github.com/samchon/typescript-json#fastest-json-string-converter)
56
- * and the JSON string conversion speed really be 2x faster.
57
- *
58
- * @default false
59
- */
60
- json?: boolean;
61
- /**
62
- * Whether to wrap DTO by primitive type.
63
- *
64
- * If you don't configure this property as `false`, all of DTOs in the
65
- * SDK library would be automatically wrapped by {@link Primitive} type.
66
- *
67
- * For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
68
- * all of methods in the DTO type would be automatically erased. Also, if
69
- * the DTO has a `toJSON()` method, the DTO type would be automatically
70
- * converted to return type of the `toJSON()` method.
71
- *
72
- * @default true
73
- */
74
- primitive?: boolean;
75
- /**
76
- * Building `swagger.json` is also possible.
77
- *
78
- * If not specified, you can't build the `swagger.json`.
79
- */
80
- swagger?: IConfiguration.ISwagger;
81
- }
82
- export declare namespace IConfiguration {
83
- /**
84
- * List of files or directories to include or exclude to specifying the NestJS
85
- * controllers.
86
- */
87
- interface IInput {
88
- /**
89
- * List of files or directories containing the NestJS controller classes.
90
- */
91
- include: string[];
92
- /**
93
- * List of files or directories to be excluded.
94
- */
95
- exclude?: string[];
96
- }
97
- /**
98
- * Building `swagger.json` is also possible.
99
- */
100
- interface ISwagger {
101
- /**
102
- * Output path of the `swagger.json`.
103
- *
104
- * If you've configured only directory, the file name would be the `swagger.json`.
105
- * Otherwise you've configured the full path with file name and extension, the
106
- * `swagger.json` file would be renamed to it.
107
- */
108
- output: string;
109
- }
110
- }
1
+ import ts from "typescript";
2
+ import type { StripEnums } from "./utils/StripEnums";
3
+ /**
4
+ * Definition for the `nestia.config.ts` file.
5
+ *
6
+ * @author Jeongho Nam - https://github.com/samchon
7
+ */
8
+ export interface IConfiguration {
9
+ /**
10
+ * List of files or directories containing the NestJS controller classes.
11
+ */
12
+ input: string | string[] | IConfiguration.IInput;
13
+ /**
14
+ * Output directory that SDK would be placed in.
15
+ *
16
+ * If not configured, you can't build the SDK library.
17
+ */
18
+ output?: string;
19
+ /**
20
+ * Compiler options for the TypeScript.
21
+ *
22
+ * If you've omitted this property or the assigned property cannot fully cover the
23
+ * `tsconfig.json`, the properties from the `tsconfig.json` would be assigned to here.
24
+ * Otherwise, this property has been configured and it's detailed values are different
25
+ * with the `tsconfig.json`, this property values would be used instead.
26
+ *
27
+ * ```typescript
28
+ * import ts from "typescript";
29
+ *
30
+ * const tsconfig: ts.TsConfig;
31
+ * const nestiaConfig: IConfiguration;
32
+ *
33
+ * const compilerOptions: ts.CompilerOptions = {
34
+ * ...tsconfig.compilerOptions,
35
+ * ...(nestiaConfig.compilerOptions || {})
36
+ * }
37
+ * ```
38
+ */
39
+ compilerOptions?: StripEnums<ts.CompilerOptions>;
40
+ /**
41
+ * Whether to assert parameter types or not.
42
+ *
43
+ * If you configure this property to be `true`, all of the function parameters would be
44
+ * checked through the [typescript-json](https://github.com/samchon/typescript-json#runtime-type-checkers).
45
+ * This option would make your SDK library slower, but would enahcne the type safety even
46
+ * in the runtime level.
47
+ *
48
+ * @default false
49
+ */
50
+ assert?: boolean;
51
+ /**
52
+ * Whether to optimize JSON string conversion 2x faster or not.
53
+ *
54
+ * If you configure this property to be `true`, the SDK library would utilize the
55
+ * [typescript-json](https://github.com/samchon/typescript-json#fastest-json-string-converter)
56
+ * and the JSON string conversion speed really be 2x faster.
57
+ *
58
+ * @default false
59
+ */
60
+ json?: boolean;
61
+ /**
62
+ * Whether to wrap DTO by primitive type.
63
+ *
64
+ * If you don't configure this property as `false`, all of DTOs in the
65
+ * SDK library would be automatically wrapped by {@link Primitive} type.
66
+ *
67
+ * For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
68
+ * all of methods in the DTO type would be automatically erased. Also, if
69
+ * the DTO has a `toJSON()` method, the DTO type would be automatically
70
+ * converted to return type of the `toJSON()` method.
71
+ *
72
+ * @default true
73
+ */
74
+ primitive?: boolean;
75
+ /**
76
+ * Building `swagger.json` is also possible.
77
+ *
78
+ * If not specified, you can't build the `swagger.json`.
79
+ */
80
+ swagger?: IConfiguration.ISwagger;
81
+ }
82
+ export declare namespace IConfiguration {
83
+ /**
84
+ * List of files or directories to include or exclude to specifying the NestJS
85
+ * controllers.
86
+ */
87
+ interface IInput {
88
+ /**
89
+ * List of files or directories containing the NestJS controller classes.
90
+ */
91
+ include: string[];
92
+ /**
93
+ * List of files or directories to be excluded.
94
+ */
95
+ exclude?: string[];
96
+ }
97
+ /**
98
+ * Building `swagger.json` is also possible.
99
+ */
100
+ interface ISwagger {
101
+ /**
102
+ * Output path of the `swagger.json`.
103
+ *
104
+ * If you've configured only directory, the file name would be the `swagger.json`.
105
+ * Otherwise you've configured the full path with file name and extension, the
106
+ * `swagger.json` file would be renamed to it.
107
+ */
108
+ output: string;
109
+ }
110
+ }
@@ -1,3 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  //# sourceMappingURL=IConfiguration.js.map
@@ -1,11 +1,11 @@
1
- import { IConfiguration } from "./IConfiguration";
2
- export declare class NestiaApplication {
3
- private readonly config_;
4
- private readonly bundle_checker_;
5
- constructor(config: IConfiguration);
6
- sdk(): Promise<void>;
7
- swagger(): Promise<void>;
8
- private generate;
9
- private prepare;
10
- private is_not_excluded;
11
- }
1
+ import { IConfiguration } from "./IConfiguration";
2
+ export declare class NestiaApplication {
3
+ private readonly config_;
4
+ private readonly bundle_checker_;
5
+ constructor(config: IConfiguration);
6
+ sdk(): Promise<void>;
7
+ swagger(): Promise<void>;
8
+ private generate;
9
+ private prepare;
10
+ private is_not_excluded;
11
+ }
@@ -1,156 +1,156 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.NestiaApplication = void 0;
39
- const fs_1 = __importDefault(require("fs"));
40
- const path_1 = __importDefault(require("path"));
41
- const runner = __importStar(require("ts-node"));
42
- const typescript_1 = __importDefault(require("typescript"));
43
- const Pair_1 = require("tstl/utility/Pair");
44
- const Singleton_1 = require("tstl/thread/Singleton");
45
- const ControllerAnalyzer_1 = require("./analyses/ControllerAnalyzer");
46
- const ReflectAnalyzer_1 = require("./analyses/ReflectAnalyzer");
47
- const SourceFinder_1 = require("./analyses/SourceFinder");
48
- const SdkGenerator_1 = require("./generates/SdkGenerator");
49
- const SwaggerGenerator_1 = require("./generates/SwaggerGenerator");
50
- const ArrayUtil_1 = require("./utils/ArrayUtil");
51
- const CompilerOptions_1 = require("./executable/internal/CompilerOptions");
52
- class NestiaApplication {
53
- constructor(config) {
54
- this.config_ = config;
55
- this.bundle_checker_ = new Singleton_1.Singleton(() => __awaiter(this, void 0, void 0, function* () {
56
- if (!this.config_.output)
57
- return () => false;
58
- const bundles = yield fs_1.default.promises.readdir(SdkGenerator_1.SdkGenerator.BUNDLE_PATH);
59
- const tuples = yield ArrayUtil_1.ArrayUtil.asyncMap(bundles, (file) => __awaiter(this, void 0, void 0, function* () {
60
- const relative = path_1.default.join(this.config_.output, file);
61
- const location = path_1.default.join(SdkGenerator_1.SdkGenerator.BUNDLE_PATH, file);
62
- const stats = yield fs_1.default.promises.stat(location);
63
- return new Pair_1.Pair(relative, stats.isDirectory());
64
- }));
65
- return (file) => {
66
- for (const it of tuples)
67
- if (it.second === false && file === it.first)
68
- return true;
69
- else if (it.second === true && file.indexOf(it.first) === 0)
70
- return true;
71
- return false;
72
- };
73
- }));
74
- }
75
- sdk() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- if (!this.config_.output)
78
- throw new Error("Error on NestiaApplication.sdk(): output path is not specified.");
79
- const parent = path_1.default.resolve(this.config_.output + "/..");
80
- const stats = yield fs_1.default.promises.lstat(parent);
81
- if (stats.isDirectory() === false)
82
- throw new Error("Error on NestiaApplication.sdk(): output directory does not exists.");
83
- yield this.generate((config) => config, SdkGenerator_1.SdkGenerator.generate);
84
- });
85
- }
86
- swagger() {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- if (!this.config_.swagger || !this.config_.swagger.output)
89
- throw new Error(`Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`);
90
- const parsed = path_1.default.parse(this.config_.swagger.output);
91
- const directory = !!parsed.ext
92
- ? path_1.default.resolve(parsed.dir)
93
- : this.config_.swagger.output;
94
- const stats = yield fs_1.default.promises.lstat(directory);
95
- if (stats.isDirectory() === false)
96
- throw new Error("Error on NestiaApplication.swagger(): output directory does not exists.");
97
- yield this.generate((config) => config.swagger, SwaggerGenerator_1.SwaggerGenerator.generate);
98
- });
99
- }
100
- generate(config, archiver) {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- // MOUNT TS-NODE
103
- this.prepare();
104
- // LOAD CONTROLLER FILES
105
- const input = this.config_.input instanceof Array
106
- ? { include: this.config_.input }
107
- : typeof this.config_.input === "string"
108
- ? { include: [this.config_.input] }
109
- : this.config_.input;
110
- const fileList = yield ArrayUtil_1.ArrayUtil.asyncFilter(yield SourceFinder_1.SourceFinder.find(input), (file) => this.is_not_excluded(file));
111
- // ANALYZE REFLECTS
112
- const unique = new WeakSet();
113
- const controllerList = [];
114
- for (const file of fileList)
115
- controllerList.push(...(yield ReflectAnalyzer_1.ReflectAnalyzer.analyze(unique, file)));
116
- // ANALYZE TYPESCRIPT CODE
117
- const program = typescript_1.default.createProgram(controllerList.map((c) => c.file), this.config_.compilerOptions || { noEmit: true });
118
- const checker = program.getTypeChecker();
119
- const routeList = [];
120
- for (const controller of controllerList) {
121
- const sourceFile = program.getSourceFile(controller.file);
122
- if (sourceFile === undefined)
123
- continue;
124
- routeList.push(...ControllerAnalyzer_1.ControllerAnalyzer.analyze(checker, sourceFile, controller));
125
- }
126
- // DO GENERATE
127
- yield archiver(checker, config(this.config_), routeList);
128
- });
129
- }
130
- prepare() {
131
- var _a;
132
- // CONSTRUCT OPTIONS
133
- if (!this.config_.compilerOptions)
134
- this.config_.compilerOptions =
135
- CompilerOptions_1.CompilerOptions.DEFAULT_OPTIONS;
136
- const absoluted = !!((_a = this.config_.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
137
- // MOUNT TS-NODE
138
- runner.register({
139
- emit: false,
140
- compiler: "ttypescript",
141
- compilerOptions: this.config_.compilerOptions,
142
- require: absoluted ? ["tsconfig-paths/register"] : undefined,
143
- });
144
- }
145
- is_not_excluded(file) {
146
- return __awaiter(this, void 0, void 0, function* () {
147
- if (this.config_.output)
148
- return (file.indexOf(path_1.default.join(this.config_.output, "functional")) ===
149
- -1 && (yield this.bundle_checker_.get())(file) === false);
150
- const content = yield fs_1.default.promises.readFile(file, "utf8");
151
- return (content.indexOf(" * @nestia Generated by Nestia - https://github.com/samchon/nestia") === -1);
152
- });
153
- }
154
- }
155
- exports.NestiaApplication = NestiaApplication;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.NestiaApplication = void 0;
39
+ const fs_1 = __importDefault(require("fs"));
40
+ const path_1 = __importDefault(require("path"));
41
+ const runner = __importStar(require("ts-node"));
42
+ const typescript_1 = __importDefault(require("typescript"));
43
+ const Pair_1 = require("tstl/utility/Pair");
44
+ const Singleton_1 = require("tstl/thread/Singleton");
45
+ const ControllerAnalyzer_1 = require("./analyses/ControllerAnalyzer");
46
+ const ReflectAnalyzer_1 = require("./analyses/ReflectAnalyzer");
47
+ const SourceFinder_1 = require("./analyses/SourceFinder");
48
+ const SdkGenerator_1 = require("./generates/SdkGenerator");
49
+ const SwaggerGenerator_1 = require("./generates/SwaggerGenerator");
50
+ const ArrayUtil_1 = require("./utils/ArrayUtil");
51
+ const CompilerOptions_1 = require("./executable/internal/CompilerOptions");
52
+ class NestiaApplication {
53
+ constructor(config) {
54
+ this.config_ = config;
55
+ this.bundle_checker_ = new Singleton_1.Singleton(() => __awaiter(this, void 0, void 0, function* () {
56
+ if (!this.config_.output)
57
+ return () => false;
58
+ const bundles = yield fs_1.default.promises.readdir(SdkGenerator_1.SdkGenerator.BUNDLE_PATH);
59
+ const tuples = yield ArrayUtil_1.ArrayUtil.asyncMap(bundles, (file) => __awaiter(this, void 0, void 0, function* () {
60
+ const relative = path_1.default.join(this.config_.output, file);
61
+ const location = path_1.default.join(SdkGenerator_1.SdkGenerator.BUNDLE_PATH, file);
62
+ const stats = yield fs_1.default.promises.stat(location);
63
+ return new Pair_1.Pair(relative, stats.isDirectory());
64
+ }));
65
+ return (file) => {
66
+ for (const it of tuples)
67
+ if (it.second === false && file === it.first)
68
+ return true;
69
+ else if (it.second === true && file.indexOf(it.first) === 0)
70
+ return true;
71
+ return false;
72
+ };
73
+ }));
74
+ }
75
+ sdk() {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ if (!this.config_.output)
78
+ throw new Error("Error on NestiaApplication.sdk(): output path is not specified.");
79
+ const parent = path_1.default.resolve(this.config_.output + "/..");
80
+ const stats = yield fs_1.default.promises.lstat(parent);
81
+ if (stats.isDirectory() === false)
82
+ throw new Error("Error on NestiaApplication.sdk(): output directory does not exists.");
83
+ yield this.generate((config) => config, SdkGenerator_1.SdkGenerator.generate);
84
+ });
85
+ }
86
+ swagger() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (!this.config_.swagger || !this.config_.swagger.output)
89
+ throw new Error(`Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`);
90
+ const parsed = path_1.default.parse(this.config_.swagger.output);
91
+ const directory = !!parsed.ext
92
+ ? path_1.default.resolve(parsed.dir)
93
+ : this.config_.swagger.output;
94
+ const stats = yield fs_1.default.promises.lstat(directory);
95
+ if (stats.isDirectory() === false)
96
+ throw new Error("Error on NestiaApplication.swagger(): output directory does not exists.");
97
+ yield this.generate((config) => config.swagger, SwaggerGenerator_1.SwaggerGenerator.generate);
98
+ });
99
+ }
100
+ generate(config, archiver) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ // MOUNT TS-NODE
103
+ this.prepare();
104
+ // LOAD CONTROLLER FILES
105
+ const input = this.config_.input instanceof Array
106
+ ? { include: this.config_.input }
107
+ : typeof this.config_.input === "string"
108
+ ? { include: [this.config_.input] }
109
+ : this.config_.input;
110
+ const fileList = yield ArrayUtil_1.ArrayUtil.asyncFilter(yield SourceFinder_1.SourceFinder.find(input), (file) => this.is_not_excluded(file));
111
+ // ANALYZE REFLECTS
112
+ const unique = new WeakSet();
113
+ const controllerList = [];
114
+ for (const file of fileList)
115
+ controllerList.push(...(yield ReflectAnalyzer_1.ReflectAnalyzer.analyze(unique, file)));
116
+ // ANALYZE TYPESCRIPT CODE
117
+ const program = typescript_1.default.createProgram(controllerList.map((c) => c.file), this.config_.compilerOptions || { noEmit: true });
118
+ const checker = program.getTypeChecker();
119
+ const routeList = [];
120
+ for (const controller of controllerList) {
121
+ const sourceFile = program.getSourceFile(controller.file);
122
+ if (sourceFile === undefined)
123
+ continue;
124
+ routeList.push(...ControllerAnalyzer_1.ControllerAnalyzer.analyze(checker, sourceFile, controller));
125
+ }
126
+ // DO GENERATE
127
+ yield archiver(checker, config(this.config_), routeList);
128
+ });
129
+ }
130
+ prepare() {
131
+ var _a;
132
+ // CONSTRUCT OPTIONS
133
+ if (!this.config_.compilerOptions)
134
+ this.config_.compilerOptions =
135
+ CompilerOptions_1.CompilerOptions.DEFAULT_OPTIONS;
136
+ const absoluted = !!((_a = this.config_.compilerOptions) === null || _a === void 0 ? void 0 : _a.baseUrl);
137
+ // MOUNT TS-NODE
138
+ runner.register({
139
+ emit: false,
140
+ compiler: "ttypescript",
141
+ compilerOptions: this.config_.compilerOptions,
142
+ require: absoluted ? ["tsconfig-paths/register"] : undefined,
143
+ });
144
+ }
145
+ is_not_excluded(file) {
146
+ return __awaiter(this, void 0, void 0, function* () {
147
+ if (this.config_.output)
148
+ return (file.indexOf(path_1.default.join(this.config_.output, "functional")) ===
149
+ -1 && (yield this.bundle_checker_.get())(file) === false);
150
+ const content = yield fs_1.default.promises.readFile(file, "utf8");
151
+ return (content.indexOf(" * @nestia Generated by Nestia - https://github.com/samchon/nestia") === -1);
152
+ });
153
+ }
154
+ }
155
+ exports.NestiaApplication = NestiaApplication;
156
156
  //# sourceMappingURL=NestiaApplication.js.map
@@ -1,6 +1,6 @@
1
- import ts from "typescript";
2
- import { IController } from "../structures/IController";
3
- import { IRoute } from "../structures/IRoute";
4
- export declare namespace ControllerAnalyzer {
5
- function analyze(checker: ts.TypeChecker, sourceFile: ts.SourceFile, controller: IController): IRoute[];
6
- }
1
+ import ts from "typescript";
2
+ import { IController } from "../structures/IController";
3
+ import { IRoute } from "../structures/IRoute";
4
+ export declare namespace ControllerAnalyzer {
5
+ function analyze(checker: ts.TypeChecker, sourceFile: ts.SourceFile, controller: IController): IRoute[];
6
+ }