@nestia/sdk 0.1.0

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 (138) hide show
  1. package/assets/bundle/HttpError.ts +1 -0
  2. package/assets/bundle/IConnection.ts +1 -0
  3. package/assets/bundle/Primitive.ts +1 -0
  4. package/assets/config/nestia.config.ts +70 -0
  5. package/lib/INestiaConfig.d.ts +110 -0
  6. package/lib/INestiaConfig.js +3 -0
  7. package/lib/INestiaConfig.js.map +1 -0
  8. package/lib/NestiaSdkApplication.d.ts +11 -0
  9. package/lib/NestiaSdkApplication.js +156 -0
  10. package/lib/NestiaSdkApplication.js.map +1 -0
  11. package/lib/analyses/ControllerAnalyzer.d.ts +6 -0
  12. package/lib/analyses/ControllerAnalyzer.js +106 -0
  13. package/lib/analyses/ControllerAnalyzer.js.map +1 -0
  14. package/lib/analyses/GenericAnalyzer.d.ts +5 -0
  15. package/lib/analyses/GenericAnalyzer.js +41 -0
  16. package/lib/analyses/GenericAnalyzer.js.map +1 -0
  17. package/lib/analyses/ImportAnalyzer.d.ts +13 -0
  18. package/lib/analyses/ImportAnalyzer.js +86 -0
  19. package/lib/analyses/ImportAnalyzer.js.map +1 -0
  20. package/lib/analyses/PathAnalyzer.d.ts +5 -0
  21. package/lib/analyses/PathAnalyzer.js +51 -0
  22. package/lib/analyses/PathAnalyzer.js.map +1 -0
  23. package/lib/analyses/ReflectAnalyzer.d.ts +4 -0
  24. package/lib/analyses/ReflectAnalyzer.js +231 -0
  25. package/lib/analyses/ReflectAnalyzer.js.map +1 -0
  26. package/lib/analyses/SourceFinder.d.ts +4 -0
  27. package/lib/analyses/SourceFinder.js +71 -0
  28. package/lib/analyses/SourceFinder.js.map +1 -0
  29. package/lib/executable/internal/CommandParser.d.ts +3 -0
  30. package/lib/executable/internal/CommandParser.js +21 -0
  31. package/lib/executable/internal/CommandParser.js.map +1 -0
  32. package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +11 -0
  33. package/lib/executable/internal/NestiaConfigCompilerOptions.js +18 -0
  34. package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +1 -0
  35. package/lib/executable/internal/NestiaSdkCommand.d.ts +4 -0
  36. package/lib/executable/internal/NestiaSdkCommand.js +128 -0
  37. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -0
  38. package/lib/executable/internal/NestiaSdkConfig.d.ts +4 -0
  39. package/lib/executable/internal/NestiaSdkConfig.js +539 -0
  40. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -0
  41. package/lib/executable/internal/nestia.config.getter.d.ts +1 -0
  42. package/lib/executable/internal/nestia.config.getter.js +24 -0
  43. package/lib/executable/internal/nestia.config.getter.js.map +1 -0
  44. package/lib/executable/sdk.d.ts +2 -0
  45. package/lib/executable/sdk.js +86 -0
  46. package/lib/executable/sdk.js.map +1 -0
  47. package/lib/generates/FileGenerator.d.ts +5 -0
  48. package/lib/generates/FileGenerator.js +138 -0
  49. package/lib/generates/FileGenerator.js.map +1 -0
  50. package/lib/generates/FunctionGenerator.d.ts +5 -0
  51. package/lib/generates/FunctionGenerator.js +204 -0
  52. package/lib/generates/FunctionGenerator.js.map +1 -0
  53. package/lib/generates/SdkGenerator.d.ts +7 -0
  54. package/lib/generates/SdkGenerator.js +45 -0
  55. package/lib/generates/SdkGenerator.js.map +1 -0
  56. package/lib/generates/SwaggerGenerator.d.ts +6 -0
  57. package/lib/generates/SwaggerGenerator.js +244 -0
  58. package/lib/generates/SwaggerGenerator.js.map +1 -0
  59. package/lib/index.d.ts +2 -0
  60. package/lib/index.js +28 -0
  61. package/lib/index.js.map +1 -0
  62. package/lib/module.d.ts +2 -0
  63. package/lib/module.js +19 -0
  64. package/lib/module.js.map +1 -0
  65. package/lib/structures/IController.d.ts +23 -0
  66. package/lib/structures/IController.js +3 -0
  67. package/lib/structures/IController.js.map +1 -0
  68. package/lib/structures/IRoute.d.ts +24 -0
  69. package/lib/structures/IRoute.js +3 -0
  70. package/lib/structures/IRoute.js.map +1 -0
  71. package/lib/structures/ISwagger.d.ts +48 -0
  72. package/lib/structures/ISwagger.js +3 -0
  73. package/lib/structures/ISwagger.js.map +1 -0
  74. package/lib/structures/ITypeTuple.d.ts +5 -0
  75. package/lib/structures/ITypeTuple.js +3 -0
  76. package/lib/structures/ITypeTuple.js.map +1 -0
  77. package/lib/structures/MethodType.d.ts +4 -0
  78. package/lib/structures/MethodType.js +14 -0
  79. package/lib/structures/MethodType.js.map +1 -0
  80. package/lib/structures/ParamCategory.d.ts +1 -0
  81. package/lib/structures/ParamCategory.js +3 -0
  82. package/lib/structures/ParamCategory.js.map +1 -0
  83. package/lib/structures/TypeEntry.d.ts +9 -0
  84. package/lib/structures/TypeEntry.js +21 -0
  85. package/lib/structures/TypeEntry.js.map +1 -0
  86. package/lib/test/TestBuilder.d.ts +4 -0
  87. package/lib/test/TestBuilder.js +64 -0
  88. package/lib/test/TestBuilder.js.map +1 -0
  89. package/lib/test/index.d.ts +1 -0
  90. package/lib/test/index.js +61 -0
  91. package/lib/test/index.js.map +1 -0
  92. package/lib/test/test.builder.executor.d.ts +1 -0
  93. package/lib/test/test.builder.executor.js +24 -0
  94. package/lib/test/test.builder.executor.js.map +1 -0
  95. package/lib/utils/ArrayUtil.d.ts +5 -0
  96. package/lib/utils/ArrayUtil.js +39 -0
  97. package/lib/utils/ArrayUtil.js.map +1 -0
  98. package/lib/utils/ImportDictionary.d.ts +6 -0
  99. package/lib/utils/ImportDictionary.js +50 -0
  100. package/lib/utils/ImportDictionary.js.map +1 -0
  101. package/lib/utils/MapUtil.d.ts +3 -0
  102. package/lib/utils/MapUtil.js +16 -0
  103. package/lib/utils/MapUtil.js.map +1 -0
  104. package/lib/utils/StripEnums.d.ts +3 -0
  105. package/lib/utils/StripEnums.js +3 -0
  106. package/lib/utils/StripEnums.js.map +1 -0
  107. package/package.json +74 -0
  108. package/src/INestiaConfig.ts +120 -0
  109. package/src/NestiaSdkApplication.ts +183 -0
  110. package/src/analyses/ControllerAnalyzer.ts +203 -0
  111. package/src/analyses/GenericAnalyzer.ts +53 -0
  112. package/src/analyses/ImportAnalyzer.ts +143 -0
  113. package/src/analyses/PathAnalyzer.ts +58 -0
  114. package/src/analyses/ReflectAnalyzer.ts +279 -0
  115. package/src/analyses/SourceFinder.ts +59 -0
  116. package/src/executable/internal/CommandParser.ts +15 -0
  117. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -0
  118. package/src/executable/internal/NestiaSdkCommand.ts +174 -0
  119. package/src/executable/internal/NestiaSdkConfig.ts +35 -0
  120. package/src/executable/internal/nestia.config.getter.ts +12 -0
  121. package/src/executable/sdk.ts +51 -0
  122. package/src/generates/FileGenerator.ts +156 -0
  123. package/src/generates/FunctionGenerator.ts +287 -0
  124. package/src/generates/SdkGenerator.ts +50 -0
  125. package/src/generates/SwaggerGenerator.ts +393 -0
  126. package/src/index.ts +3 -0
  127. package/src/module.ts +2 -0
  128. package/src/structures/IController.ts +27 -0
  129. package/src/structures/IRoute.ts +29 -0
  130. package/src/structures/ISwagger.ts +55 -0
  131. package/src/structures/ITypeTuple.ts +6 -0
  132. package/src/structures/MethodType.ts +11 -0
  133. package/src/structures/ParamCategory.ts +1 -0
  134. package/src/structures/TypeEntry.ts +22 -0
  135. package/src/utils/ArrayUtil.ts +26 -0
  136. package/src/utils/ImportDictionary.ts +56 -0
  137. package/src/utils/MapUtil.ts +14 -0
  138. package/src/utils/StripEnums.ts +10 -0
