@nestia/sdk 1.3.9 → 1.3.11

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 (68) hide show
  1. package/lib/INestiaConfig.d.ts +15 -6
  2. package/lib/NestiaSdkApplication.d.ts +1 -1
  3. package/lib/NestiaSdkApplication.js +15 -9
  4. package/lib/NestiaSdkApplication.js.map +1 -1
  5. package/lib/analyses/ControllerAnalyzer.js +3 -3
  6. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  7. package/lib/analyses/ImportAnalyzer.js +2 -6
  8. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  9. package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +1 -0
  10. package/lib/executable/internal/NestiaConfigCompilerOptions.js +1 -1
  11. package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +1 -1
  12. package/lib/executable/internal/NestiaSdkCommand.js +2 -2
  13. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  14. package/lib/executable/internal/NestiaSdkConfig.js +5 -1
  15. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  16. package/lib/executable/sdk.js +11 -11
  17. package/lib/generates/SdkGenerator.js +33 -3
  18. package/lib/generates/SdkGenerator.js.map +1 -1
  19. package/lib/generates/SwaggerGenerator.js +9 -9
  20. package/lib/generates/internal/DistributionComposer.js +7 -4
  21. package/lib/generates/internal/DistributionComposer.js.map +1 -1
  22. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  23. package/lib/generates/internal/SdkFileProgrammer.js +4 -3
  24. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  25. package/lib/generates/internal/SdkFunctionProgrammer.js +7 -4
  26. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  27. package/lib/generates/internal/SdkSimulationProgrammer.js +4 -4
  28. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  29. package/lib/structures/IRoute.d.ts +1 -0
  30. package/package.json +4 -5
  31. package/src/INestiaConfig.ts +16 -6
  32. package/src/NestiaSdkApplication.ts +273 -262
  33. package/src/analyses/ControllerAnalyzer.ts +266 -261
  34. package/src/analyses/GenericAnalyzer.ts +53 -53
  35. package/src/analyses/ImportAnalyzer.ts +158 -164
  36. package/src/analyses/PathAnalyzer.ts +58 -58
  37. package/src/analyses/ReflectAnalyzer.ts +321 -321
  38. package/src/executable/internal/CommandParser.ts +15 -15
  39. package/src/executable/internal/NestiaConfigCompilerOptions.ts +19 -18
  40. package/src/executable/internal/NestiaSdkCommand.ts +157 -156
  41. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  42. package/src/executable/internal/nestia.config.getter.ts +12 -12
  43. package/src/executable/sdk.ts +70 -70
  44. package/src/generates/E2eGenerator.ts +67 -67
  45. package/src/generates/SdkGenerator.ts +97 -65
  46. package/src/generates/SwaggerGenerator.ts +504 -504
  47. package/src/generates/internal/DistributionComposer.ts +3 -1
  48. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  49. package/src/generates/internal/SdkFileProgrammer.ts +2 -2
  50. package/src/generates/internal/SdkFunctionProgrammer.ts +6 -4
  51. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  52. package/src/generates/internal/SdkSimulationProgrammer.ts +4 -4
  53. package/src/index.ts +4 -4
  54. package/src/module.ts +2 -2
  55. package/src/structures/IController.ts +31 -31
  56. package/src/structures/IRoute.ts +40 -39
  57. package/src/structures/ISwaggerDocument.ts +120 -120
  58. package/src/structures/ITypeTuple.ts +6 -6
  59. package/src/structures/MethodType.ts +11 -11
  60. package/src/structures/ParamCategory.ts +1 -1
  61. package/src/structures/TypeEntry.ts +22 -22
  62. package/src/utils/ArrayUtil.ts +26 -26
  63. package/src/utils/FileRetriever.ts +22 -22
  64. package/src/utils/ImportDictionary.ts +56 -56
  65. package/src/utils/MapUtil.ts +14 -14
  66. package/src/utils/NestiaConfigUtil.ts +21 -21
  67. package/src/utils/SourceFinder.ts +60 -60
  68. package/src/utils/StripEnums.ts +10 -10
