@nestia/sdk 2.0.0-dev.20230903 → 2.0.0-dev.20230904

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 (38) hide show
  1. package/lib/INestiaConfig.d.ts +8 -23
  2. package/lib/NestiaSdkApplication.d.ts +6 -5
  3. package/lib/NestiaSdkApplication.js +27 -84
  4. package/lib/NestiaSdkApplication.js.map +1 -1
  5. package/lib/analyses/ControllerAnalyzer.js +1 -1
  6. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  7. package/lib/executable/internal/NestiaConfigLoader.d.ts +7 -0
  8. package/lib/executable/internal/NestiaConfigLoader.js +574 -0
  9. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -0
  10. package/lib/executable/internal/NestiaProjectGetter.d.ts +3 -0
  11. package/lib/executable/internal/NestiaProjectGetter.js +28 -0
  12. package/lib/executable/internal/NestiaProjectGetter.js.map +1 -0
  13. package/lib/executable/internal/NestiaSdkCommand.d.ts +3 -3
  14. package/lib/executable/internal/NestiaSdkCommand.js +13 -104
  15. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  16. package/lib/executable/internal/{nestia.config.getter.js → nestia.project.getter.js} +3 -3
  17. package/lib/executable/internal/nestia.project.getter.js.map +1 -0
  18. package/lib/executable/sdk.js +3 -3
  19. package/lib/executable/sdk.js.map +1 -1
  20. package/package.json +3 -3
  21. package/src/INestiaConfig.ts +9 -25
  22. package/src/NestiaSdkApplication.ts +36 -77
  23. package/src/analyses/ControllerAnalyzer.ts +1 -1
  24. package/src/executable/internal/NestiaConfigLoader.ts +82 -0
  25. package/src/executable/internal/NestiaProjectGetter.ts +11 -0
  26. package/src/executable/internal/NestiaSdkCommand.ts +23 -146
  27. package/src/executable/internal/{nestia.config.getter.ts → nestia.project.getter.ts} +2 -2
  28. package/src/executable/sdk.ts +3 -3
  29. package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +0 -12
  30. package/lib/executable/internal/NestiaConfigCompilerOptions.js +0 -18
  31. package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +0 -1
  32. package/lib/executable/internal/NestiaSdkConfig.d.ts +0 -4
  33. package/lib/executable/internal/NestiaSdkConfig.js +0 -1019
  34. package/lib/executable/internal/NestiaSdkConfig.js.map +0 -1
  35. package/lib/executable/internal/nestia.config.getter.js.map +0 -1
  36. package/src/executable/internal/NestiaConfigCompilerOptions.ts +0 -19
  37. package/src/executable/internal/NestiaSdkConfig.ts +0 -36
  38. /package/lib/executable/internal/{nestia.config.getter.d.ts → nestia.project.getter.d.ts} +0 -0
@@ -1,157 +1,34 @@
1
- import cli from "cli";
2
- import path from "path";
3
- import { WorkerConnector } from "tgrid/protocols/workers/WorkerConnector";
4
- import { parseNative } from "tsconfck";
5
1
  import ts from "typescript";
6
2
 
7
3
  import { INestiaConfig } from "../../INestiaConfig";
8
4
  import { NestiaSdkApplication } from "../../NestiaSdkApplication";
9
- import { NestiaSdkConfig } from "./NestiaSdkConfig";
10
-
11
- interface ICommand {
12
- exclude: string | null;
13
- out: string | null;
14
- e2e: string | null;
15
- }
16
-
17
- interface IProps {
18
- assign: (config: INestiaConfig, output: string) => void;
19
- validate: (config: INestiaConfig) => boolean;
20
- location: (config: INestiaConfig) => string;
21
- }
5
+ import { NestiaConfigLoader } from "./NestiaConfigLoader";
22
6
 