@@ -0,0 +1,61 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const WorkerConnector_1 = require("tgrid/protocols/workers/WorkerConnector");
13
+ function execute(name, job, elements) {
14
+ return __awaiter(this, void 0, void 0, function* () {
15
+ if (job === "test")
16
+ console.log(`${name} -> npx ts-node -C ttypescript src/test`);
17
+ else
18
+ console.log(`${name} -> npx nestia ${job} ${elements.join(" ")}`);
19
+ const worker = new WorkerConnector_1.WorkerConnector(null, null, "process");
20
+ yield worker.connect(`${__dirname}/test.builder.executor.js`);
21
+ try {
22
+ const driver = worker.getDriver();
23
+ if (job === "test")
24
+ yield driver.test(name);
25
+ else
26
+ yield driver.generate(name, job, elements);
27
+ yield worker.close();
28
+ }
29
+ catch (exp) {
30
+ yield worker.close();
31
+ process.exit(-1);
32
+ }
33
+ });
34
+ }
35
+ function get_arguments(target, job, specialize = false) {
36
+ return [
37
+ target === "directory" ? "src/controllers" : "src/**/*.controller.ts",
38
+ "--out",
39
+ job === "sdk" ? "src/api" : specialize ? "swagger.json" : "./",
40
+ ];
41
+ }
42
+ function main() {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ console.log("Build Demonstration Projects");
45
+ for (const job of ["swagger", "sdk", "test"]) {
46
+ console.log("---------------------------------------------------------");
47
+ yield execute("176", job, get_arguments("directory", job));
48
+ yield execute("encrypted", job, get_arguments("directory", job));
49
+ yield execute("generic", job, get_arguments("directory", job));
50
+ yield execute("recursive", job, get_arguments("pattern", job));
51
+ yield execute("safe", job, get_arguments("directory", job));
52
+ yield execute("union", job, get_arguments("directory", job));
53
+ yield execute("multiple-paths", job, get_arguments("directory", job));
54
+ }
55
+ });
56
+ }
57
+ main().catch((exp) => {
58
+ console.log(exp);
59
+ process.exit(-1);
60
+ });
61
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,6EAA0E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AC5C,KAAK,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,KAAK,EAAE,MAAM,CAAU,EAAE;YACnD,OAAO,CAAC,GAAG,CACP,2DAA2D,CAC9D,CAAC;YACF,MAAM,OAAO,CAAC,KAAK,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;YAC3D,MAAM,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;YACjE,MAAM,OAAO,CAAC,SAAS,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;YAC/D,MAAM,OAAO,CAAC,WAAW,EAAE,GAAG,EAAE,aAAa,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC,CAAC;YAC/D,MAAM,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;YAC5D,MAAM,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;YAC7D,MAAM,OAAO,CAAC,gBAAgB,EAAE,GAAG,EAAE,aAAa,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,CAAC;SACzE;IACL,CAAC;CAAA;AACD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,24 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const WorkerServer_1 = require("tgrid/protocols/workers/WorkerServer");
13
+ const TestBuilder_1 = require("./TestBuilder");
14
+ function main() {
15
+ return __awaiter(this, void 0, void 0, function* () {
16
+ const worker = new WorkerServer_1.WorkerServer();
17
+ yield worker.open(TestBuilder_1.TestBuilder);
18
+ });
19
+ }
20
+ main().catch((exp) => {
21
+ console.log(exp);
22
+ process.exit(-1);
23
+ });
24
+ //# sourceMappingURL=test.builder.executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.builder.executor.js","sourceRoot":"","sources":["../../src/test/test.builder.executor.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,uEAAoE;AAEpE,+CAA4C;AAE5C,SAAe,IAAI;;QACf,MAAM,MAAM,GAAG,IAAI,2BAAY,EAAE,CAAC;QAClC,MAAM,MAAM,CAAC,IAAI,CAAC,yBAAW,CAAC,CAAC;IACnC,CAAC;CAAA;AACD,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IACjB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AACrB,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare namespace ArrayUtil {
2
+ function has<T>(array: T[], ...items: T[]): boolean;
3
+ function asyncMap<Input, Output>(array: Input[], closure: (input: Input) => Promise<Output>): Promise<Output[]>;
4
+ function asyncFilter<Input>(array: Input[], closure: (input: Input) => Promise<boolean>): Promise<Input[]>;
5
+ }
@@ -0,0 +1,39 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ArrayUtil = void 0;
13
+ var ArrayUtil;
14
+ (function (ArrayUtil) {
15
+ function has(array, ...items) {
16
+ return items.every((elem) => array.find((org) => org === elem) !== undefined);
17
+ }
18
+ ArrayUtil.has = has;
19
+ function asyncMap(array, closure) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const ret = [];
22
+ for (const elem of array)
23
+ ret.push(yield closure(elem));
24
+ return ret;
25
+ });
26
+ }
27
+ ArrayUtil.asyncMap = asyncMap;
28
+ function asyncFilter(array, closure) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ const ret = [];
31
+ for (const elem of array)
32
+ if ((yield closure(elem)) === true)
33
+ ret.push(elem);
34
+ return ret;
35
+ });
36
+ }
37
+ ArrayUtil.asyncFilter = asyncFilter;
38
+ })(ArrayUtil = exports.ArrayUtil || (exports.ArrayUtil = {}));
39
+ //# sourceMappingURL=ArrayUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArrayUtil.js","sourceRoot":"","sources":["../../src/utils/ArrayUtil.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,IAAiB,SAAS,CAyBzB;AAzBD,WAAiB,SAAS;IACtB,SAAgB,GAAG,CAAI,KAAU,EAAE,GAAG,KAAU;QAC5C,OAAO,KAAK,CAAC,KAAK,CACd,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,KAAK,SAAS,CAC5D,CAAC;IACN,CAAC;IAJe,aAAG,MAIlB,CAAA;IAED,SAAsB,QAAQ,CAC1B,KAAc,EACd,OAA0C;;YAE1C,MAAM,GAAG,GAAa,EAAE,CAAC;YACzB,KAAK,MAAM,IAAI,IAAI,KAAK;gBAAE,GAAG,CAAC,IAAI,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;YACxD,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;IAPqB,kBAAQ,WAO7B,CAAA;IAED,SAAsB,WAAW,CAC7B,KAAc,EACd,OAA2C;;YAE3C,MAAM,GAAG,GAAY,EAAE,CAAC;YACxB,KAAK,MAAM,IAAI,IAAI,KAAK;gBACpB,IAAI,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,IAAI;oBAAE,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvD,OAAO,GAAG,CAAC;QACf,CAAC;KAAA;IARqB,qBAAW,cAQhC,CAAA;AACL,CAAC,EAzBgB,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAyBzB"}
@@ -0,0 +1,6 @@
1
+ export declare class ImportDictionary {
2
+ private readonly dict_;
3
+ empty(): boolean;
4
+ emplace(file: string, realistic: boolean, instance: string): void;
5
+ toScript(outDir: string): string;
6
+ }
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ImportDictionary = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const HashMap_1 = require("tstl/container/HashMap");
9
+ const HashSet_1 = require("tstl/container/HashSet");
10
+ const Pair_1 = require("tstl/utility/Pair");
11
+ class ImportDictionary {
12
+ constructor() {
13
+ this.dict_ = new HashMap_1.HashMap();
14
+ }
15
+ empty() {
16
+ return this.dict_.empty();
17
+ }
18
+ emplace(file, realistic, instance) {
19
+ if (file.substr(-5) === ".d.ts")
20
+ file = file.substr(0, file.length - 5);
21
+ else if (file.substr(-3) === ".ts")
22
+ file = file.substr(0, file.length - 3);
23
+ else
24
+ throw new Error(`Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`);
25
+ const pair = this.dict_.take(file, () => new Pair_1.Pair(realistic, new HashSet_1.HashSet()));
26
+ pair.second.insert(instance);
27
+ }
28
+ toScript(outDir) {
29
+ const statements = [];
30
+ for (const it of this.dict_) {
31
+ const file = (() => {
32
+ const location = path_1.default
33
+ .relative(outDir, it.first)
34
+ .split("\\")
35
+ .join("/");
36
+ const index = location.lastIndexOf(NODE_MODULES);
37
+ return index === -1
38
+ ? `./${location}`
39
+ : location.substring(index + NODE_MODULES.length);
40
+ })();
41
+ const realistic = it.second.first;
42
+ const instances = it.second.second.toJSON();
43
+ statements.push(`import ${!realistic ? "type " : ""}{ ${instances.join(", ")} } from "${file}";`);
44
+ }
45
+ return statements.join("\n");
46
+ }
47
+ }
48
+ exports.ImportDictionary = ImportDictionary;
49
+ const NODE_MODULES = "node_modules/";
50
+ //# sourceMappingURL=ImportDictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImportDictionary.js","sourceRoot":"","sources":["../../src/utils/ImportDictionary.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AACxB,oDAAiD;AACjD,oDAAiD;AACjD,4CAAyC;AAEzC,MAAa,gBAAgB;IAA7B;QACqB,UAAK,GAClB,IAAI,iBAAO,EAAE,CAAC;IA8CtB,CAAC;IA5CU,KAAK;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;IAEM,OAAO,CAAC,IAAY,EAAE,SAAkB,EAAE,QAAgB;QAC7D,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,OAAO;YAAE,IAAI,GAAG,IAAI,CAAC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,EAAE,CAAC;YAEtD,UAAU,CAAC,IAAI,CACX,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,SAAS,CAAC,IAAI,CAClD,IAAI,CACP,YAAY,IAAI,IAAI,CACxB,CAAC;SACL;QACD,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;CACJ;AAhDD,4CAgDC;AAED,MAAM,YAAY,GAAG,eAAe,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare namespace MapUtil {
2
+ function take<Key, T>(dict: Map<Key, T>, key: Key, generator: () => T): T;
3
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MapUtil = void 0;
4
+ var MapUtil;
5
+ (function (MapUtil) {
6
+ function take(dict, key, generator) {
7
+ const oldbie = dict.get(key);
8
+ if (oldbie)
9
+ return oldbie;
10
+ const value = generator();
11
+ dict.set(key, value);
12
+ return value;
13
+ }
14
+ MapUtil.take = take;
15
+ })(MapUtil = exports.MapUtil || (exports.MapUtil = {}));
16
+ //# sourceMappingURL=MapUtil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapUtil.js","sourceRoot":"","sources":["../../src/utils/MapUtil.ts"],"names":[],"mappings":";;;AAAA,IAAiB,OAAO,CAavB;AAbD,WAAiB,OAAO;IACpB,SAAgB,IAAI,CAChB,IAAiB,EACjB,GAAQ,EACR,SAAkB;QAElB,MAAM,MAAM,GAAkB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAC;QAE1B,MAAM,KAAK,GAAM,SAAS,EAAE,CAAC;QAC7B,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC;IACjB,CAAC;IAXe,YAAI,OAWnB,CAAA;AACL,CAAC,EAbgB,OAAO,GAAP,eAAO,KAAP,eAAO,QAavB"}
@@ -0,0 +1,3 @@
1
+ export type StripEnums<T extends Record<string, any>> = {
2
+ [Key in keyof T]: T[Key] extends string | boolean | object | undefined | any[] ? T[Key] : any;
3
+ };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=StripEnums.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StripEnums.js","sourceRoot":"","sources":["../../src/utils/StripEnums.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,74 @@
1
+ {
2
+ "name": "@nestia/sdk",
3
+ "version": "0.1.0",
4
+ "description": "Nestia SDK and Swagger generator",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "bin": {
8
+ "@nestia/sdk": "lib/executable/sdk.js"
9
+ },
10
+ "scripts": {
11
+ "build": "rimraf lib && ttsc",
12
+ "dev": "rimraf lib && ttsc --watch",
13
+ "prettier": "prettier --write ./**/*.ts",
14
+ "test": "node lib/test"
15
+ },
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/samchon/nestia"
19
+ },
20
+ "keywords": [
21
+ "nestia",
22
+ "sdk",
23
+ "swagger",
24
+ "generator",
25
+ "nestjs",
26
+ "typia"
27
+ ],
28
+ "author": "Jeongho Nam",
29
+ "license": "MIT",
30
+ "bugs": {
31
+ "url": "https://github.com/samchon/nestia/issues"
32
+ },
33
+ "homepage": "https://github.com/samchon/nestia",
34
+ "devDependencies": {
35
+ "@nestia/core": "^0.1.5",
36
+ "@nestia/fetcher": "^0.1.0",
37
+ "@trivago/prettier-plugin-sort-imports": "^4.0.0",
38
+ "@types/cli": "^0.11.21",
39
+ "@types/express": "^4.17.15",
40
+ "@types/glob": "^7.2.0",
41
+ "@types/node": "^18.11.15",
42
+ "@types/reflect-metadata": "^0.1.0",
43
+ "@types/uuid": "^9.0.0",
44
+ "@typescript-eslint/eslint-plugin": "^5.46.1",
45
+ "@typescript-eslint/parser": "^5.46.1",
46
+ "eslint": "^8.29.0",
47
+ "prettier": "^2.8.1",
48
+ "rimraf": "^3.0.2",
49
+ "ts-node": "^10.9.1",
50
+ "ttypescript": "^1.5.15",
51
+ "typescript": "^4.9.4",
52
+ "typescript-transform-paths": "^3.4.4",
53
+ "uuid": "^9.0.0"
54
+ },
55
+ "dependencies": {
56
+ "cli": "^1.0.1",
57
+ "glob": "^7.2.0",
58
+ "path-to-regexp": "^6.2.1",
59
+ "tgrid": "^0.8.7",
60
+ "tsconfck": "^2.0.1",
61
+ "tsconfig-paths": "^4.1.1",
62
+ "tstl": "^2.5.13",
63
+ "typia": "^3.4.7"
64
+ },
65
+ "files": [
66
+ "assets",
67
+ "lib",
68
+ "src",
69
+ "!src/test",
70
+ "README.md",
71
+ "LICENSE",
72
+ "package.json"
73
+ ]
74
+ }
@@ -0,0 +1,120 @@
1
+ import ts from "typescript";
2
+
3
+ import type { StripEnums } from "./utils/StripEnums";
4
+
5
+ /**
6
+ * Definition for the `nestia.config.ts` file.
7
+ *
8
+ * @author Jeongho Nam - https://github.com/samchon
9
+ */
10
+ export interface INestiaConfig {
11
+ /**
12
+ * List of files or directories containing the NestJS controller classes.
13
+ */
14
+ input: string | string[] | INestiaConfig.IInput;
15
+
16
+ /**
17
+ * Output directory that SDK would be placed in.
18
+ *
19
+ * If not configured, you can't build the SDK library.
20
+ */
21
+ output?: string;
22
+
23
+ /**
24
+ * Compiler options for the TypeScript.
25
+ *
26
+ * If you've omitted this property or the assigned property cannot fully cover the
27
+ * `tsconfig.json`, the properties from the `tsconfig.json` would be assigned to here.
28
+ * Otherwise, this property has been configured and it's detailed values are different
29
+ * with the `tsconfig.json`, this property values would be used instead.
30
+ *
31
+ * ```typescript
32
+ * import ts from "typescript";
33
+ *
34
+ * const tsconfig: ts.TsConfig;
35
+ * const nestiaConfig: IConfiguration;
36
+ *
37
+ * const compilerOptions: ts.CompilerOptions = {
38
+ * ...tsconfig.compilerOptions,
39
+ * ...(nestiaConfig.compilerOptions || {})
40
+ * }
41
+ * ```
42
+ */
43
+ compilerOptions?: StripEnums<ts.CompilerOptions>;
44
+
45
+ /**
46
+ * Whether to assert parameter types or not.
47
+ *
48
+ * If you configure this property to be `true`, all of the function parameters would be
49
+ * checked through the [typia](https://github.com/samchon/typia#runtime-type-checkers).
50
+ * This option would make your SDK library slower, but would enahcne the type safety even
51
+ * in the runtime level.
52
+ *
53
+ * @default false
54
+ */
55
+ assert?: boolean;
56
+
57
+ /**
58
+ * Whether to optimize JSON string conversion 2x faster or not.
59
+ *
60
+ * If you configure this property to be `true`, the SDK library would utilize the
61
+ * [typia](https://github.com/samchon/typia#fastest-json-string-converter)
62
+ * and the JSON string conversion speed really be 2x faster.
63
+ *
64
+ * @default false
65
+ */
66
+ json?: boolean;
67
+
68
+ /**
69
+ * Whether to wrap DTO by primitive type.
70
+ *
71
+ * If you don't configure this property as `false`, all of DTOs in the
72
+ * SDK library would be automatically wrapped by {@link Primitive} type.
73
+ *
74
+ * For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
75
+ * all of methods in the DTO type would be automatically erased. Also, if
76
+ * the DTO has a `toJSON()` method, the DTO type would be automatically
77
+ * converted to return type of the `toJSON()` method.
78
+ *
79
+ * @default true
80
+ */
81
+ primitive?: boolean;
82
+
83
+ /**
84
+ * Building `swagger.json` is also possible.
85
+ *
86
+ * If not specified, you can't build the `swagger.json`.
87
+ */
88
+ swagger?: INestiaConfig.ISwagger;
89
+ }
90
+ export namespace INestiaConfig {
91
+ /**
92
+ * List of files or directories to include or exclude to specifying the NestJS
93
+ * controllers.
94
+ */
95
+ export interface IInput {
96
+ /**
97
+ * List of files or directories containing the NestJS controller classes.
98
+ */
99
+ include: string[];
100
+
101
+ /**
102
+ * List of files or directories to be excluded.
103
+ */
104
+ exclude?: string[];
105
+ }
106
+
107
+ /**
108
+ * Building `swagger.json` is also possible.
109
+ */
110
+ export interface ISwagger {
111
+ /**
112
+ * Output path of the `swagger.json`.
113
+ *
114
+ * If you've configured only directory, the file name would be the `swagger.json`.
115
+ * Otherwise you've configured the full path with file name and extension, the
116
+ * `swagger.json` file would be renamed to it.
117
+ */
118
+ output: string;
119
+ }
120
+ }
@@ -0,0 +1,183 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import * as runner from "ts-node";
4
+ import { Singleton } from "tstl/thread/Singleton";
5
+ import { Pair } from "tstl/utility/Pair";
6
+ import ts from "typescript";
7
+
8
+ import { INestiaConfig } from "./INestiaConfig";
9
+ import { ControllerAnalyzer } from "./analyses/ControllerAnalyzer";
10
+ import { ReflectAnalyzer } from "./analyses/ReflectAnalyzer";
11
+ import { SourceFinder } from "./analyses/SourceFinder";
12
+ import { NestiaConfigCompilerOptions } from "./executable/internal/NestiaConfigCompilerOptions";
13
+ import { SdkGenerator } from "./generates/SdkGenerator";
14
+ import { SwaggerGenerator } from "./generates/SwaggerGenerator";
15
+ import { IController } from "./structures/IController";
16
+ import { IRoute } from "./structures/IRoute";
17
+ import { ArrayUtil } from "./utils/ArrayUtil";
18
+
19
+ export class NestiaSdkApplication {
20
+ private readonly config_: INestiaConfig;
21
+ private readonly bundle_checker_: Singleton<
22
+ Promise<(str: string) => boolean>
23
+ >;
24
+
25
+ public constructor(config: INestiaConfig) {
26
+ this.config_ = config;
27
+ this.bundle_checker_ = new Singleton(async () => {
28
+ if (!this.config_.output) return () => false;
29
+
30
+ const bundles: string[] = await fs.promises.readdir(
31
+ SdkGenerator.BUNDLE_PATH,
32
+ );
33
+ const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
34
+ bundles,
35
+ async (file) => {
36
+ const relative: string = path.join(
37
+ this.config_.output!,
38
+ file,
39
+ );
40
+ const location: string = path.join(
41
+ SdkGenerator.BUNDLE_PATH,
42
+ file,
43
+ );
44
+ const stats: fs.Stats = await fs.promises.stat(location);
45
+
46
+ return new Pair(relative, stats.isDirectory());
47
+ },
48
+ );
49
+
50
+ return (file: string): boolean => {
51
+ for (const it of tuples)
52
+ if (it.second === false && file === it.first) return true;
53
+ else if (it.second === true && file.indexOf(it.first) === 0)
54
+ return true;
55
+ return false;
56
+ };
57
+ });
58
+ }
59
+
60
+ public async sdk(): Promise<void> {
61
+ if (!this.config_.output)
62
+ throw new Error(
63
+ "Error on NestiaApplication.sdk(): output path is not specified.",
64
+ );
65
+
66
+ const parent: string = path.resolve(this.config_.output + "/..");
67
+ const stats: fs.Stats = await fs.promises.lstat(parent);
68
+ if (stats.isDirectory() === false)
69
+ throw new Error(
70
+ "Error on NestiaApplication.sdk(): output directory does not exists.",
71
+ );
72
+
73
+ await this.generate((config) => config, SdkGenerator.generate);
74
+ }
75
+
76
+ public async swagger(): Promise<void> {
77
+ if (!this.config_.swagger || !this.config_.swagger.output)
78
+ throw new Error(
79
+ `Error on NestiaApplication.swagger(): output path of the "swagger.json" is not specified.`,
80
+ );
81
+
82
+ const parsed: path.ParsedPath = path.parse(this.config_.swagger.output);
83
+ const directory: string = !!parsed.ext
84
+ ? path.resolve(parsed.dir)
85
+ : this.config_.swagger.output;
86
+ const stats: fs.Stats = await fs.promises.lstat(directory);
87
+ if (stats.isDirectory() === false)
88
+ throw new Error(
89
+ "Error on NestiaApplication.swagger(): output directory does not exists.",
90
+ );
91
+
92
+ await this.generate(
93
+ (config) => config.swagger!,
94
+ SwaggerGenerator.generate,
95
+ );
96
+ }
97
+
98
+ private async generate<Config>(
99
+ config: (entire: INestiaConfig) => Config,
100
+ archiver: (
101
+ checker: ts.TypeChecker,
102
+ config: Config,
103
+ routes: IRoute[],
104
+ ) => Promise<void>,
105
+ ): Promise<void> {
106
+ // MOUNT TS-NODE
107
+ this.prepare();
108
+
109
+ // LOAD CONTROLLER FILES
110
+ const input: INestiaConfig.IInput =
111
+ this.config_.input instanceof Array
112
+ ? { include: this.config_.input }
113
+ : typeof this.config_.input === "string"
114
+ ? { include: [this.config_.input] }
115
+ : this.config_.input;
116
+ const fileList: string[] = await ArrayUtil.asyncFilter(
117
+ await SourceFinder.find(input),
118
+ (file) => this.is_not_excluded(file),
119
+ );
120
+
121
+ // ANALYZE REFLECTS
122
+ const unique: WeakSet<any> = new WeakSet();
123
+ const controllerList: IController[] = [];
124
+
125
+ for (const file of fileList)
126
+ controllerList.push(
127
+ ...(await ReflectAnalyzer.analyze(unique, file)),
128
+ );
129
+
130
+ // ANALYZE TYPESCRIPT CODE
131
+ const program: ts.Program = ts.createProgram(
132
+ controllerList.map((c) => c.file),
133
+ this.config_.compilerOptions || { noEmit: true },
134
+ );
135
+ const checker: ts.TypeChecker = program.getTypeChecker();
136
+
137
+ const routeList: IRoute[] = [];
138
+ for (const controller of controllerList) {
139
+ const sourceFile: ts.SourceFile | undefined = program.getSourceFile(
140
+ controller.file,
141
+ );
142
+ if (sourceFile === undefined) continue;
143
+
144
+ routeList.push(
145
+ ...ControllerAnalyzer.analyze(checker, sourceFile, controller),
146
+ );
147
+ }
148
+
149
+ // DO GENERATE
150
+ await archiver(checker, config(this.config_), routeList);
151
+ }
152
+
153
+ private prepare(): void {
154
+ // CONSTRUCT OPTIONS
155
+ if (!this.config_.compilerOptions)
156
+ this.config_.compilerOptions =
157
+ NestiaConfigCompilerOptions.DEFAULT_OPTIONS as any;
158
+ const absoluted: boolean = !!this.config_.compilerOptions?.baseUrl;
159
+
160
+ // MOUNT TS-NODE
161
+ runner.register({
162
+ emit: false,
163
+ compiler: "ttypescript",
164
+ compilerOptions: this.config_.compilerOptions,
165
+ require: absoluted ? ["tsconfig-paths/register"] : undefined,
166
+ });
167
+ }
168
+
169
+ private async is_not_excluded(file: string): Promise<boolean> {
170
+ if (this.config_.output)
171
+ return (
172
+ file.indexOf(path.join(this.config_.output, "functional")) ===
173
+ -1 && (await this.bundle_checker_.get())(file) === false
174
+ );
175
+
176
+ const content: string = await fs.promises.readFile(file, "utf8");
177
+ return (
178
+ content.indexOf(
179
+ " * @nestia Generated by Nestia - https://github.com/samchon/nestia",
180
+ ) === -1
181
+ );
182
+ }
183
+ }