@@ -1,67 +1,67 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { INestiaConfig } from "../INestiaConfig";
5
- import { IRoute } from "../structures/IRoute";
6
- import { NestiaConfigUtil } from "../utils/NestiaConfigUtil";
7
- import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
-
9
- export namespace E2eGenerator {
10
- export const generate =
11
- (config: INestiaConfig) =>
12
- async (routeList: IRoute[]): Promise<void> => {
13
- console.log("Generating E2E Test Functions");
14
-
15
- // PREPARE DIRECTORIES
16
- const output: string = path.resolve(config.e2e!);
17
- await mkdir(output);
18
- await mkdir(path.join(output, "features"));
19
- await mkdir(path.join(output, "features", "api"));
20
- await mkdir(path.join(output, "features", "api", "automated"));
21
-
22
- // GENERATE TEST INDEX FILE
23
- await index(config)(path.join(config.e2e!, "index.ts"));
24
-
25
- // GENERATE EACH TEST FILES
26
- for (const route of routeList)
27
- await E2eFileProgrammer.generate(config)({
28
- api: path.resolve(config.output!),
29
- current: path.join(output, "features", "api", "automated"),
30
- })(route);
31
- };
32
-
33
- const index =
34
- (config: INestiaConfig) =>
35
- async (output: string): Promise<void> => {
36
- if (fs.existsSync(output)) return;
37
-
38
- const location: string = path.join(
39
- __dirname,
40
- "..",
41
- "..",
42
- "assets",
43
- "bundle",
44
- "e2e",
45
- "index.ts",
46
- );
47
- const content: string = await fs.promises.readFile(
48
- location,
49
- "utf8",
50
- );
51
-
52
- await fs.promises.writeFile(
53
- output,
54
- content.replace(
55
- "${input}",
56
- JSON.stringify(NestiaConfigUtil.input(config.input)),
57
- ),
58
- "utf8",
59
- );
60
- };
61
- }
62
-
63
- const mkdir = async (location: string): Promise<void> => {
64
- try {
65
- await fs.promises.mkdir(location);
66
- } catch {}
67
- };
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { INestiaConfig } from "../INestiaConfig";
5
+ import { IRoute } from "../structures/IRoute";
6
+ import { NestiaConfigUtil } from "../utils/NestiaConfigUtil";
7
+ import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
+
9
+ export namespace E2eGenerator {
10
+ export const generate =
11
+ (config: INestiaConfig) =>
12
+ async (routeList: IRoute[]): Promise<void> => {
13
+ console.log("Generating E2E Test Functions");
14
+
15
+ // PREPARE DIRECTORIES
16
+ const output: string = path.resolve(config.e2e!);
17
+ await mkdir(output);
18
+ await mkdir(path.join(output, "features"));
19
+ await mkdir(path.join(output, "features", "api"));
20
+ await mkdir(path.join(output, "features", "api", "automated"));
21
+
22
+ // GENERATE TEST INDEX FILE
23
+ await index(config)(path.join(config.e2e!, "index.ts"));
24
+
25
+ // GENERATE EACH TEST FILES
26
+ for (const route of routeList)
27
+ await E2eFileProgrammer.generate(config)({
28
+ api: path.resolve(config.output!),
29
+ current: path.join(output, "features", "api", "automated"),
30
+ })(route);
31
+ };
32
+
33
+ const index =
34
+ (config: INestiaConfig) =>
35
+ async (output: string): Promise<void> => {
36
+ if (fs.existsSync(output)) return;
37
+
38
+ const location: string = path.join(
39
+ __dirname,
40
+ "..",
41
+ "..",
42
+ "assets",
43
+ "bundle",
44
+ "e2e",
45
+ "index.ts",
46
+ );
47
+ const content: string = await fs.promises.readFile(
48
+ location,
49
+ "utf8",
50
+ );
51
+
52
+ await fs.promises.writeFile(
53
+ output,
54
+ content.replace(
55
+ "${input}",
56
+ JSON.stringify(NestiaConfigUtil.input(config.input)),
57
+ ),
58
+ "utf8",
59
+ );
60
+ };
61
+ }
62
+
63
+ const mkdir = async (location: string): Promise<void> => {
64
+ try {
65
+ await fs.promises.mkdir(location);
66
+ } catch {}
67
+ };
@@ -1,65 +1,97 @@
1
- import fs from "fs";
2
- import NodePath from "path";
3
-
4
- import { INestiaConfig } from "../INestiaConfig";
5
- import { IRoute } from "../structures/IRoute";
6
- import { DistributionComposer } from "./internal/DistributionComposer";
7
- import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
8
-
9
- export namespace SdkGenerator {
10
- export const generate =
11
- (config: INestiaConfig) =>
12
- async (routes: IRoute[]): Promise<void> => {
13
- console.log("Generating SDK Library");
14
-
15
- // PREPARE NEW DIRECTORIES
16
- try {
17
- await fs.promises.mkdir(config.output!);
18
- } catch {}
19
-
20
- // BUNDLING
21
- const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
22
- for (const file of bundle) {
23
- const current: string = `${BUNDLE_PATH}/${file}`;
24
- const stats: fs.Stats = await fs.promises.stat(current);
25
-
26
- if (stats.isFile() === true) {
27
- const content: string = await fs.promises.readFile(
28
- current,
29
- "utf8",
30
- );
31
- if (fs.existsSync(`${config.output}/${file}`) === false)
32
- await fs.promises.writeFile(
33
- `${config.output}/${file}`,
34
- content,
35
- "utf8",
36
- );
37
- }
38
- }
39
- if (config.random && routes.some((r) => !!r.parameters.length)) {
40
- try {
41
- await fs.promises.mkdir(`${config.output}/utils`);
42
- } catch {}
43
- await fs.promises.copyFile(
44
- `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
45
- `${config.output}/utils/NestiaSimulator.ts`,
46
- );
47
- }
48
-
49
- // FUNCTIONAL
50
- await SdkFileProgrammer.generate(config)(routes);
51
-
52
- // DISTRIBUTION
53
- if (config.distribute !== undefined)
54
- await DistributionComposer.compose(config);
55
- };
56
-
57
- export const BUNDLE_PATH = NodePath.join(
58
- __dirname,
59
- "..",
60
- "..",
61
- "assets",
62
- "bundle",
63
- "api",
64
- );
65
- }
1
+ import fs from "fs";
2
+ import NodePath from "path";
3
+
4
+ import { INestiaConfig } from "../INestiaConfig";
5
+ import { IRoute } from "../structures/IRoute";
6
+ import { DistributionComposer } from "./internal/DistributionComposer";
7
+ import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
8
+
9
+ export namespace SdkGenerator {
10
+ export const generate =
11
+ (config: INestiaConfig) =>
12
+ async (routes: IRoute[]): Promise<void> => {
13
+ console.log("Generating SDK Library");
14
+
15
+ // FIND IMPLICIT TYPES
16
+ const implicit: IRoute[] = routes.filter(is_implicit_return_typed);
17
+ if (implicit.length > 0)
18
+ throw new Error(
19
+ "NestiaApplication.sdk(): implicit return type is not allowed.\n" +
20
+ "\n" +
21
+ "List of implicit return typed routes:\n" +
22
+ implicit
23
+ .map((it) => ` - ${it.symbol} at "${it.location}"`)
24
+ .join("\n"),
25
+ );
26
+
27
+ // PREPARE NEW DIRECTORIES
28
+ try {
29
+ await fs.promises.mkdir(config.output!);
30
+ } catch {}
31
+
32
+ // BUNDLING
33
+ const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
34
+ for (const file of bundle) {
35
+ const current: string = `${BUNDLE_PATH}/${file}`;
36
+ const stats: fs.Stats = await fs.promises.stat(current);
37
+
38
+ if (stats.isFile() === true) {
39
+ const content: string = await fs.promises.readFile(
40
+ current,
41
+ "utf8",
42
+ );
43
+ if (fs.existsSync(`${config.output}/${file}`) === false)
44
+ await fs.promises.writeFile(
45
+ `${config.output}/${file}`,
46
+ content,
47
+ "utf8",
48
+ );
49
+ }
50
+ }
51
+ if (
52
+ (config.simulate ?? (config as any).random) === true &&
53
+ routes.some((r) => !!r.parameters.length)
54
+ ) {
55
+ try {
56
+ await fs.promises.mkdir(`${config.output}/utils`);
57
+ } catch {}
58
+ await fs.promises.copyFile(
59
+ `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
60
+ `${config.output}/utils/NestiaSimulator.ts`,
61
+ );
62
+ }
63
+
64
+ // FUNCTIONAL
65
+ await SdkFileProgrammer.generate(config)(routes);
66
+
67
+ // DISTRIBUTION
68
+ if (config.distribute !== undefined)
69
+ await DistributionComposer.compose(config);
70
+ };
71
+
72
+ export const BUNDLE_PATH = NodePath.join(
73
+ __dirname,
74
+ "..",
75
+ "..",
76
+ "assets",
77
+ "bundle",
78
+ "api",
79
+ );
80
+ }
81
+
82
+ const is_implicit_return_typed = (route: IRoute): boolean => {
83
+ const name: string = route.output.name;
84
+ if (name === "void") return false;
85
+ else if (name.indexOf("readonly [") !== -1) return true;
86
+
87
+ const pos: number = name.indexOf("__object");
88
+ if (pos === -1) return false;
89
+
90
+ const before: number = pos - 1;
91
+ const after: number = pos + "__object".length;
92
+ for (const i of [before, after])
93
+ if (name[i] === undefined) continue;
94
+ else if (VARIABLE.test(name[i])) return false;
95
+ return true;
96
+ };
97
+ const VARIABLE = /[a-zA-Z_$0-9]/;