@nestia/sdk 1.3.2 → 1.3.4

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 (51) hide show
  1. package/assets/config/nestia.config.ts +70 -70
  2. package/lib/INestiaConfig.d.ts +13 -0
  3. package/lib/executable/internal/NestiaSdkConfig.js +6 -2
  4. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  5. package/lib/executable/sdk.js +11 -11
  6. package/lib/generates/SwaggerGenerator.js +9 -9
  7. package/lib/generates/internal/DistributionComposer.js +1 -1
  8. package/lib/generates/internal/DistributionComposer.js.map +1 -1
  9. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  10. package/lib/generates/internal/SdkFileProgrammer.js +7 -5
  11. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkFunctionProgrammer.js +42 -49
  13. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  14. package/package.json +6 -4
  15. package/src/INestiaConfig.ts +204 -190
  16. package/src/NestiaSdkApplication.ts +262 -262
  17. package/src/analyses/ControllerAnalyzer.ts +261 -261
  18. package/src/analyses/GenericAnalyzer.ts +53 -53
  19. package/src/analyses/ImportAnalyzer.ts +164 -164
  20. package/src/analyses/PathAnalyzer.ts +58 -58
  21. package/src/analyses/ReflectAnalyzer.ts +321 -321
  22. package/src/executable/internal/CommandParser.ts +15 -15
  23. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  24. package/src/executable/internal/NestiaSdkCommand.ts +156 -156
  25. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  26. package/src/executable/internal/nestia.config.getter.ts +12 -12
  27. package/src/executable/sdk.ts +70 -70
  28. package/src/generates/E2eGenerator.ts +67 -67
  29. package/src/generates/SdkGenerator.ts +56 -56
  30. package/src/generates/SwaggerGenerator.ts +504 -504
  31. package/src/generates/internal/DistributionComposer.ts +98 -97
  32. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  33. package/src/generates/internal/SdkFileProgrammer.ts +150 -144
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +51 -58
  35. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  36. package/src/index.ts +4 -4
  37. package/src/module.ts +2 -2
  38. package/src/structures/IController.ts +31 -31
  39. package/src/structures/IRoute.ts +39 -39
  40. package/src/structures/ISwaggerDocument.ts +120 -120
  41. package/src/structures/ITypeTuple.ts +6 -6
  42. package/src/structures/MethodType.ts +11 -11
  43. package/src/structures/ParamCategory.ts +1 -1
  44. package/src/structures/TypeEntry.ts +22 -22
  45. package/src/utils/ArrayUtil.ts +26 -26
  46. package/src/utils/FileRetriever.ts +22 -22
  47. package/src/utils/ImportDictionary.ts +56 -56
  48. package/src/utils/MapUtil.ts +14 -14
  49. package/src/utils/NestiaConfigUtil.ts +21 -21
  50. package/src/utils/SourceFinder.ts +60 -60
  51. package/src/utils/StripEnums.ts +10 -10
