@nestia/sdk 2.4.5 → 2.4.6

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 (66) hide show
  1. package/lib/analyses/ConfigAnalyzer.js +1 -1
  2. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.js.map +1 -1
  5. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  6. package/lib/executable/sdk.js +11 -11
  7. package/lib/generates/SwaggerGenerator.js.map +1 -1
  8. package/lib/generates/internal/SdkFunctionProgrammer.js +7 -7
  9. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  10. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  11. package/package.json +3 -3
  12. package/src/INestiaConfig.ts +248 -248
  13. package/src/NestiaSdkApplication.ts +253 -253
  14. package/src/analyses/AccessorAnalyzer.ts +60 -60
  15. package/src/analyses/ConfigAnalyzer.ts +3 -3
  16. package/src/analyses/ControllerAnalyzer.ts +2 -2
  17. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  18. package/src/analyses/GenericAnalyzer.ts +51 -51
  19. package/src/analyses/ImportAnalyzer.ts +138 -138
  20. package/src/analyses/PathAnalyzer.ts +14 -14
  21. package/src/analyses/ReflectAnalyzer.ts +9 -9
  22. package/src/analyses/SecurityAnalyzer.ts +20 -20
  23. package/src/executable/internal/CommandParser.ts +15 -15
  24. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  25. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  26. package/src/executable/sdk.ts +73 -73
  27. package/src/generates/E2eGenerator.ts +64 -64
  28. package/src/generates/SdkGenerator.ts +96 -96
  29. package/src/generates/SwaggerGenerator.ts +5 -5
  30. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  31. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  32. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  33. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +518 -518
  35. package/src/generates/internal/SdkImportWizard.ts +55 -55
  36. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  37. package/src/generates/internal/SdkSimulationProgrammer.ts +4 -4
  38. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  39. package/src/generates/internal/SwaggerSchemaGenerator.ts +16 -16
  40. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  41. package/src/index.ts +4 -4
  42. package/src/module.ts +2 -2
  43. package/src/structures/IController.ts +91 -91
  44. package/src/structures/IErrorReport.ts +6 -6
  45. package/src/structures/INestiaProject.ts +13 -13
  46. package/src/structures/INormalizedInput.ts +20 -20
  47. package/src/structures/IRoute.ts +52 -52
  48. package/src/structures/ISwagger.ts +91 -91
  49. package/src/structures/ISwaggerComponents.ts +29 -29
  50. package/src/structures/ISwaggerError.ts +8 -8
  51. package/src/structures/ISwaggerInfo.ts +80 -80
  52. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  53. package/src/structures/ISwaggerLazySchema.ts +7 -7
  54. package/src/structures/ISwaggerRoute.ts +51 -51
  55. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  56. package/src/structures/ITypeTuple.ts +6 -6
  57. package/src/structures/MethodType.ts +5 -5
  58. package/src/structures/ParamCategory.ts +1 -1
  59. package/src/structures/TypeEntry.ts +22 -22
  60. package/src/utils/ArrayUtil.ts +26 -26
  61. package/src/utils/FileRetriever.ts +22 -22
  62. package/src/utils/ImportDictionary.ts +125 -125
  63. package/src/utils/MapUtil.ts +14 -14
  64. package/src/utils/PathUtil.ts +10 -10
  65. package/src/utils/SourceFinder.ts +66 -66
  66. package/src/utils/StripEnums.ts +5 -5
