@nestia/core 0.1.4 → 0.1.6

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 (41) hide show
  1. package/lib/decorators/DynamicModule.d.ts +3 -0
  2. package/lib/decorators/DynamicModule.js +73 -0
  3. package/lib/decorators/DynamicModule.js.map +1 -0
  4. package/lib/decorators/EncryptedModule.js +16 -137
  5. package/lib/decorators/EncryptedModule.js.map +1 -1
  6. package/lib/decorators/PlainBody.d.ts +1 -1
  7. package/lib/decorators/PlainBody.js +1 -1
  8. package/lib/decorators/internal/headers_to_object.d.ts +3 -1
  9. package/lib/decorators/internal/headers_to_object.js +0 -3
  10. package/lib/decorators/internal/headers_to_object.js.map +1 -1
  11. package/lib/decorators/internal/load_controller.d.ts +2 -0
  12. package/lib/decorators/internal/load_controller.js +153 -0
  13. package/lib/decorators/internal/load_controller.js.map +1 -0
  14. package/lib/decorators/internal/route_error.d.ts +3 -1
  15. package/lib/decorators/internal/route_error.js +0 -3
  16. package/lib/decorators/internal/route_error.js.map +1 -1
  17. package/lib/executable/core.d.ts +2 -0
  18. package/lib/executable/core.js +100 -0
  19. package/lib/executable/core.js.map +1 -0
  20. package/lib/executable/internal/CommandParser.d.ts +3 -0
  21. package/lib/executable/internal/CommandParser.js +21 -0
  22. package/lib/executable/internal/CommandParser.js.map +1 -0
  23. package/lib/executable/internal/CoreSetupWizard.d.ts +4 -0
  24. package/lib/executable/internal/CoreSetupWizard.js +259 -0
  25. package/lib/executable/internal/CoreSetupWizard.js.map +1 -0
  26. package/lib/module.d.ts +2 -0
  27. package/lib/module.js +2 -0
  28. package/lib/module.js.map +1 -1
  29. package/package.json +5 -1
  30. package/src/decorators/DynamicModule.ts +16 -0
  31. package/src/decorators/EncryptedModule.ts +9 -59
  32. package/src/decorators/PlainBody.ts +1 -1
  33. package/src/decorators/internal/headers_to_object.ts +0 -3
  34. package/src/decorators/internal/load_controller.ts +35 -0
  35. package/src/decorators/internal/route_error.ts +0 -3
  36. package/src/executable/core.ts +46 -0
  37. package/src/executable/internal/CommandParser.ts +15 -0
  38. package/src/executable/internal/CoreSetupWizard.ts +177 -0
  39. package/src/module.ts +2 -0
  40. package/src/options/INestiaTransformOptions.ts +1 -1
  41. package/src/options/INestiaTransformProject.ts +2 -1
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CommandParser = void 0;
4
+ var CommandParser;
5
+ (function (CommandParser) {
6
+ function parse(argList) {
7
+ var output = {};
8
+ argList.forEach(function (arg, i) {
9
+ if (arg.startsWith("--") === false)
10
+ return;
11
+ var key = arg.slice(2);
12
+ var value = argList[i + 1];
13
+ if (value === undefined || value.startsWith("--"))
14
+ return;
15
+ output[key] = value;
16
+ });
17
+ return output;
18
+ }
19
+ CommandParser.parse = parse;
20
+ })(CommandParser = exports.CommandParser || (exports.CommandParser = {}));
21
+ //# sourceMappingURL=CommandParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CommandParser.js","sourceRoot":"","sources":["../../../src/executable/internal/CommandParser.ts"],"names":[],"mappings":";;;AAAA,IAAiB,aAAa,CAc7B;AAdD,WAAiB,aAAa;IAC1B,SAAgB,KAAK,CAAC,OAAiB;QACnC,IAAM,MAAM,GAA2B,EAAE,CAAC;QAC1C,OAAO,CAAC,OAAO,CAAC,UAAC,GAAG,EAAE,CAAC;YACnB,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,KAAK;gBAAE,OAAO;YAE3C,IAAM,GAAG,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzB,IAAM,KAAK,GAAuB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO;YAE1D,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACxB,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;IAZe,mBAAK,QAYpB,CAAA;AACL,CAAC,EAdgB,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAc7B"}
@@ -0,0 +1,4 @@
1
+ export declare namespace CoreSetupWizard {
2
+ function ttypescript(manager: string): Promise<void>;
3
+ function tsPatch(manager: string): Promise<void>;
4
+ }
@@ -0,0 +1,259 @@
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 __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ 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;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ var __importDefault = (this && this.__importDefault) || function (mod) {
62
+ return (mod && mod.__esModule) ? mod : { "default": mod };
63
+ };
64
+ Object.defineProperty(exports, "__esModule", { value: true });
65
+ exports.CoreSetupWizard = void 0;
66
+ var child_process_1 = __importDefault(require("child_process"));
67
+ var fs_1 = __importDefault(require("fs"));
68
+ var CoreSetupWizard;
69
+ (function (CoreSetupWizard) {
70
+ var _this = this;
71
+ function ttypescript(manager) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var pack;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0: return [4 /*yield*/, prepare(manager)];
77
+ case 1:
78
+ pack = _a.sent();
79
+ add(manager)(pack)("ttypescript", true);
80
+ add(manager)(pack)("ts-node", true);
81
+ // TSCONFIG.JSON
82
+ return [4 /*yield*/, configure(manager)(pack)];
83
+ case 2:
84
+ // TSCONFIG.JSON
85
+ _a.sent();
86
+ return [2 /*return*/];
87
+ }
88
+ });
89
+ });
90
+ }
91
+ CoreSetupWizard.ttypescript = ttypescript;
92
+ function tsPatch(manager) {
93
+ return __awaiter(this, void 0, void 0, function () {
94
+ var _a, pack, _b, _c;
95
+ return __generator(this, function (_d) {
96
+ switch (_d.label) {
97
+ case 0:
98
+ // INSTALL
99
+ _a = add(manager);
100
+ return [4 /*yield*/, prepare(manager)];
101
+ case 1:
102
+ // INSTALL
103
+ _a.apply(void 0, [_d.sent()])("ts-patch", true);
104
+ execute("npx ts-patch install");
105
+ _c = (_b = JSON).parse;
106
+ return [4 /*yield*/, fs_1.default.promises.readFile("package.json", "utf8")];
107
+ case 2:
108
+ pack = _c.apply(_b, [_d.sent()]);
109
+ if (!pack.scripts || typeof pack.scripts !== "object")
110
+ pack.scripts = {};
111
+ if (typeof pack.scripts.prepare === "string") {
112
+ if (pack.scripts.prepare.indexOf("ts-patch install") === -1)
113
+ pack.scripts.prepare =
114
+ "ts-patch install && " + pack.scripts.prepare;
115
+ }
116
+ else
117
+ pack.scripts.prepare = "ts-patch install";
118
+ return [4 /*yield*/, fs_1.default.promises.writeFile("package.json", JSON.stringify(pack, null, 2), "utf8")];
119
+ case 3:
120
+ _d.sent();
121
+ // TSCONFIG.JSON
122
+ return [4 /*yield*/, configure(manager)(pack)];
123
+ case 4:
124
+ // TSCONFIG.JSON
125
+ _d.sent();
126
+ return [2 /*return*/];
127
+ }
128
+ });
129
+ });
130
+ }
131
+ CoreSetupWizard.tsPatch = tsPatch;
132
+ function prepare(manager) {
133
+ return __awaiter(this, void 0, void 0, function () {
134
+ var pack, _a, _b;
135
+ return __generator(this, function (_c) {
136
+ switch (_c.label) {
137
+ case 0:
138
+ if (fs_1.default.existsSync("package.json") === false)
139
+ halt(function () { })("make package.json file or move to it.");
140
+ _b = (_a = JSON).parse;
141
+ return [4 /*yield*/, fs_1.default.promises.readFile("package.json", "utf8")];
142
+ case 1:
143
+ pack = _b.apply(_a, [_c.sent()]);
144
+ add(manager)(pack)("typescript", true);
145
+ add(manager)(pack)("typia", false);
146
+ add(manager)(pack)("@nestia/core", false);
147
+ return [2 /*return*/, pack];
148
+ }
149
+ });
150
+ });
151
+ }
152
+ var configure = function (manager) {
153
+ return function (pack) { return __awaiter(_this, void 0, void 0, function () {
154
+ var temporary, halter, Comment, config, _a, _b, options, plugins, strict, core, typia;
155
+ return __generator(this, function (_c) {
156
+ var _d;
157
+ switch (_c.label) {
158
+ case 0:
159
+ // VALIDATE PRERATATION
160
+ if (fs_1.default.existsSync("tsconfig.json") === false) {
161
+ execute("npx tsc --init");
162
+ if (fs_1.default.existsSync("tsconfig.json") === false)
163
+ halt(function () { })("tsconfig.json file does not exist.");
164
+ }
165
+ temporary = !fs_1.default.existsSync("node_modules/comment-json");
166
+ if (temporary === true)
167
+ add(manager)(pack)("comment-json", true);
168
+ halter = halt(function () {
169
+ if (temporary === true)
170
+ remove(manager)("comment-json", true);
171
+ });
172
+ return [4 /*yield*/, (_d = process.cwd() + "/node_modules/comment-json", Promise.resolve().then(function () { return __importStar(require(_d)); }))];
173
+ case 1:
174
+ Comment = _c.sent();
175
+ _b = (_a = Comment).parse;
176
+ return [4 /*yield*/, fs_1.default.promises.readFile("tsconfig.json", "utf8")];
177
+ case 2:
178
+ config = _b.apply(_a, [_c.sent()]);
179
+ options = config.compilerOptions;
180
+ if (options === undefined)
181
+ halter("tsconfig.json file does not have \"compilerOptions\" property.");
182
+ plugins = (function () {
183
+ var plugins = options.plugins;
184
+ if (plugins === undefined)
185
+ return (options.plugins = []);
186
+ else if (!Array.isArray(plugins))
187
+ halter("\"plugins\" property of tsconfig.json must be array type.");
188
+ return plugins;
189
+ })();
190
+ strict = options.strict === true;
191
+ core = plugins.find(function (p) {
192
+ return typeof p === "object" &&
193
+ p !== null &&
194
+ p.transform === "@nestia/core/lib/transform";
195
+ });
196
+ typia = plugins.find(function (p) {
197
+ return typeof p === "object" &&
198
+ p !== null &&
199
+ p.transform === "typia/lib/transform";
200
+ });
201
+ if (!(strict === true && core !== undefined && typia !== undefined)) return [3 /*break*/, 3];
202
+ console.log("you've been already configured the tsconfig.json file.");
203
+ return [3 /*break*/, 5];
204
+ case 3:
205
+ // DO CONFIGURE
206
+ options.strict = true;
207
+ if (core === undefined)
208
+ plugins.push({
209
+ transform: "@nestia/core/lib/transform",
210
+ });
211
+ if (!(typia === undefined)) return [3 /*break*/, 5];
212
+ return [4 /*yield*/, fs_1.default.promises.writeFile("tsconfig.json", Comment.stringify(config, null, 2))];
213
+ case 4:
214
+ _c.sent();
215
+ _c.label = 5;
216
+ case 5:
217
+ if (temporary === true)
218
+ remove(manager)("comment-json", false);
219
+ return [2 /*return*/];
220
+ }
221
+ });
222
+ }); };
223
+ };
224
+ })(CoreSetupWizard = exports.CoreSetupWizard || (exports.CoreSetupWizard = {}));
225
+ var add = function (manager) {
226
+ return function (pack) {
227
+ return function (modulo, devOnly) {
228
+ var exists = (devOnly === false
229
+ ? !!pack.dependencies && !!pack.dependencies[modulo]
230
+ : !!pack.devDependencies && !!pack.devDependencies[modulo]) &&
231
+ fs_1.default.existsSync("node_modules/" + modulo);
232
+ var middle = manager === "yarn"
233
+ ? "add".concat(devOnly ? " -D" : "")
234
+ : "install ".concat(devOnly ? "--save-dev" : "--save");
235
+ if (exists === false)
236
+ execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
237
+ };
238
+ };
239
+ };
240
+ var remove = function (manager) {
241
+ return function (modulo, devOnly) {
242
+ var middle = manager === "yarn"
243
+ ? "remove".concat(devOnly ? " -D" : "")
244
+ : "uninstall ".concat(devOnly ? "--save-dev" : "--save");
245
+ execute("".concat(manager, " ").concat(middle, " ").concat(modulo));
246
+ };
247
+ };
248
+ var halt = function (closer) {
249
+ return function (desc) {
250
+ closer();
251
+ console.error(desc);
252
+ process.exit(-1);
253
+ };
254
+ };
255
+ function execute(command) {
256
+ console.log(command);
257
+ child_process_1.default.execSync(command, { stdio: "inherit" });
258
+ }
259
+ //# sourceMappingURL=CoreSetupWizard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CoreSetupWizard.js","sourceRoot":"","sources":["../../../src/executable/internal/CoreSetupWizard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAA+B;AAE/B,0CAAoB;AAEpB,IAAiB,eAAe,CAqI/B;AArID,WAAiB,eAAe;;IAC5B,SAAsB,WAAW,CAAC,OAAe;;;;;4BAE3B,qBAAM,OAAO,CAAC,OAAO,CAAC,EAAA;;wBAAlC,IAAI,GAAQ,SAAsB;wBACxC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,IAAI,CAAC,CAAC;wBACxC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;wBAEpC,gBAAgB;wBAChB,qBAAM,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,EAAA;;wBAD9B,gBAAgB;wBAChB,SAA8B,CAAC;;;;;KAClC;IARqB,2BAAW,cAQhC,CAAA;IAED,SAAsB,OAAO,CAAC,OAAe;;;;;;wBACzC,UAAU;wBACV,KAAA,GAAG,CAAC,OAAO,CAAC,CAAA;wBAAC,qBAAM,OAAO,CAAC,OAAO,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MAAM,cAAI,MAAM,CAAE,CAAC,CAAC;QACpE,CAAC;IAXD,CAWC;AAZD,CAYC,CAAC;AAEN,IAAM,MAAM,GACR,UAAC,OAAe;IAChB,OAAA,UAAC,MAAc,EAAE,OAAgB;QAC7B,IAAM,MAAM,GACR,OAAO,KAAK,MAAM;YACd,CAAC,CAAC,gBAAS,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAE;YACjC,CAAC,CAAC,oBAAa,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,QAAQ,CAAE,CAAC;QAC3D,OAAO,CAAC,UAAG,OAAO,cAAI,MAAM,cAAI,MAAM,CAAE,CAAC,CAAC;IAC9C,CAAC;AAND,CAMC,CAAC;AAEN,IAAM,IAAI,GACN,UAAC,MAAiB;IAClB,OAAA,UAAC,IAAY;QACT,MAAM,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACpB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;AAJD,CAIC,CAAC;AAEN,SAAS,OAAO,CAAC,OAAe;IAC5B,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACrB,uBAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;AAC/C,CAAC"}
package/lib/module.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export * from "./decorators/DynamicModule";
1
2
  export * from "./decorators/EncryptedBody";