@@ -1,39 +1,39 @@
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
- status?: number;
12
-
13
- parameters: IRoute.IParameter[];
14
- imports: [string, string[]][];
15
- output: ITypeTuple;
16
-
17
- symbol: string;
18
- description?: string;
19
- tags: ts.JSDocTagInfo[];
20
- setHeaders: Array<
21
- | { type: "setter"; source: string; target?: string }
22
- | { type: "assigner"; source: string }
23
- >;
24
- }
25
-
26
- export namespace IRoute {
27
- export interface IParameter {
28
- name: string;
29
- field: string | undefined;
30
- category: ParamCategory;
31
- encrypted: boolean;
32
- type: ITypeTuple;
33
- optional: boolean;
34
- meta?: {
35
- type: string;
36
- nullable: boolean;
37
- };
38
- }
39
- }
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
+ status?: number;
12
+
13
+ parameters: IRoute.IParameter[];
14
+ imports: [string, string[]][];
15
+ output: ITypeTuple;
16
+
17
+ symbol: string;
18
+ description?: string;
19
+ tags: ts.JSDocTagInfo[];
20
+ setHeaders: Array<
21
+ | { type: "setter"; source: string; target?: string }
22
+ | { type: "assigner"; source: string }
23
+ >;
24
+ }
25
+
26
+ export namespace IRoute {
27
+ export interface IParameter {
28
+ name: string;
29
+ field: string | undefined;
30
+ category: ParamCategory;
31
+ encrypted: boolean;
32
+ type: ITypeTuple;
33
+ optional: boolean;
34
+ meta?: {
35
+ type: string;
36
+ nullable: boolean;
37
+ };
38
+ }
39
+ }
@@ -1,120 +1,120 @@
1
- import { IJsonComponents, IJsonSchema } from "typia";
2
- import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
3
-
4
- export interface ISwaggerDocument {
5
- openapi: "3.0.1";
6
- servers: ISwaggerDocument.IServer[];
7
- info: ISwaggerDocument.IInfo;
8
- components: ISwaggerDocument.IComponents;
9
- security?: Record<string, string[]>[];
10
- paths: Record<string, ISwaggerDocument.IPath>;
11
- }
12
- export namespace ISwaggerDocument {
13
- export interface IServer {
14
- url: string;
15
- description?: string;
16
- }
17
-
18
- export interface IInfo {
19
- version: string;
20
- title: string;
21
- description?: string;
22
- }
23
-
24
- export interface IComponents extends IJsonComponents {
25
- securitySchemes?: Record<string, ISecurityScheme>;
26
- }
27
-
28
- /* ---------------------------------------------------------
29
- SECURITY SCHEMES
30
- --------------------------------------------------------- */
31
- export type ISecurityScheme =
32
- | ISecurityScheme.IHttpBasic
33
- | ISecurityScheme.IHttpBearer
34
- | ISecurityScheme.IApiKey
35
- | ISecurityScheme.IOpenId
36
- | ISecurityScheme.IOAuth2;
37
- export namespace ISecurityScheme {
38
- export interface IHttpBasic {
39
- type: "http";
40
- schema: "basic";
41
- }
42
- export interface IHttpBearer {
43
- type: "http";
44
- scheme: "bearer";
45
- bearerFormat?: string;
46
- }
47
- export interface IApiKey {
48
- type: "apiKey";
49
- in: "header" | "query" | "cookie";
50
- name: string;
51
- }
52
-
53
- export interface IOpenId {
54
- type: "openIdConnect";
55
- openIdConnectUrl: string;
56
- }
57
-
58
- export interface IOAuth2 {
59
- type: "oauth2";
60
- flows: IOAuth2.IFlowSet;
61
- description?: string;
62
- }
63
- export namespace IOAuth2 {
64
- export interface IFlowSet {
65
- authorizationCode?: IFlow;
66
- implicit?: Omit<IFlow, "tokenUrl">;
67
- password?: Omit<IFlow, "authorizationUrl">;
68
- clientCredentials?: Omit<IFlow, "authorizationUrl">;
69
- }
70
- export interface IFlow {
71
- authorizationUrl: string;
72
- tokenUrl: string;
73
- refreshUrl: string;
74
- scopes?: Record<string, string>;
75
- }
76
- }
77
- }
78
-
79
- /* ---------------------------------------------------------
80
- ROUTE FUNCTIONS
81
- --------------------------------------------------------- */
82
- export type IPath = Record<string, IRoute>;
83
- export interface IRoute {
84
- tags: string[];
85
- parameters: IParameter[];
86
- requestBody?: IRequestBody;
87
- responses: IResponseBody;
88
- summary?: string;
89
- description?: string;
90
- "x-nestia-namespace": string;
91
- "x-nestia-jsDocTags": IJsDocTagInfo[];
92
- }
93
-
94
- export interface IParameter {
95
- name: string;
96
- in: string;
97
- schema: IJsonSchema;
98
- required: boolean;
99
- description: string;
100
- }
101
- export interface IRequestBody {
102
- description: string;
103
- content: IJsonContent;
104
- required: true;
105
- "x-nestia-encrypted": boolean;
106
- }
107
- export type IResponseBody = Record<
108
- string,
109
- {
110
- description: string;
111
- content?: IJsonContent;
112
- "x-nestia-encrypted"?: boolean;
113
- }
114
- >;
115
- export interface IJsonContent {
116
- "application/json": {
117
- schema: IJsonSchema;
118
- };
119
- }
120
- }
1
+ import { IJsonComponents, IJsonSchema } from "typia";
2
+ import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
3
+
4
+ export interface ISwaggerDocument {
5
+ openapi: "3.0.1";
6
+ servers: ISwaggerDocument.IServer[];
7
+ info: ISwaggerDocument.IInfo;
8
+ components: ISwaggerDocument.IComponents;
9
+ security?: Record<string, string[]>[];
10
+ paths: Record<string, ISwaggerDocument.IPath>;
11
+ }
12
+ export namespace ISwaggerDocument {
13
+ export interface IServer {
14
+ url: string;
15
+ description?: string;
16
+ }
17
+
18
+ export interface IInfo {
19
+ version: string;
20
+ title: string;
21
+ description?: string;
22
+ }
23
+
24
+ export interface IComponents extends IJsonComponents {
25
+ securitySchemes?: Record<string, ISecurityScheme>;
26
+ }
27
+
28
+ /* ---------------------------------------------------------
29
+ SECURITY SCHEMES
30
+ --------------------------------------------------------- */
31
+ export type ISecurityScheme =
32
+ | ISecurityScheme.IHttpBasic
33
+ | ISecurityScheme.IHttpBearer
34
+ | ISecurityScheme.IApiKey
35
+ | ISecurityScheme.IOpenId
36
+ | ISecurityScheme.IOAuth2;
37
+ export namespace ISecurityScheme {
38
+ export interface IHttpBasic {
39
+ type: "http";
40
+ schema: "basic";
41
+ }
42
+ export interface IHttpBearer {
43
+ type: "http";
44
+ scheme: "bearer";
45
+ bearerFormat?: string;
46
+ }
47
+ export interface IApiKey {
48
+ type: "apiKey";
49
+ in: "header" | "query" | "cookie";
50
+ name: string;
51
+ }
52
+
53
+ export interface IOpenId {
54
+ type: "openIdConnect";
55
+ openIdConnectUrl: string;
56
+ }
57
+
58
+ export interface IOAuth2 {
59
+ type: "oauth2";
60
+ flows: IOAuth2.IFlowSet;
61
+ description?: string;
62
+ }
63
+ export namespace IOAuth2 {
64
+ export interface IFlowSet {
65
+ authorizationCode?: IFlow;
66
+ implicit?: Omit<IFlow, "tokenUrl">;
67
+ password?: Omit<IFlow, "authorizationUrl">;
68
+ clientCredentials?: Omit<IFlow, "authorizationUrl">;
69
+ }
70
+ export interface IFlow {
71
+ authorizationUrl: string;
72
+ tokenUrl: string;
73
+ refreshUrl: string;
74
+ scopes?: Record<string, string>;
75
+ }
76
+ }
77
+ }
78
+
79
+ /* ---------------------------------------------------------
80
+ ROUTE FUNCTIONS
81
+ --------------------------------------------------------- */
82
+ export type IPath = Record<string, IRoute>;
83
+ export interface IRoute {
84
+ tags: string[];
85
+ parameters: IParameter[];
86
+ requestBody?: IRequestBody;
87
+ responses: IResponseBody;
88
+ summary?: string;
89
+ description?: string;
90
+ "x-nestia-namespace": string;
91
+ "x-nestia-jsDocTags": IJsDocTagInfo[];
92
+ }
93
+
94
+ export interface IParameter {
95
+ name: string;
96
+ in: string;
97
+ schema: IJsonSchema;
98
+ required: boolean;
99
+ description: string;
100
+ }
101
+ export interface IRequestBody {
102
+ description: string;
103
+ content: IJsonContent;
104
+ required: true;
105
+ "x-nestia-encrypted": boolean;
106
+ }
107
+ export type IResponseBody = Record<
108
+ string,
109
+ {
110
+ description: string;
111
+ content?: IJsonContent;
112
+ "x-nestia-encrypted"?: boolean;
113
+ }
114
+ >;
115
+ export interface IJsonContent {
116
+ "application/json": {
117
+ schema: IJsonSchema;
118
+ };
119
+ }
120
+ }
@@ -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,22 +1,22 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export namespace FileRetriever {
5
- export const directory =
6
- (name: string) =>
7
- (dir: string, depth: number = 0): string | null => {
8
- const location: string = path.join(dir, name);
9
- if (fs.existsSync(location)) return dir;
10
- else if (depth > 2) return null;
11
- return directory(name)(path.join(dir, ".."), depth + 1);
12
- };
13
-
14
- export const file =
15
- (name: string) =>
16
- (directory: string, depth: number = 0): string | null => {
17
- const location: string = path.join(directory, name);
18
- if (fs.existsSync(location)) return location;
19
- else if (depth > 2) return null;
20
- return file(name)(path.join(directory, ".."), depth + 1);
21
- };
22
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export namespace FileRetriever {
5
+ export const directory =
6
+ (name: string) =>
7
+ (dir: string, depth: number = 0): string | null => {
8
+ const location: string = path.join(dir, name);
9
+ if (fs.existsSync(location)) return dir;
10
+ else if (depth > 2) return null;
11
+ return directory(name)(path.join(dir, ".."), depth + 1);
12
+ };
13
+
14
+ export const file =
15
+ (name: string) =>
16
+ (directory: string, depth: number = 0): string | null => {
17
+ const location: string = path.join(directory, name);
18
+ if (fs.existsSync(location)) return location;
19
+ else if (depth > 2) return null;
20
+ return file(name)(path.join(directory, ".."), depth + 1);
21
+ };
22
+ }
@@ -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
+ }