@@ -1,55 +1,55 @@
1
- import { ImportDictionary } from "../../utils/ImportDictionary";
2
-
3
- export namespace SdkImportWizard {
4
- export const Fetcher = (encrypted: boolean) =>
5
- encrypted ? EncryptedFetcher : PlainFetcher;
6
-
7
- export const HttpError = (importer: ImportDictionary) =>
8
- importer.external({
9
- type: true,
10
- library: "@nestia/fetcher",
11
- instance: "HttpError",
12
- });
13
-
14
- export const IConnection = (importer: ImportDictionary) =>
15
- importer.external({
16
- type: true,
17
- library: "@nestia/fetcher",
18
- instance: "IConnection",
19
- });
20
-
21
- export const Primitive = (importer: ImportDictionary) =>
22
- importer.external({
23
- type: true,
24
- library: "@nestia/fetcher",
25
- instance: "Primitive",
26
- });
27
-
28
- export const Resolved = (importer: ImportDictionary) =>
29
- importer.external({
30
- type: true,
31
- library: "@nestia/fetcher",
32
- instance: "Resolved",
33
- });
34
-
35
- export const typia = (importer: ImportDictionary) =>
36
- importer.external({
37
- type: false,
38
- library: "typia",
39
- instance: null,
40
- });
41
- }
42
-
43
- const PlainFetcher = (importer: ImportDictionary) =>
44
- importer.external({
45
- type: false,
46
- library: "@nestia/fetcher/lib/PlainFetcher",
47
- instance: "PlainFetcher",
48
- });
49
-
50
- const EncryptedFetcher = (importer: ImportDictionary) =>
51
- importer.external({
52
- type: false,
53
- library: "@nestia/fetcher/lib/EncryptedFetcher",
54
- instance: "EncryptedFetcher",
55
- });
1
+ import { ImportDictionary } from "../../utils/ImportDictionary";
2
+
3
+ export namespace SdkImportWizard {
4
+ export const Fetcher = (encrypted: boolean) =>
5
+ encrypted ? EncryptedFetcher : PlainFetcher;
6
+
7
+ export const HttpError = (importer: ImportDictionary) =>
8
+ importer.external({
9
+ type: true,
10
+ library: "@nestia/fetcher",
11
+ instance: "HttpError",
12
+ });
13
+
14
+ export const IConnection = (importer: ImportDictionary) =>
15
+ importer.external({
16
+ type: true,
17
+ library: "@nestia/fetcher",
18
+ instance: "IConnection",
19
+ });
20
+
21
+ export const Primitive = (importer: ImportDictionary) =>
22
+ importer.external({
23
+ type: true,
24
+ library: "@nestia/fetcher",
25
+ instance: "Primitive",
26
+ });
27
+
28
+ export const Resolved = (importer: ImportDictionary) =>
29
+ importer.external({
30
+ type: true,
31
+ library: "@nestia/fetcher",
32
+ instance: "Resolved",
33
+ });
34
+
35
+ export const typia = (importer: ImportDictionary) =>
36
+ importer.external({
37
+ type: false,
38
+ library: "typia",
39
+ instance: null,
40
+ });
41
+ }
42
+
43
+ const PlainFetcher = (importer: ImportDictionary) =>
44
+ importer.external({
45
+ type: false,
46
+ library: "@nestia/fetcher/lib/PlainFetcher",
47
+ instance: "PlainFetcher",
48
+ });
49
+
50
+ const EncryptedFetcher = (importer: ImportDictionary) =>
51
+ importer.external({
52
+ type: false,
53
+ library: "@nestia/fetcher/lib/EncryptedFetcher",
54
+ instance: "EncryptedFetcher",
55
+ });
@@ -1,17 +1,17 @@
1
- import { IRoute } from "../../structures/IRoute";
2
-
3
- export class SdkRouteDirectory {
4
- public readonly module: string;
5
- public readonly children: Map<string, SdkRouteDirectory>;
6
- public readonly routes: IRoute[];
7
-
8
- public constructor(
9
- readonly parent: SdkRouteDirectory | null,
10
- readonly name: string,
11
- ) {
12
- this.children = new Map();
13
- this.routes = [];
14
- this.module =
15
- this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
- }
17
- }
1
+ import { IRoute } from "../../structures/IRoute";
2
+
3
+ export class SdkRouteDirectory {
4
+ public readonly module: string;
5
+ public readonly children: Map<string, SdkRouteDirectory>;
6
+ public readonly routes: IRoute[];
7
+
8
+ public constructor(
9
+ readonly parent: SdkRouteDirectory | null,
10
+ readonly name: string,
11
+ ) {
12
+ this.children = new Map();
13
+ this.routes = [];
14
+ this.module =
15
+ this.parent !== null ? `${this.parent.module}.${name}` : `api.${name}`;
16
+ }
17
+ }
@@ -78,10 +78,10 @@ export namespace SdkSimulationProgrammer {
78
78
  p.category === "body"
79
79
  ? `assert.body(() => ${typia}.assert(${p.name}));`
80
80
  : p.category === "query"
81
- ? `assert.query(() => ${typia}.assert(${p.name}));`
82
- : p.category === "headers"
83
- ? `assert.headers(() => ${typia}.assert(connection.headers);`
84
- : `assert.param("${p.field}")(() => ${typia}.assert(${p.name}));`,
81
+ ? `assert.query(() => ${typia}.assert(${p.name}));`
82
+ : p.category === "headers"
83
+ ? `assert.headers(() => ${typia}.assert(connection.headers);`
84
+ : `assert.param("${p.field}")(() => ${typia}.assert(${p.name}));`,
85
85
  );