2
3
  export * from "./decorators/EncryptedController";
3
4
  export * from "./decorators/EncryptedModule";
@@ -7,3 +8,4 @@ export * from "./decorators/PlainBody";
7
8
  export * from "./decorators/TypedBody";
8
9
  export * from "./decorators/TypedParam";
9
10
  export * from "./decorators/TypedRoute";
11
+ export * from "./options/INestiaTransformOptions";
package/lib/module.js CHANGED
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./decorators/DynamicModule"), exports);
17
18
  __exportStar(require("./decorators/EncryptedBody"), exports);
18
19
  __exportStar(require("./decorators/EncryptedController"), exports);
19
20
  __exportStar(require("./decorators/EncryptedModule"), exports);
@@ -23,4 +24,5 @@ __exportStar(require("./decorators/PlainBody"), exports);
23
24
  __exportStar(require("./decorators/TypedBody"), exports);
24
25
  __exportStar(require("./decorators/TypedParam"), exports);
25
26
  __exportStar(require("./decorators/TypedRoute"), exports);
27
+ __exportStar(require("./options/INestiaTransformOptions"), exports);
26
28
  //# sourceMappingURL=module.js.map
package/lib/module.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,mEAAiD;AACjD,+DAA6C;AAC7C,8DAA4C;AAC5C,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,0DAAwC;AACxC,0DAAwC"}
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA2C;AAC3C,6DAA2C;AAC3C,mEAAiD;AACjD,+DAA6C;AAC7C,8DAA4C;AAC5C,2DAAyC;AACzC,yDAAuC;AACvC,yDAAuC;AACvC,0DAAwC;AACxC,0DAAwC;AACxC,oEAAkD"}
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "@nestia/core",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Super-fast validation decorators of NestJS",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
+ "bin": {
8
+ "@nestia/core": "lib/executable/core.js"
9
+ },
7
10
  "scripts": {
8
11
  "build": "rimraf lib && tsc",
9
12
  "build:test": "rimraf bin && ttsc -p test/tsconfig.json",
@@ -37,6 +40,7 @@
37
40
  "@types/express": "^4.17.15",
38
41
  "@typescript-eslint/eslint-plugin": "^5.46.1",
39
42
  "@typescript-eslint/parser": "^5.46.1",
43
+ "comment-json": "^4.2.3",
40
44
  "eslint-plugin-deprecation": "^1.3.3",
41
45
  "git-last-commit": "^1.0.1",
42
46
  "rimraf": "^3.0.2",
@@ -0,0 +1,16 @@
1
+ import { Module } from "@nestjs/common";
2
+
3
+ import { Creator } from "../typings/Creator";
4
+ import { load_controllers } from "./internal/load_controller";
5
+
6
+ export namespace DynamicModule {
7
+ export async function mount(path: string): Promise<object> {
8
+ // LOAD CONTROLLERS
9
+ const controllers: Creator<object>[] = await load_controllers(path);
10
+
11
+ // RETURN WITH DECORATING
12
+ @Module({ controllers })
13
+ class NestiaModule {}
14
+ return NestiaModule;
15
+ }
16
+ }
@@ -1,9 +1,9 @@
1
1
  import { IEncryptionPassword } from "@nestia/fetcher/lib/IEncryptionPassword";
2
2
  import { Module, ModuleMetadata } from "@nestjs/common";
3
- import is_ts_node from "detect-ts-node";
4
- import fs from "fs";
5
3
 
4
+ import { Creator } from "../typings/Creator";
6
5
  import { ENCRYPTION_METADATA_KEY } from "./internal/EncryptedConstant";
6
+ import { load_controllers } from "./internal/load_controller";
7
7
 
8
8
  /**
9
9
  * Encrypted module.
@@ -43,16 +43,9 @@ export function EncryptedModule(
43
43
  Module(metadata)(target);
44
44
  if (metadata.controllers === undefined) return;
45
45
 
46
- for (const controller of metadata.controllers)
47
- if (
48
- Reflect.hasMetadata(ENCRYPTION_METADATA_KEY, controller) ===
49
- false
50
- )
51
- Reflect.defineMetadata(
52
- ENCRYPTION_METADATA_KEY,
53
- password,
54
- controller,
55
- );
46
+ for (const c of metadata.controllers)
47
+ if (Reflect.hasMetadata(ENCRYPTION_METADATA_KEY, c) === false)
48
+ Reflect.defineMetadata(ENCRYPTION_METADATA_KEY, password, c);
56
49
  };
57
50
  }
58
51
 
@@ -74,54 +67,11 @@ export namespace EncryptedModule {
74
67
  password: IEncryptionPassword | IEncryptionPassword.Closure,
75
68
  ): Promise<object> {
76
69
  // LOAD CONTROLLERS
77
- const metadata: ModuleMetadata = {
78
- controllers: await controllers(path, password),
79
- };
70
+ const controllers: Creator<object>[] = await load_controllers(path);
80
71
 
81
72
  // RETURNS WITH DECORATING
82
- @EncryptedModule(metadata, password)
83
- class Module {}
84
- return Module;
85
- }
86
-
87
- async function controllers(
88
- path: string,
89
- password: IEncryptionPassword | IEncryptionPassword.Closure,
90
- ): Promise<any[]> {
91
- const output: any[] = [];
92
- await iterate(output, path);
93
-
94
- for (const controller of output)
95
- if (
96
- Reflect.hasMetadata(ENCRYPTION_METADATA_KEY, controller) ===
97
- false
98
- )
99
- Reflect.defineMetadata(
100
- ENCRYPTION_METADATA_KEY,
101
- password,
102
- controller,
103
- );
104
-
105
- return output;
106
- }
107
-
108
- async function iterate(controllers: object[], path: string): Promise<void> {
109
- const directory: string[] = await fs.promises.readdir(path);
110
- for (const file of directory) {
111
- const current: string = `${path}/${file}`;
112
- const stats: fs.Stats = await fs.promises.lstat(current);
113
-
114
- if (stats.isDirectory() === true)
115
- await iterate(controllers, current);
116
- else if (file.substring(file.length - 3) === `.${EXTENSION}`) {
117
- const external: any = await import(current);
118
- for (const key in external) {
119
- const instance: object = external[key];
120
- if (Reflect.getMetadata("path", instance) !== undefined)
121
- controllers.push(instance);
122
- }
123
- }
124
- }
73
+ @EncryptedModule({ controllers }, password)
74
+ class NestiaModule {}
75
+ return NestiaModule;
125
76
  }
126
77
  }
127
- const EXTENSION = is_ts_node ? "ts" : "js";
@@ -13,7 +13,7 @@ import raw from "raw-body";
13
13
  *
14
14
  * If you adjust the regular {@link Body} decorator function to the body parameter,
15
15
  * you can't get the full body text because the {@link Body} tries to convert the
16
- * body text to JSON object. Therefore, `nestia-helper` provides this `PlainBody`
16
+ * body text to JSON object. Therefore, `@nestia/core` provides this `PlainBody`
17
17
  * decorator function to get the full body text.
18
18
  *
19
19
  * ```typescript
@@ -1,8 +1,5 @@
1
1
  import http from "http";
2
2
 
3
- /**
4
- * @internal
5
- */
6
3
  export function headers_to_object(
7
4
  headers: http.IncomingHttpHeaders,
8
5
  ): Record<string, string> {
@@ -0,0 +1,35 @@
1
+ import is_ts_node from "detect-ts-node";
2
+ import fs from "fs";
3
+
4
+ import { Creator } from "../../typings/Creator";
5
+
6
+ export async function load_controllers(
7
+ path: string,
8
+ ): Promise<Creator<object>[]> {
9
+ const output: any[] = [];
10
+ await iterate(output, path);
11
+ return output;
12
+ }
13
+
14
+ async function iterate(
15
+ controllers: Creator<object>[],
16
+ path: string,
17
+ ): Promise<void> {
18
+ const directory: string[] = await fs.promises.readdir(path);
19
+ for (const file of directory) {
20
+ const current: string = `${path}/${file}`;
21
+ const stats: fs.Stats = await fs.promises.lstat(current);
22
+
23
+ if (stats.isDirectory() === true) await iterate(controllers, current);
24
+ else if (file.substring(file.length - 3) === `.${EXTENSION}`) {
25
+ const external: any = await import(current);
26
+ for (const key in external) {
27
+ const instance: Creator<object> = external[key];
28
+ if (Reflect.getMetadata("path", instance) !== undefined)
29
+ controllers.push(instance);
30
+ }
31
+ }
32
+ }
33
+ }
34
+
35
+ const EXTENSION = is_ts_node ? "ts" : "js";
@@ -4,9 +4,6 @@ import { Observable, throwError } from "rxjs";
4
4
 
5
5
  import { ExceptionManager } from "../../utils/ExceptionManager";
6
6
 
7
- /**
8
- * @internal
9
- */
10
7
  export function route_error(
11
8
  request: express.Request,
12
9
  error: any,
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env node
2
+ import { CommandParser } from "./internal/CommandParser";
3
+ import { CoreSetupWizard } from "./internal/CoreSetupWizard";
4
+
5
+ const USAGE = `Wrong command has been detected. Use like below:
6
+
7
+ npx @nestia/core setup \\
8
+ --compiler (ttypescript|ts-patch) \\
9
+ --manager (npm|pnpm|yarn)
10
+
11
+ - npx @nestia/core setup
12
+ - npx @nestia/core setup --compiler ttypescript
13
+ - npx @nestia/core setup --compiler ts-patch
14
+ - npx @nestia/core setup --manager pnpm`;
15
+
16
+ function halt(desc: string): never {
17
+ console.error(desc);
18
+ process.exit(-1);
19
+ }
20
+
21
+ async function setup(): Promise<void> {
22
+ const options: Record<string, string> = CommandParser.parse(
23
+ process.argv.slice(3),
24
+ );
25
+ const manager: string = options.manager ?? "npm";
26
+ const compiler: string = options.compiler ?? "ttypescript";
27
+
28
+ if (
29
+ (compiler !== "ttypescript" && compiler !== "ts-patch") ||
30
+ (manager !== "npm" && manager !== "pnpm" && manager !== "yarn")
31
+ )
32
+ halt(USAGE);
33
+ else if (compiler === "ttypescript")
34
+ await CoreSetupWizard.ttypescript(manager);
35
+ else await CoreSetupWizard.tsPatch(manager);
36
+ }
37
+
38
+ async function main(): Promise<void> {
39
+ const type: string | undefined = process.argv[2];
40
+ if (type === "setup") await setup();
41
+ else halt(USAGE);
42
+ }
43
+ main().catch((exp) => {
44
+ console.error(exp);
45
+ process.exit(-1);
46
+ });
@@ -0,0 +1,15 @@
1
+ export namespace CommandParser {
2
+ export function parse(argList: string[]): Record<string, string> {
3
+ const output: Record<string, string> = {};
4
+ argList.forEach((arg, i) => {
5
+ if (arg.startsWith("--") === false) return;
6
+
7
+ const key = arg.slice(2);
8
+ const value: string | undefined = argList[i + 1];
9
+ if (value === undefined || value.startsWith("--")) return;
10
+
11
+ output[key] = value;
12
+ });
13
+ return output;
14
+ }
15
+ }