@nestia/sdk 1.3.8 → 1.3.10

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 (56) hide show
  1. package/assets/bundle/api/utils/NestiaSimulator.ts +4 -4
  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/sdk.js +11 -11
  15. package/lib/generates/SdkGenerator.js +28 -0
  16. package/lib/generates/SdkGenerator.js.map +1 -1
  17. package/lib/generates/SwaggerGenerator.js +9 -9
  18. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  19. package/lib/generates/internal/SdkSimulationProgrammer.js +15 -14
  20. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  21. package/lib/structures/IRoute.d.ts +1 -0
  22. package/package.json +2 -2
  23. package/src/NestiaSdkApplication.ts +273 -262
  24. package/src/analyses/ControllerAnalyzer.ts +266 -261
  25. package/src/analyses/GenericAnalyzer.ts +53 -53
  26. package/src/analyses/ImportAnalyzer.ts +158 -164
  27. package/src/analyses/PathAnalyzer.ts +58 -58
  28. package/src/analyses/ReflectAnalyzer.ts +321 -321
  29. package/src/executable/internal/CommandParser.ts +15 -15
  30. package/src/executable/internal/NestiaConfigCompilerOptions.ts +19 -18
  31. package/src/executable/internal/NestiaSdkCommand.ts +157 -156
  32. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  33. package/src/executable/internal/nestia.config.getter.ts +12 -12
  34. package/src/executable/sdk.ts +70 -70
  35. package/src/generates/E2eGenerator.ts +67 -67
  36. package/src/generates/SdkGenerator.ts +94 -65
  37. package/src/generates/SwaggerGenerator.ts +504 -504
  38. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  39. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  40. package/src/generates/internal/SdkSimulationProgrammer.ts +19 -19
  41. package/src/index.ts +4 -4
  42. package/src/module.ts +2 -2
  43. package/src/structures/IController.ts +31 -31
  44. package/src/structures/IRoute.ts +40 -39
  45. package/src/structures/ISwaggerDocument.ts +120 -120
  46. package/src/structures/ITypeTuple.ts +6 -6
  47. package/src/structures/MethodType.ts +11 -11
  48. package/src/structures/ParamCategory.ts +1 -1
  49. package/src/structures/TypeEntry.ts +22 -22
  50. package/src/utils/ArrayUtil.ts +26 -26
  51. package/src/utils/FileRetriever.ts +22 -22
  52. package/src/utils/ImportDictionary.ts +56 -56
  53. package/src/utils/MapUtil.ts +14 -14
  54. package/src/utils/NestiaConfigUtil.ts +21 -21
  55. package/src/utils/SourceFinder.ts +60 -60
  56. 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,94 @@
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 (config.random && routes.some((r) => !!r.parameters.length)) {
52
+ try {
53
+ await fs.promises.mkdir(`${config.output}/utils`);
54
+ } catch {}
55
+ await fs.promises.copyFile(
56
+ `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
57
+ `${config.output}/utils/NestiaSimulator.ts`,
58
+ );
59
+ }
60
+
61
+ // FUNCTIONAL
62
+ await SdkFileProgrammer.generate(config)(routes);
63
+
64
+ // DISTRIBUTION
65
+ if (config.distribute !== undefined)
66
+ await DistributionComposer.compose(config);
67
+ };
68
+
69
+ export const BUNDLE_PATH = NodePath.join(
70
+ __dirname,
71
+ "..",
72
+ "..",
73
+ "assets",
74
+ "bundle",
75
+ "api",
76
+ );
77
+ }
78
+
79
+ const is_implicit_return_typed = (route: IRoute): boolean => {
80
+ const name: string = route.output.name;
81
+ if (name === "void") return false;
82
+ else if (name.indexOf("readonly [") !== -1) return true;
83
+
84
+ const pos: number = name.indexOf("__object");
85
+ if (pos === -1) return false;
86
+
87
+ const before: number = pos - 1;
88
+ const after: number = pos + "__object".length;
89
+ for (const i of [before, after])
90
+ if (name[i] === undefined) continue;
91
+ else if (VARIABLE.test(name[i])) return false;
92
+ return true;
93
+ };
94
+ const VARIABLE = /[a-zA-Z_$0-9]/;