86
86
  if (config.propagate !== true) return [...func, ...individual];
87
87
 
@@ -1,119 +1,119 @@
1
- import { INestiaConfig } from "../../INestiaConfig";
2
- import { IRoute } from "../../structures/IRoute";
3
- import { ImportDictionary } from "../../utils/ImportDictionary";
4
- import { SdkDtoGenerator } from "./SdkDtoGenerator";
5
-
6
- export namespace SdkTypeDefiner {
7
- export const name =
8
- (config: INestiaConfig) =>
9
- (importer: ImportDictionary) =>
10
- (p: IRoute.IParameter | IRoute.IOutput): string =>
11
- p.metadata
12
- ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
13
- : p.typeName;
14
-
15
- export const headers =
16
- (config: INestiaConfig) =>
17
- (importer: ImportDictionary) =>
18
- (param: IRoute.IParameter): string => {
19
- const type: string = name(config)(importer)(param);
20
- if (config.primitive === false) return type;
21
-
22
- const resolved: string = importer.external({
23
- type: true,
24
- library: "@nestia/fetcher",
25
- instance: "Resolved",
26
- });
27
- return `${resolved}<${type}>`;
28
- };
29
-
30
- export const query =
31
- (config: INestiaConfig) =>
32
- (importer: ImportDictionary) =>
33
- (param: IRoute.IParameter): string => {
34
- const type: string = name(config)(importer)(param);
35
- if (config.primitive === false) return type;
36
-
37
- const resolved: string = importer.external({
38
- type: true,
39
- library: "@nestia/fetcher",
40
- instance: "Resolved",
41
- });
42
- return `${resolved}<${type}>`;
43
- };
44
-
45
- export const input =
46
- (config: INestiaConfig) =>
47
- (importer: ImportDictionary) =>
48
- (param: IRoute.IParameter): string => {
49
- const type: string = name(config)(importer)(param);
50
- if (config.primitive === false) return type;
51
-
52
- const primitive: string = importer.external({
53
- type: true,
54
- library: "@nestia/fetcher",
55
- instance: "Primitive",
56
- });
57
- return `${primitive}<${type}>`;
58
- };
59
-
60
- export const output =
61
- (config: INestiaConfig) =>
62
- (importer: ImportDictionary) =>
63
- (route: IRoute): string => {
64
- if (config.propagate !== true) {
65
- const type: string = name(config)(importer)(route.output);
66
- if (type === "void" || config.primitive === false) return type;
67
-
68
- const wrapper: string = importer.external({
69
- type: true,
70
- library: "@nestia/fetcher",
71
- instance:
72
- route.output.contentType === "application/x-www-form-urlencoded"
73
- ? "Resolved"
74
- : "Primitive",
75
- });
76
- return `${wrapper}<${type}>`;
77
- }
78
-
79
- const propagation: string = importer.external({
80
- type: true,
81
- library: "@nestia/fetcher",
82
- instance: "IPropagation",
83
- });
84
- const branches: IBranch[] = [
85
- {
86
- status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
87
- type: name(config)(importer)(route.output),
88
- },
89
- ...Object.entries(route.exceptions).map(([status, value]) => ({
90
- status,
91
- type: name(config)(importer)(value),
92
- })),
93
- ];
94
- return (
95
- `${propagation}<{\n` +
96
- branches
97
- .map(
98
- (b) =>
99
- ` ${
100
- b.status.endsWith("XX") ? `"${b.status}"` : b.status
101
- }: ${b.type};`,
102
- )
103
- .join("\n") +
104
- "\n" +
105
- ` }${route.status ? `, ${route.status}` : ""}>`
106
- );
107
- };
108
-
109
- export const responseBody =
110
- (config: INestiaConfig) =>
111
- (importer: ImportDictionary) =>
112
- (route: IRoute): string =>
113
- output({ ...config, propagate: false })(importer)(route);
114
- }
115
-
116
- interface IBranch {
117
- status: string;
118
- type: string;
119
- }
1
+ import { INestiaConfig } from "../../INestiaConfig";
2
+ import { IRoute } from "../../structures/IRoute";
3
+ import { ImportDictionary } from "../../utils/ImportDictionary";
4
+ import { SdkDtoGenerator } from "./SdkDtoGenerator";
5
+
6
+ export namespace SdkTypeDefiner {
7
+ export const name =
8
+ (config: INestiaConfig) =>
9
+ (importer: ImportDictionary) =>
10
+ (p: IRoute.IParameter | IRoute.IOutput): string =>
11
+ p.metadata
12
+ ? SdkDtoGenerator.decode(config)(importer)(p.metadata)
13
+ : p.typeName;
14
+
15
+ export const headers =
16
+ (config: INestiaConfig) =>
17
+ (importer: ImportDictionary) =>
18
+ (param: IRoute.IParameter): string => {
19
+ const type: string = name(config)(importer)(param);
20
+ if (config.primitive === false) return type;
21
+
22
+ const resolved: string = importer.external({
23
+ type: true,
24
+ library: "@nestia/fetcher",
25
+ instance: "Resolved",
26
+ });
27
+ return `${resolved}<${type}>`;
28
+ };
29
+
30
+ export const query =
31
+ (config: INestiaConfig) =>
32
+ (importer: ImportDictionary) =>
33
+ (param: IRoute.IParameter): string => {
34
+ const type: string = name(config)(importer)(param);
35
+ if (config.primitive === false) return type;
36
+
37
+ const resolved: string = importer.external({
38
+ type: true,
39
+ library: "@nestia/fetcher",
40
+ instance: "Resolved",
41
+ });
42
+ return `${resolved}<${type}>`;
43
+ };
44
+
45
+ export const input =
46
+ (config: INestiaConfig) =>
47
+ (importer: ImportDictionary) =>
48
+ (param: IRoute.IParameter): string => {
49
+ const type: string = name(config)(importer)(param);
50
+ if (config.primitive === false) return type;
51
+
52
+ const primitive: string = importer.external({
53
+ type: true,
54
+ library: "@nestia/fetcher",
55
+ instance: "Primitive",
56
+ });
57
+ return `${primitive}<${type}>`;
58
+ };
59
+
60
+ export const output =
61
+ (config: INestiaConfig) =>
62
+ (importer: ImportDictionary) =>
63
+ (route: IRoute): string => {
64
+ if (config.propagate !== true) {
65
+ const type: string = name(config)(importer)(route.output);
66
+ if (type === "void" || config.primitive === false) return type;
67
+
68
+ const wrapper: string = importer.external({
69
+ type: true,
70
+ library: "@nestia/fetcher",
71
+ instance:
72
+ route.output.contentType === "application/x-www-form-urlencoded"
73
+ ? "Resolved"
74
+ : "Primitive",
75
+ });
76
+ return `${wrapper}<${type}>`;
77
+ }
78
+
79
+ const propagation: string = importer.external({
80
+ type: true,
81
+ library: "@nestia/fetcher",
82
+ instance: "IPropagation",
83
+ });
84
+ const branches: IBranch[] = [
85
+ {
86
+ status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
87
+ type: name(config)(importer)(route.output),
88
+ },
89
+ ...Object.entries(route.exceptions).map(([status, value]) => ({
90
+ status,
91
+ type: name(config)(importer)(value),
92
+ })),
93
+ ];
94
+ return (
95
+ `${propagation}<{\n` +
96
+ branches
97
+ .map(
98
+ (b) =>
99
+ ` ${
100
+ b.status.endsWith("XX") ? `"${b.status}"` : b.status
101
+ }: ${b.type};`,
102
+ )
103
+ .join("\n") +
104
+ "\n" +
105
+ ` }${route.status ? `, ${route.status}` : ""}>`
106
+ );
107
+ };
108
+
109
+ export const responseBody =
110
+ (config: INestiaConfig) =>
111
+ (importer: ImportDictionary) =>
112
+ (route: IRoute): string =>
113
+ output({ ...config, propagate: false })(importer)(route);
114
+ }
115
+
116
+ interface IBranch {
117
+ status: string;
118
+ type: string;
119
+ }
@@ -108,10 +108,10 @@ export namespace SwaggerSchemaGenerator {
108
108
  route.status !== undefined
109
109
  ? String(route.status)
110
110
  : route.method === "GET" ||
111
- route.method === "HEAD" ||
112
- route.method === "DELETE"
113
- ? "200"
114
- : "201";
111
+ route.method === "HEAD" ||
112
+ route.method === "DELETE"
113
+ ? "200"
114
+ : "201";
115
115
 
116
116
  // SCHEMA
117
117
  const result = MetadataFactory.analyze(props.checker)({
@@ -156,10 +156,10 @@ export namespace SwaggerSchemaGenerator {
156
156
  "x-nestia-encrypted": route.encrypted,
157
157
  }
158
158
  : route.encrypted === true
159
- ? {
160
- "x-nestia-encrypted": true,
161
- }
162
- : {}),
159
+ ? {
160
+ "x-nestia-encrypted": true,
161
+ }
162
+ : {}),
163
163
  };