23
7
  export namespace NestiaSdkCommand {
24
- export const sdk = (argv: string[]) =>
25
- main({
26
- assign: (config, output) => (config.output = output),
27
- validate: (config) => !!config.output,
28
- location: (config) => config.output!,
29
- })(argv)((app) => app.sdk());
30
-
31
- export const swagger = (argv: string[]) =>
32
- main({
33
- assign: (config, output) => {
34
- if (!config.swagger) config.swagger = { output };
35
- else config.swagger.output = output;
36
- },
37
- validate: (config) => !!config.swagger && !!config.swagger.output,
38
- location: (config) => config.swagger!.output!,
39
- })(argv)((app) => app.swagger());
40
-
41
- export const e2e = (argv: string[]) =>
42
- main({
43
- assign: (config, output) => (config.output = output),
44
- validate: (config) => !!config.output,
45
- location: (config) => config.output!,
46
- })(argv)((app) => app.e2e());
47
-
48
- const main =
49
- (props: IProps) =>
50
- (argv: string[]) =>
51
- async (task: (app: NestiaSdkApplication) => Promise<void>) => {
52
- const command: ICommand = cli.parse({
53
- exclude: ["e", "Something to exclude", "string", null],
54
- out: ["o", "Output path of the SDK files", "string", null],
55
- e2e: [
56
- "e",
57
- "Output path of e2e test function files",
58
- "string",
59
- null,
60
- ],
61
- });
62
-
63
- const inputs: string[] = [];
64
- for (const r of argv) {
65
- if (r[0] === "-") break;
66
- inputs.push(r);
67
- }
68
- await generate(props)(command)(inputs)(task);
69
- };
70
-
71
- const generate =
72
- (props: IProps) =>
73
- (command: ICommand) =>
74
- (include: string[]) =>
75
- async (task: (app: NestiaSdkApplication) => Promise<void>) => {
76
- // CONFIGURATION
77
- const config: INestiaConfig =
78
- (await get_nestia_config(props.validate)) ??
79
- parse_cli(props)(command)(include);
80
-
81
- const options: ts.CompilerOptions | null =
82
- await get_typescript_options();
83
- config.compilerOptions = {
84
- ...(options ?? {}),
85
- ...(config.compilerOptions ?? {}),
86
- };
87
-
88
- // CALL THE APP.GENERATE()
89
- const app: NestiaSdkApplication = new NestiaSdkApplication(config);
90
- await task(app);
91
- };
92
-
93
- async function get_typescript_options(): Promise<ts.CompilerOptions | null> {
94
- const configFileName = ts.findConfigFile(
95
- process.cwd(),
96
- ts.sys.fileExists,
97
- "tsconfig.json",
8
+ export const sdk = () => main((app) => app.sdk());
9
+ export const swagger = () => main((app) => app.swagger());
10
+ export const e2e = () => main((app) => app.e2e());
11
+
12
+ const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
13
+ await generate(task);
14
+ };
15
+
16
+ const generate = async (
17
+ task: (app: NestiaSdkApplication) => Promise<void>,
18
+ ) => {
19
+ // LOAD CONFIG INFO
20
+ const project: string = await NestiaConfigLoader.project();
21
+ const compilerOptions: ts.CompilerOptions =
22
+ await NestiaConfigLoader.compilerOptions(project);
23
+ const config: INestiaConfig = await NestiaConfigLoader.config(
24
+ compilerOptions,
98
25
  );
99
- if (!configFileName) return null;
100
26
 
101
- const { tsconfig } = await parseNative(configFileName);
102
- const configFileText = JSON.stringify(tsconfig);
103
- const { config } = ts.parseConfigFileTextToJson(
104
- configFileName,
105
- configFileText,
106
- );
107
- const configParseResult = ts.parseJsonConfigFileContent(
27
+ // GENERATE
28
+ const app: NestiaSdkApplication = new NestiaSdkApplication(
108
29
  config,
109
- ts.sys,
110
- path.dirname(configFileName),
111
- );
112
-
113
- const { moduleResolution, ...result } =
114
- configParseResult.raw.compilerOptions;
115
- return result;
116
- }
117
-
118
- async function get_nestia_config(
119
- validate: (config: INestiaConfig) => boolean,
120
- ): Promise<INestiaConfig | null> {
121
- const connector = new WorkerConnector(null, null, "process");
122
- await connector.connect(
123
- `${__dirname}/nestia.config.getter.${__filename.substr(-2)}`,
30
+ compilerOptions,
124
31
  );
125
-
126
- const driver = await connector.getDriver<typeof NestiaSdkConfig>();
127
- const config: INestiaConfig | null = await driver.get();
128
- await connector.close();
129
-
130
- if (config !== null && validate(config) === false)
131
- throw new Error(
132
- `Error on NestiaCommand.main(): output path is not specified in the "nestia.config.ts".`,
133
- );
134
-
135
- return config;
136
- }
137
-
138
- const parse_cli =
139
- (props: IProps) =>
140
- (command: ICommand) =>
141
- (include: string[]): INestiaConfig => {
142
- if (command.out === null)
143
- throw new Error(
144
- `Error on NestiaCommand.main(): output directory is not specified. Add the "--out <output_directory>" option.`,
145
- );
146
-
147
- const config: INestiaConfig = {
148
- input: {
149
- include,
150
- exclude: command.exclude ? [command.exclude] : undefined,
151
- },
152
- e2e: command.e2e ?? undefined,
153
- };
154
- props.assign(config, command.out);
155
- return config;
156
- };
32
+ await task(app);
33
+ };
157
34
  }
@@ -1,10 +1,10 @@
1
1
  import { WorkerServer } from "tgrid/protocols/workers/WorkerServer";
2
2
 
3
- import { NestiaSdkConfig } from "./NestiaSdkConfig";
3
+ import { NestiaProjectGetter } from "./NestiaProjectGetter";
4
4
 
5
5
  async function main(): Promise<void> {
6
6
  const worker = new WorkerServer();
7
- await worker.open(NestiaSdkConfig);
7
+ await worker.open(NestiaProjectGetter);
8
8
  }
9
9
  main().catch((exp) => {
10
10
  console.log(exp);
@@ -59,9 +59,9 @@ async function main() {
59
59
 
60
60
  if (type === "dependencies") dependencies(argv);
61
61
  else if (type === "init") await initialize();
62
- else if (type === "sdk") await execute((c) => c.sdk(argv));
63
- else if (type === "swagger") await execute((c) => c.swagger(argv));
64
- else if (type === "e2e") await execute((c) => c.e2e(argv));
62
+ else if (type === "sdk") await execute((c) => c.sdk());
63
+ else if (type === "swagger") await execute((c) => c.swagger());
64
+ else if (type === "e2e") await execute((c) => c.e2e());
65
65
  else halt(USAGE);
66
66
  }
67
67
  main().catch((exp) => {
@@ -1,12 +0,0 @@
1
- export declare namespace NestiaConfigCompilerOptions {
2
- const DEFAULT_OPTIONS: {
3
- target: string;
4
- module: string;
5
- strictNullChecks: boolean;
6
- types: string[];
7
- noEmit: boolean;
8
- esModuleInterop: boolean;
9
- experimentalDecorators: boolean;
10
- emitDecoratorMetadata: boolean;
11
- };
12
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NestiaConfigCompilerOptions = void 0;
4
- var NestiaConfigCompilerOptions;
5
- (function (NestiaConfigCompilerOptions) {
6
- /* -----------------------------------------------------------
7
- DEFAULT VALUES
8
- ----------------------------------------------------------- */
9
- const ESSENTIAL_OPTIONS = {
10
- types: ["node", "reflect-metadata"],
11
- noEmit: true,
12
- esModuleInterop: true,
13
- experimentalDecorators: true,
14
- emitDecoratorMetadata: true,
15
- };
16
- NestiaConfigCompilerOptions.DEFAULT_OPTIONS = Object.assign(Object.assign({}, ESSENTIAL_OPTIONS), { target: "es5", module: "commonjs", strictNullChecks: true });
17
- })(NestiaConfigCompilerOptions || (exports.NestiaConfigCompilerOptions = NestiaConfigCompilerOptions = {}));
18
- //# sourceMappingURL=NestiaConfigCompilerOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NestiaConfigCompilerOptions.js","sourceRoot":"","sources":["../../../src/executable/internal/NestiaConfigCompilerOptions.ts"],"names":[],"mappings":";;;AAAA,IAAiB,2BAA2B,CAkB3C;AAlBD,WAAiB,2BAA2B;IACxC;;kEAE8D;IAC9D,MAAM,iBAAiB,GAAG;QACtB,KAAK,EAAE,CAAC,MAAM,EAAE,kBAAkB,CAAC;QACnC,MAAM,EAAE,IAAI;QACZ,eAAe,EAAE,IAAI;QACrB,sBAAsB,EAAE,IAAI;QAC5B,qBAAqB,EAAE,IAAI;KAC9B,CAAC;IAEW,2CAAe,mCACrB,iBAAiB,KACpB,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,UAAU,EAClB,gBAAgB,EAAE,IAAI,GACzB,CAAC;AACN,CAAC,EAlBgB,2BAA2B,2CAA3B,2BAA2B,QAkB3C"}
@@ -1,4 +0,0 @@
1
- import { INestiaConfig } from "../../INestiaConfig";
2
- export declare namespace NestiaSdkConfig {
3
- function get(): Promise<INestiaConfig | null>;
4
- }