@nestia/sdk 0.2.0 → 1.0.1

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/assets/config/nestia.config.ts +79 -70
  2. package/lib/INestiaConfig.d.ts +18 -14
  3. package/lib/executable/sdk.js +16 -16
  4. package/lib/generates/FunctionGenerator.js +9 -9
  5. package/lib/generates/FunctionGenerator.js.map +1 -1
  6. package/lib/generates/SwaggerGenerator.js +9 -9
  7. package/package.json +3 -3
  8. package/src/INestiaConfig.ts +124 -120
  9. package/src/NestiaSdkApplication.ts +183 -183
  10. package/src/analyses/ControllerAnalyzer.ts +203 -203
  11. package/src/analyses/GenericAnalyzer.ts +53 -53
  12. package/src/analyses/ImportAnalyzer.ts +143 -143
  13. package/src/analyses/PathAnalyzer.ts +58 -58
  14. package/src/analyses/ReflectAnalyzer.ts +279 -279
  15. package/src/analyses/SourceFinder.ts +59 -59
  16. package/src/executable/internal/CommandParser.ts +15 -15
  17. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  18. package/src/executable/internal/NestiaSdkCommand.ts +174 -174
  19. package/src/executable/internal/NestiaSdkConfig.ts +35 -35
  20. package/src/executable/internal/nestia.config.getter.ts +12 -12
  21. package/src/executable/sdk.ts +74 -74
  22. package/src/generates/FileGenerator.ts +156 -156
  23. package/src/generates/FunctionGenerator.ts +284 -287
  24. package/src/generates/SdkGenerator.ts +50 -50
  25. package/src/generates/SwaggerGenerator.ts +393 -393
  26. package/src/index.ts +3 -3
  27. package/src/module.ts +2 -2
  28. package/src/structures/IController.ts +27 -27
  29. package/src/structures/IRoute.ts +29 -29
  30. package/src/structures/ISwagger.ts +55 -55
  31. package/src/structures/ITypeTuple.ts +6 -6
  32. package/src/structures/MethodType.ts +11 -11
  33. package/src/structures/ParamCategory.ts +1 -1
  34. package/src/structures/TypeEntry.ts +22 -22
  35. package/src/utils/ArrayUtil.ts +26 -26
  36. package/src/utils/ImportDictionary.ts +56 -56
  37. package/src/utils/MapUtil.ts +14 -14
  38. package/src/utils/StripEnums.ts +10 -10