164
164
  return output;
165
165
  };
@@ -219,10 +219,10 @@ export namespace SwaggerSchemaGenerator {
219
219
  "x-nestia-encrypted": encrypted,
220
220
  }
221
221
  : encrypted === true
222
- ? {
223
- "x-nestia-encrypted": true,
224
- }
225
- : {}),
222
+ ? {
223
+ "x-nestia-encrypted": true,
224
+ }
225
+ : {}),
226
226
  };
227
227
  };
228
228
 
@@ -233,8 +233,8 @@ export namespace SwaggerSchemaGenerator {
233
233
  param.category === "headers"
234
234
  ? headers(props)(route)(param)
235
235
  : param.category === "param"
236
- ? [path(props)(route)(param)]
237
- : query(props)(route)(param);
236
+ ? [path(props)(route)(param)]
237
+ : query(props)(route)(param);
238
238
 
239
239
  const path =
240
240
  (props: IProps) =>
@@ -345,8 +345,8 @@ export namespace SwaggerSchemaGenerator {
345
345
  param.category === "headers"
346
346
  ? "header"
347
347
  : param.category === "param"
348
- ? "path"
349
- : param.category,
348
+ ? "path"
349
+ : param.category,
350
350
  schema,
351
351
  description: describe(route, "param", param.name) ?? "",
352
352
  required: result.success ? result.data.isRequired() : true,