package/src/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- import * as nestia from "./module";
2
-
3
- export default nestia;
1
+ import * as nestia from "./module";
2
+
3
+ export default nestia;
package/src/module.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from "./INestiaConfig";
2
- export * from "./NestiaSdkApplication";
1
+ export * from "./INestiaConfig";
2
+ export * from "./NestiaSdkApplication";
@@ -1,27 +1,27 @@
1
- import { ParamCategory } from "./ParamCategory";
2
-
3
- export interface IController {
4
- file: string;
5
- name: string;
6
- paths: string[];
7
- functions: IController.IFunction[];
8
- }
9
-
10
- export namespace IController {
11
- export interface IFunction {
12
- name: string;
13
- method: string;
14
- paths: string[];
15
- encrypted: boolean;
16
-
17
- parameters: IParameter[];
18
- }
19
-
20
- export interface IParameter {
21
- name: string;
22
- index: number;
23
- field: string | undefined;
24
- category: ParamCategory;
25
- encrypted: boolean;
26
- }
27
- }
1
+ import { ParamCategory } from "./ParamCategory";
2
+
3
+ export interface IController {
4
+ file: string;
5
+ name: string;
6
+ paths: string[];
7
+ functions: IController.IFunction[];
8
+ }
9
+
10
+ export namespace IController {
11
+ export interface IFunction {
12
+ name: string;
13
+ method: string;
14
+ paths: string[];
15
+ encrypted: boolean;
16
+
17
+ parameters: IParameter[];
18
+ }
19
+
20
+ export interface IParameter {
21
+ name: string;
22
+ index: number;
23
+ field: string | undefined;
24
+ category: ParamCategory;
25
+ encrypted: boolean;
26
+ }
27
+ }
@@ -1,29 +1,29 @@
1
- import ts from "typescript";
2
-
3
- import { ITypeTuple } from "./ITypeTuple";
4
- import { ParamCategory } from "./ParamCategory";
5
-
6
- export interface IRoute {
7
- name: string;
8
- method: string;
9
- path: string;
10
- encrypted: boolean;
11
-
12
- parameters: IRoute.IParameter[];
13
- imports: [string, string[]][];
14
- output: ITypeTuple;
15
-
16
- symbol: string;
17
- comments: ts.SymbolDisplayPart[];
18
- tags: ts.JSDocTagInfo[];
19
- }
20
-
21
- export namespace IRoute {
22
- export interface IParameter {
23
- name: string;
24
- field: string | undefined;
25
- category: ParamCategory;
26
- encrypted: boolean;
27
- type: ITypeTuple;
28
- }
29
- }
1
+ import ts from "typescript";
2
+
3
+ import { ITypeTuple } from "./ITypeTuple";
4
+ import { ParamCategory } from "./ParamCategory";
5
+
6
+ export interface IRoute {
7
+ name: string;
8
+ method: string;
9
+ path: string;
10
+ encrypted: boolean;
11
+
12
+ parameters: IRoute.IParameter[];
13
+ imports: [string, string[]][];
14
+ output: ITypeTuple;
15
+
16
+ symbol: string;
17
+ comments: ts.SymbolDisplayPart[];
18
+ tags: ts.JSDocTagInfo[];
19
+ }
20
+
21
+ export namespace IRoute {
22
+ export interface IParameter {
23
+ name: string;
24
+ field: string | undefined;
25
+ category: ParamCategory;
26
+ encrypted: boolean;
27
+ type: ITypeTuple;
28
+ }
29
+ }
@@ -1,55 +1,55 @@
1
- import { IJsonComponents, IJsonSchema } from "typia";
2
-
3
- export interface ISwagger {
4
- openapi: "3.0";
5
- servers: ISwagger.IServer[];
6
- info: ISwagger.IInfo;
7
- paths: Record<string, ISwagger.IPath>;
8
- components: IJsonComponents;
9
- }
10
- export namespace ISwagger {
11
- export type IPath = Record<string, IRoute>;
12
- export interface IRoute {
13
- description: string;
14
- tags: string[];
15
- parameters: IParameter[];
16
- responses: IResponseBody;
17
- requestBody?: IRequestBody;
18
- summary?: string;
19
- }
20
-
21
- export interface IInfo {
22
- version: string;
23
- title: string;
24
- }
25
- export interface IParameter {
26
- name: string;
27
- in: string;
28
- schema: IJsonSchema;
29
- required: true;
30
- description: string;
31
- }
32
- export interface IRequestBody {
33
- description: string;
34
- content: IJsonContent;
35
- required: true;
36
- }
37
- export type IResponseBody = Record<
38
- string,
39
- {
40
- description: string;
41
- content?: IJsonContent;
42
- }
43
- >;
44
-
45
- export interface IServer {
46
- url: string;
47
- description?: string;
48
- }
49
-
50
- export interface IJsonContent {
51
- "application/json": {
52
- schema: IJsonSchema;
53
- };
54
- }
55
- }
1
+ import { IJsonComponents, IJsonSchema } from "typia";
2
+
3
+ export interface ISwagger {
4
+ openapi: "3.0";
5
+ servers: ISwagger.IServer[];
6
+ info: ISwagger.IInfo;
7
+ paths: Record<string, ISwagger.IPath>;
8
+ components: IJsonComponents;
9
+ }
10
+ export namespace ISwagger {
11
+ export type IPath = Record<string, IRoute>;
12
+ export interface IRoute {
13
+ description: string;
14
+ tags: string[];
15
+ parameters: IParameter[];
16
+ responses: IResponseBody;
17
+ requestBody?: IRequestBody;
18
+ summary?: string;
19
+ }
20
+
21
+ export interface IInfo {
22
+ version: string;
23
+ title: string;
24
+ }
25
+ export interface IParameter {
26
+ name: string;
27
+ in: string;
28
+ schema: IJsonSchema;
29
+ required: true;
30
+ description: string;
31
+ }
32
+ export interface IRequestBody {
33
+ description: string;
34
+ content: IJsonContent;
35
+ required: true;
36
+ }
37
+ export type IResponseBody = Record<
38
+ string,
39
+ {
40
+ description: string;
41
+ content?: IJsonContent;
42
+ }
43
+ >;
44
+
45
+ export interface IServer {
46
+ url: string;
47
+ description?: string;
48
+ }
49
+
50
+ export interface IJsonContent {
51
+ "application/json": {
52
+ schema: IJsonSchema;
53
+ };
54
+ }
55
+ }
@@ -1,6 +1,6 @@
1
- import ts from "typescript";
2
-
3
- export interface ITypeTuple {
4
- type: ts.Type;
5
- name: string;
6
- }
1
+ import ts from "typescript";
2
+
3
+ export interface ITypeTuple {
4
+ type: ts.Type;
5
+ name: string;
6
+ }
@@ -1,11 +1,11 @@
1
- export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
-
3
- export namespace MethodType {
4
- export const VALUES: MethodType[] = [
5
- "GET",
6
- "POST",
7
- "PUT",
8
- "PATCH",
9
- "DELETE",
10
- ];
11
- }
1
+ export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
+
3
+ export namespace MethodType {
4
+ export const VALUES: MethodType[] = [
5
+ "GET",
6
+ "POST",
7
+ "PUT",
8
+ "PATCH",
9
+ "DELETE",
10
+ ];
11
+ }
@@ -1 +1 @@
1
- export type ParamCategory = "param" | "query" | "body";
1
+ export type ParamCategory = "param" | "query" | "body";
@@ -1,22 +1,22 @@
1
- import { hash } from "tstl/functional/hash";
2
- import ts from "typescript";
3
-
4
- export class TypeEntry {
5
- public constructor(
6
- public readonly type: ts.Type,
7
- public readonly nullable: boolean,
8
- public readonly required: boolean,
9
- ) {}
10
-
11
- public equals(obj: TypeEntry): boolean {
12
- return (
13
- this.type === obj.type &&
14
- this.nullable === obj.nullable &&
15
- this.required === obj.required
16
- );
17
- }
18
-
19
- public hashCode(): number {
20
- return hash(this.type, this.nullable, this.required);
21
- }
22
- }
1
+ import { hash } from "tstl/functional/hash";
2
+ import ts from "typescript";
3
+
4
+ export class TypeEntry {
5
+ public constructor(
6
+ public readonly type: ts.Type,
7
+ public readonly nullable: boolean,
8
+ public readonly required: boolean,
9
+ ) {}
10
+
11
+ public equals(obj: TypeEntry): boolean {
12
+ return (
13
+ this.type === obj.type &&
14
+ this.nullable === obj.nullable &&
15
+ this.required === obj.required
16
+ );
17
+ }
18
+
19
+ public hashCode(): number {
20
+ return hash(this.type, this.nullable, this.required);
21
+ }
22
+ }
@@ -1,26 +1,26 @@
1
- export namespace ArrayUtil {
2
- export function has<T>(array: T[], ...items: T[]): boolean {
3
- return items.every(
4
- (elem) => array.find((org) => org === elem) !== undefined,
5
- );
6
- }
7
-
8
- export async function asyncMap<Input, Output>(
9
- array: Input[],
10
- closure: (input: Input) => Promise<Output>,
11
- ): Promise<Output[]> {
12
- const ret: Output[] = [];
13
- for (const elem of array) ret.push(await closure(elem));
14
- return ret;
15
- }
16
-
17
- export async function asyncFilter<Input>(
18
- array: Input[],
19
- closure: (input: Input) => Promise<boolean>,
20
- ): Promise<Input[]> {
21
- const ret: Input[] = [];
22
- for (const elem of array)
23
- if ((await closure(elem)) === true) ret.push(elem);
24
- return ret;
25
- }
26
- }
1
+ export namespace ArrayUtil {
2
+ export function has<T>(array: T[], ...items: T[]): boolean {
3
+ return items.every(
4
+ (elem) => array.find((org) => org === elem) !== undefined,
5
+ );
6
+ }
7
+
8
+ export async function asyncMap<Input, Output>(
9
+ array: Input[],
10
+ closure: (input: Input) => Promise<Output>,
11
+ ): Promise<Output[]> {
12
+ const ret: Output[] = [];
13
+ for (const elem of array) ret.push(await closure(elem));
14
+ return ret;
15
+ }
16
+
17
+ export async function asyncFilter<Input>(
18
+ array: Input[],
19
+ closure: (input: Input) => Promise<boolean>,
20
+ ): Promise<Input[]> {
21
+ const ret: Input[] = [];
22
+ for (const elem of array)
23
+ if ((await closure(elem)) === true) ret.push(elem);
24
+ return ret;
25
+ }
26
+ }
@@ -1,56 +1,56 @@
1
- import path from "path";
2
- import { HashMap } from "tstl/container/HashMap";
3
- import { HashSet } from "tstl/container/HashSet";
4
- import { Pair } from "tstl/utility/Pair";
5
-
6
- export class ImportDictionary {
7
- private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> =
8
- new HashMap();
9
-
10
- public empty(): boolean {
11
- return this.dict_.empty();
12
- }
13
-
14
- public emplace(file: string, realistic: boolean, instance: string): void {
15
- if (file.substr(-5) === ".d.ts") file = file.substr(0, file.length - 5);
16
- else if (file.substr(-3) === ".ts")
17
- file = file.substr(0, file.length - 3);
18
- else
19
- throw new Error(
20
- `Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`,
21
- );
22
-
23
- const pair: Pair<boolean, HashSet<string>> = this.dict_.take(
24
- file,
25
- () => new Pair(realistic, new HashSet()),
26
- );
27
- pair.second.insert(instance);
28
- }
29
-
30
- public toScript(outDir: string): string {
31
- const statements: string[] = [];
32
- for (const it of this.dict_) {
33
- const file: string = (() => {
34
- const location: string = path
35
- .relative(outDir, it.first)
36
- .split("\\")
37
- .join("/");
38
- const index: number = location.lastIndexOf(NODE_MODULES);
39
- return index === -1
40
- ? `./${location}`
41
- : location.substring(index + NODE_MODULES.length);
42
- })();
43
- const realistic: boolean = it.second.first;
44
- const instances: string[] = it.second.second.toJSON();
45
-
46
- statements.push(
47
- `import ${!realistic ? "type " : ""}{ ${instances.join(
48
- ", ",
49
- )} } from "${file}";`,
50
- );
51
- }
52
- return statements.join("\n");
53
- }
54
- }
55
-
56
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap } from "tstl/container/HashMap";
3
+ import { HashSet } from "tstl/container/HashSet";
4
+ import { Pair } from "tstl/utility/Pair";
5
+
6
+ export class ImportDictionary {
7
+ private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> =
8
+ new HashMap();
9
+
10
+ public empty(): boolean {
11
+ return this.dict_.empty();
12
+ }
13
+
14
+ public emplace(file: string, realistic: boolean, instance: string): void {
15
+ if (file.substr(-5) === ".d.ts") file = file.substr(0, file.length - 5);
16
+ else if (file.substr(-3) === ".ts")
17
+ file = file.substr(0, file.length - 3);
18
+ else
19
+ throw new Error(
20
+ `Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`,
21
+ );
22
+
23
+ const pair: Pair<boolean, HashSet<string>> = this.dict_.take(
24
+ file,
25
+ () => new Pair(realistic, new HashSet()),
26
+ );
27
+ pair.second.insert(instance);
28
+ }
29
+
30
+ public toScript(outDir: string): string {
31
+ const statements: string[] = [];
32
+ for (const it of this.dict_) {
33
+ const file: string = (() => {
34
+ const location: string = path
35
+ .relative(outDir, it.first)
36
+ .split("\\")
37
+ .join("/");
38
+ const index: number = location.lastIndexOf(NODE_MODULES);
39
+ return index === -1
40
+ ? `./${location}`
41
+ : location.substring(index + NODE_MODULES.length);
42
+ })();
43
+ const realistic: boolean = it.second.first;
44
+ const instances: string[] = it.second.second.toJSON();
45
+
46
+ statements.push(
47
+ `import ${!realistic ? "type " : ""}{ ${instances.join(
48
+ ", ",
49
+ )} } from "${file}";`,
50
+ );
51
+ }
52
+ return statements.join("\n");
53
+ }
54
+ }
55
+
56
+ const NODE_MODULES = "node_modules/";
@@ -1,14 +1,14 @@
1
- export namespace MapUtil {
2
- export function take<Key, T>(
3
- dict: Map<Key, T>,
4
- key: Key,
5
- generator: () => T,
6
- ): T {
7
- const oldbie: T | undefined = dict.get(key);
8
- if (oldbie) return oldbie;
9
-
10
- const value: T = generator();
11
- dict.set(key, value);
12
- return value;
13
- }
14
- }
1
+ export namespace MapUtil {
2
+ export function take<Key, T>(
3
+ dict: Map<Key, T>,
4
+ key: Key,
5
+ generator: () => T,
6
+ ): T {
7
+ const oldbie: T | undefined = dict.get(key);
8
+ if (oldbie) return oldbie;
9
+
10
+ const value: T = generator();
11
+ dict.set(key, value);
12
+ return value;
13
+ }
14
+ }
@@ -1,10 +1,10 @@
1
- export type StripEnums<T extends Record<string, any>> = {
2
- [Key in keyof T]: T[Key] extends
3
- | string
4
- | boolean
5
- | object
6
- | undefined
7
- | any[]
8
- ? T[Key]
9
- : any;
10
- };
1
+ export type StripEnums<T extends Record<string, any>> = {
2
+ [Key in keyof T]: T[Key] extends
3
+ | string
4
+ | boolean
5
+ | object
6
+ | undefined
7
+ | any[]
8
+ ? T[Key]
9
+ : any;
10
+ };