@nestia/sdk 2.6.2 → 2.6.3

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 (46) hide show
  1. package/lib/analyses/ControllerAnalyzer.js +3 -3
  2. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  3. package/lib/analyses/ImportAnalyzer.d.ts +1 -2
  4. package/lib/analyses/ImportAnalyzer.js +2 -2
  5. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  6. package/lib/analyses/ReflectAnalyzer.js +2 -2
  7. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  8. package/lib/generates/SwaggerGenerator.js +4 -4
  9. package/lib/generates/SwaggerGenerator.js.map +1 -1
  10. package/lib/generates/internal/ImportDictionary.js +6 -8
  11. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  12. package/lib/structures/TypeEntry.js +2 -2
  13. package/lib/structures/TypeEntry.js.map +1 -1
  14. package/package.json +4 -4
  15. package/src/INestiaConfig.ts +248 -248
  16. package/src/NestiaSdkApplication.ts +255 -255
  17. package/src/analyses/ControllerAnalyzer.ts +402 -402
  18. package/src/analyses/ExceptionAnalyzer.ts +148 -148
  19. package/src/analyses/ImportAnalyzer.ts +1 -2
  20. package/src/analyses/ReflectAnalyzer.ts +463 -463
  21. package/src/analyses/SecurityAnalyzer.ts +24 -24
  22. package/src/generates/CloneGenerator.ts +62 -62
  23. package/src/generates/E2eGenerator.ts +66 -66
  24. package/src/generates/SdkGenerator.ts +84 -84
  25. package/src/generates/SwaggerGenerator.ts +446 -446
  26. package/src/generates/internal/E2eFileProgrammer.ts +182 -182
  27. package/src/generates/internal/FilePrinter.ts +53 -53
  28. package/src/generates/internal/ImportDictionary.ts +147 -149
  29. package/src/generates/internal/SdkAliasCollection.ts +152 -152
  30. package/src/generates/internal/SdkCloneProgrammer.ts +155 -155
  31. package/src/generates/internal/SdkFileProgrammer.ts +115 -115
  32. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -298
  33. package/src/generates/internal/SdkImportWizard.ts +55 -55
  34. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -510
  35. package/src/generates/internal/SdkRouteProgrammer.ts +83 -83
  36. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -365
  37. package/src/generates/internal/SdkTypeProgrammer.ts +385 -385
  38. package/src/generates/internal/SwaggerSchemaGenerator.ts +438 -438
  39. package/src/structures/IController.ts +94 -94
  40. package/src/structures/IRoute.ts +53 -53
  41. package/src/structures/ISwagger.ts +91 -91
  42. package/src/structures/ISwaggerRoute.ts +54 -54
  43. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  44. package/src/structures/ParamCategory.ts +1 -1
  45. package/src/structures/TypeEntry.ts +1 -1
  46. package/src/utils/StringUtil.ts +6 -6
@@ -1,149 +1,147 @@
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
- import ts from "typescript";
6
-
7
- import { FilePrinter } from "./FilePrinter";
8
-
9
- export class ImportDictionary {
10
- private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
11
- new HashMap();
12
-
13
- public constructor(public readonly file: string) {}
14
-
15
- public empty(): boolean {
16
- return this.components_.empty();
17
- }
18
-
19
- public external(props: ImportDictionary.IExternalProps): string {
20
- const composition: IComposition = this.components_.take(
21
- new Pair(props.library, props.type),
22
- () => ({
23
- location: `node_modules/${props.library}`,
24
- elements: new HashSet(),
25
- default: false,
26
- type: props.type,
27
- }),
28
- );
29
- if (props.instance === null) composition.default = true;
30
- else composition.elements.insert(props.instance);
31
- return props.instance ?? props.library;
32
- }
33
-
34
- public internal(props: ImportDictionary.IInternalProps): string {
35
- const file: string = (() => {
36
- if (props.file.substring(props.file.length - 5) === ".d.ts")
37
- return props.file.substring(0, props.file.length - 5);
38
- else if (props.file.substring(props.file.length - 3) === ".ts")
39
- return props.file.substring(0, props.file.length - 3);
40
- return props.file;
41
- })();
42
- const composition: IComposition = this.components_.take(
43
- new Pair(file, props.type),
44
- () => ({
45
- location: file,
46
- elements: new HashSet(),
47
- default: false,
48
- type: props.type,
49
- }),
50
- );
51
- if (props.instance === null) {
52
- composition.default = true;
53
- if (props.name) composition.name = props.name;
54
- } else composition.elements.insert(props.instance);
55
- return props.instance ?? file;
56
- }
57
-
58
- public toStatements(outDir: string): ts.Statement[] {
59
- const external: ts.ImportDeclaration[] = [];
60
- const internal: ts.ImportDeclaration[] = [];
61
-
62
- const locator = (str: string) => {
63
- const location: string = path.relative(outDir, str).split("\\").join("/");
64
- const index: number = location.lastIndexOf(NODE_MODULES);
65
- return index === -1
66
- ? location.startsWith("..")
67
- ? location
68
- : `./${location}`
69
- : location.substring(index + NODE_MODULES.length);
70
- };
71
- const enroll =
72
- (filter: (str: string) => boolean) =>
73
- (container: ts.ImportDeclaration[]) => {
74
- const compositions: IComposition[] = this.components_
75
- .toJSON()
76
- .filter((c) => filter(c.second.location))
77
- .map((e) => ({
78
- ...e.second,
79
- location: locator(e.second.location),
80
- }))
81
- .sort((a, b) => a.location.localeCompare(b.location));
82
- for (const c of compositions) {
83
- const brackets: string[] = [];
84
- if (c.default) brackets.push(c.name ?? c.location);
85
- if (c.elements.empty() === false)
86
- brackets.push(
87
- `{ ${c.elements
88
- .toJSON()
89
- .sort((a, b) => a.localeCompare(b))
90
- .join(", ")} }`,
91
- );
92
- container.push(
93
- ts.factory.createImportDeclaration(
94
- undefined,
95
- ts.factory.createImportClause(
96
- c.type,
97
- c.default
98
- ? ts.factory.createIdentifier(c.name ?? c.location)
99
- : undefined,
100
- c.elements.empty() === false
101
- ? ts.factory.createNamedImports(
102
- [...c.elements].map((elem) =>
103
- ts.factory.createImportSpecifier(
104
- false,
105
- undefined,
106
- ts.factory.createIdentifier(elem),
107
- ),
108
- ),
109
- )
110
- : undefined,
111
- ),
112
- ts.factory.createStringLiteral(c.location),
113
- ),
114
- );
115
- }
116
- };
117
-
118
- enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
119
- enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
120
- return [
121
- ...external,
122
- ...(external.length && internal.length ? [FilePrinter.enter()] : []),
123
- ...internal,
124
- ];
125
- }
126
- }
127
- export namespace ImportDictionary {
128
- export interface IExternalProps {
129
- type: boolean;
130
- library: string;
131
- instance: string | null;
132
- }
133
- export interface IInternalProps {
134
- type: boolean;
135
- file: string;
136
- instance: string | null;
137
- name?: string | null;
138
- }
139
- }
140
-
141
- interface IComposition {
142
- location: string;
143
- type: boolean;
144
- default: boolean;
145
- name?: string;
146
- elements: HashSet<string>;
147
- }
148
-
149
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap, HashSet, Pair } from "tstl";
3
+ import ts from "typescript";
4
+
5
+ import { FilePrinter } from "./FilePrinter";
6
+
7
+ export class ImportDictionary {
8
+ private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
9
+ new HashMap();
10
+
11
+ public constructor(public readonly file: string) {}
12
+
13
+ public empty(): boolean {
14
+ return this.components_.empty();
15
+ }
16
+
17
+ public external(props: ImportDictionary.IExternalProps): string {
18
+ const composition: IComposition = this.components_.take(
19
+ new Pair(props.library, props.type),
20
+ () => ({
21
+ location: `node_modules/${props.library}`,
22
+ elements: new HashSet(),
23
+ default: false,
24
+ type: props.type,
25
+ }),
26
+ );
27
+ if (props.instance === null) composition.default = true;
28
+ else composition.elements.insert(props.instance);
29
+ return props.instance ?? props.library;
30
+ }
31
+
32
+ public internal(props: ImportDictionary.IInternalProps): string {
33
+ const file: string = (() => {
34
+ if (props.file.substring(props.file.length - 5) === ".d.ts")
35
+ return props.file.substring(0, props.file.length - 5);
36
+ else if (props.file.substring(props.file.length - 3) === ".ts")
37
+ return props.file.substring(0, props.file.length - 3);
38
+ return props.file;
39
+ })();
40
+ const composition: IComposition = this.components_.take(
41
+ new Pair(file, props.type),
42
+ () => ({
43
+ location: file,
44
+ elements: new HashSet(),
45
+ default: false,
46
+ type: props.type,
47
+ }),
48
+ );
49
+ if (props.instance === null) {
50
+ composition.default = true;
51
+ if (props.name) composition.name = props.name;
52
+ } else composition.elements.insert(props.instance);
53
+ return props.instance ?? file;
54
+ }
55
+
56
+ public toStatements(outDir: string): ts.Statement[] {
57
+ const external: ts.ImportDeclaration[] = [];
58
+ const internal: ts.ImportDeclaration[] = [];
59
+
60
+ const locator = (str: string) => {
61
+ const location: string = path.relative(outDir, str).split("\\").join("/");
62
+ const index: number = location.lastIndexOf(NODE_MODULES);
63
+ return index === -1
64
+ ? location.startsWith("..")
65
+ ? location
66
+ : `./${location}`
67
+ : location.substring(index + NODE_MODULES.length);
68
+ };
69
+ const enroll =
70
+ (filter: (str: string) => boolean) =>
71
+ (container: ts.ImportDeclaration[]) => {
72
+ const compositions: IComposition[] = this.components_
73
+ .toJSON()
74
+ .filter((c) => filter(c.second.location))
75
+ .map((e) => ({
76
+ ...e.second,
77
+ location: locator(e.second.location),
78
+ }))
79
+ .sort((a, b) => a.location.localeCompare(b.location));
80
+ for (const c of compositions) {
81
+ const brackets: string[] = [];
82
+ if (c.default) brackets.push(c.name ?? c.location);
83
+ if (c.elements.empty() === false)
84
+ brackets.push(
85
+ `{ ${c.elements
86
+ .toJSON()
87
+ .sort((a, b) => a.localeCompare(b))
88
+ .join(", ")} }`,
89
+ );
90
+ container.push(
91
+ ts.factory.createImportDeclaration(
92
+ undefined,
93
+ ts.factory.createImportClause(
94
+ c.type,
95
+ c.default
96
+ ? ts.factory.createIdentifier(c.name ?? c.location)
97
+ : undefined,
98
+ c.elements.empty() === false
99
+ ? ts.factory.createNamedImports(
100
+ [...c.elements].map((elem) =>
101
+ ts.factory.createImportSpecifier(
102
+ false,
103
+ undefined,
104
+ ts.factory.createIdentifier(elem),
105
+ ),
106
+ ),
107
+ )
108
+ : undefined,
109
+ ),
110
+ ts.factory.createStringLiteral(c.location),
111
+ ),
112
+ );
113
+ }
114
+ };
115
+
116
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
117
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
118
+ return [
119
+ ...external,
120
+ ...(external.length && internal.length ? [FilePrinter.enter()] : []),
121
+ ...internal,
122
+ ];
123
+ }
124
+ }
125
+ export namespace ImportDictionary {
126
+ export interface IExternalProps {
127
+ type: boolean;
128
+ library: string;
129
+ instance: string | null;
130
+ }
131
+ export interface IInternalProps {
132
+ type: boolean;
133
+ file: string;
134
+ instance: string | null;
135
+ name?: string | null;
136
+ }
137
+ }
138
+
139
+ interface IComposition {
140
+ location: string;
141
+ type: boolean;
142
+ default: boolean;
143
+ name?: string;
144
+ elements: HashSet<string>;
145
+ }
146
+
147
+ const NODE_MODULES = "node_modules/";
@@ -1,152 +1,152 @@
1
- import ts from "typescript";
2
- import typia from "typia";
3
-
4
- import { INestiaConfig } from "../../INestiaConfig";
5
- import { IController } from "../../structures/IController";
6
- import { IRoute } from "../../structures/IRoute";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
9
-
10
- export namespace SdkAliasCollection {
11
- export const name =
12
- (config: INestiaConfig) =>
13
- (importer: ImportDictionary) =>
14
- (p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
15
- p.metadata
16
- ? SdkTypeProgrammer.write(config)(importer)(p.metadata)
17
- : ts.factory.createTypeReferenceNode(p.typeName);
18
-
19
- export const headers =
20
- (config: INestiaConfig) =>
21
- (importer: ImportDictionary) =>
22
- (param: IRoute.IParameter): ts.TypeNode => {
23
- const type: ts.TypeNode = name(config)(importer)(param);
24
- if (config.primitive === false) return type;
25
- return ts.factory.createTypeReferenceNode(
26
- importer.external({
27
- type: true,
28
- library: "@nestia/fetcher",
29
- instance: "Resolved",
30
- }),
31
- [type],
32
- );
33
- };
34
-
35
- export const query =
36
- (config: INestiaConfig) =>
37
- (importer: ImportDictionary) =>
38
- (param: IRoute.IParameter): ts.TypeNode => {
39
- const type: ts.TypeNode = name(config)(importer)(param);
40
- if (config.primitive === false) return type;
41
- return ts.factory.createTypeReferenceNode(
42
- importer.external({
43
- type: true,
44
- library: "@nestia/fetcher",
45
- instance: "Resolved",
46
- }),
47
- [type],
48
- );
49
- };
50
-
51
- export const input =
52
- (config: INestiaConfig) =>
53
- (importer: ImportDictionary) =>
54
- (param: IRoute.IParameter): ts.TypeNode => {
55
- const type: ts.TypeNode = name(config)(importer)(param);
56
- if (config.clone === true || config.primitive === false) return type;
57
- return ts.factory.createTypeReferenceNode(
58
- importer.external({
59
- type: true,
60
- library: "@nestia/fetcher",
61
- instance:
62
- typia.is<IController.IBodyParameter>(param) &&
63
- param.contentType === "multipart/form-data"
64
- ? "Resolved"
65
- : "Primitive",
66
- }),
67
- [type],
68
- );
69
- };
70
-
71
- export const output =
72
- (checker: ts.TypeChecker) =>
73
- (config: INestiaConfig) =>
74
- (importer: ImportDictionary) =>
75
- (route: IRoute): ts.TypeNode => {
76
- if (config.propagate !== true) {
77
- const node: ts.TypeNode = name(config)(importer)(route.output);
78
- const type = checker.getTypeAtLocation(node);
79
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
80
-
81
- if (
82
- config.clone === true ||
83
- config.primitive === false ||
84
- filter(ts.TypeFlags.Undefined) ||
85
- filter(ts.TypeFlags.Never) ||
86
- filter(ts.TypeFlags.Void) ||
87
- filter(ts.TypeFlags.VoidLike)
88
- )
89
- return node;
90
- return ts.factory.createTypeReferenceNode(
91
- importer.external({
92
- type: true,
93
- library: "@nestia/fetcher",
94
- instance:
95
- route.output.contentType === "application/x-www-form-urlencoded"
96
- ? "Resolved"
97
- : "Primitive",
98
- }),
99
- [node],
100
- );
101
- }
102
-
103
- const branches: IBranch[] = [
104
- {
105
- status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
106
- type: name(config)(importer)(route.output),
107
- },
108
- ...Object.entries(route.exceptions).map(([status, value]) => ({
109
- status,
110
- type: name(config)(importer)(value),
111
- })),
112
- ];
113
- return ts.factory.createTypeReferenceNode(
114
- importer.external({
115
- type: true,
116
- library: "@nestia/fetcher",
117
- instance: "IPropagation",
118
- }),
119
- [
120
- ts.factory.createTypeLiteralNode(
121
- branches.map((b) =>
122
- ts.factory.createPropertySignature(
123
- undefined,
124
- ts.factory.createNumericLiteral(b.status),
125
- undefined,
126
- b.type,
127
- ),
128
- ),
129
- ),
130
- ...(route.status
131
- ? [
132
- ts.factory.createLiteralTypeNode(
133
- ts.factory.createNumericLiteral(route.status),
134
- ),
135
- ]
136
- : []),
137
- ],
138
- );
139
- };
140
-
141
- export const responseBody =
142
- (checker: ts.TypeChecker) =>
143
- (config: INestiaConfig) =>
144
- (importer: ImportDictionary) =>
145
- (route: IRoute): ts.TypeNode =>
146
- output(checker)({ ...config, propagate: false })(importer)(route);
147
- }
148
-
149
- interface IBranch {
150
- status: string;
151
- type: ts.TypeNode;
152
- }
1
+ import ts from "typescript";
2
+ import typia from "typia";
3
+
4
+ import { INestiaConfig } from "../../INestiaConfig";
5
+ import { IController } from "../../structures/IController";
6
+ import { IRoute } from "../../structures/IRoute";
7
+ import { ImportDictionary } from "./ImportDictionary";
8
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
9
+
10
+ export namespace SdkAliasCollection {
11
+ export const name =
12
+ (config: INestiaConfig) =>
13
+ (importer: ImportDictionary) =>
14
+ (p: IRoute.IParameter | IRoute.IOutput): ts.TypeNode =>
15
+ p.metadata
16
+ ? SdkTypeProgrammer.write(config)(importer)(p.metadata)
17
+ : ts.factory.createTypeReferenceNode(p.typeName);
18
+
19
+ export const headers =
20
+ (config: INestiaConfig) =>
21
+ (importer: ImportDictionary) =>
22
+ (param: IRoute.IParameter): ts.TypeNode => {
23
+ const type: ts.TypeNode = name(config)(importer)(param);
24
+ if (config.primitive === false) return type;
25
+ return ts.factory.createTypeReferenceNode(
26
+ importer.external({
27
+ type: true,
28
+ library: "@nestia/fetcher",
29
+ instance: "Resolved",
30
+ }),
31
+ [type],
32
+ );
33
+ };
34
+
35
+ export const query =
36
+ (config: INestiaConfig) =>
37
+ (importer: ImportDictionary) =>
38
+ (param: IRoute.IParameter): ts.TypeNode => {
39
+ const type: ts.TypeNode = name(config)(importer)(param);
40
+ if (config.primitive === false) return type;
41
+ return ts.factory.createTypeReferenceNode(
42
+ importer.external({
43
+ type: true,
44
+ library: "@nestia/fetcher",
45
+ instance: "Resolved",
46
+ }),
47
+ [type],
48
+ );
49
+ };
50
+
51
+ export const input =
52
+ (config: INestiaConfig) =>
53
+ (importer: ImportDictionary) =>
54
+ (param: IRoute.IParameter): ts.TypeNode => {
55
+ const type: ts.TypeNode = name(config)(importer)(param);
56
+ if (config.clone === true || config.primitive === false) return type;
57
+ return ts.factory.createTypeReferenceNode(
58
+ importer.external({
59
+ type: true,
60
+ library: "@nestia/fetcher",
61
+ instance:
62
+ typia.is<IController.IBodyParameter>(param) &&
63
+ param.contentType === "multipart/form-data"
64
+ ? "Resolved"
65
+ : "Primitive",
66
+ }),
67
+ [type],
68
+ );
69
+ };
70
+
71
+ export const output =
72
+ (checker: ts.TypeChecker) =>
73
+ (config: INestiaConfig) =>
74
+ (importer: ImportDictionary) =>
75
+ (route: IRoute): ts.TypeNode => {
76
+ if (config.propagate !== true) {
77
+ const node: ts.TypeNode = name(config)(importer)(route.output);
78
+ const type = checker.getTypeAtLocation(node);
79
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
80
+
81
+ if (
82
+ config.clone === true ||
83
+ config.primitive === false ||
84
+ filter(ts.TypeFlags.Undefined) ||
85
+ filter(ts.TypeFlags.Never) ||
86
+ filter(ts.TypeFlags.Void) ||
87
+ filter(ts.TypeFlags.VoidLike)
88
+ )
89
+ return node;
90
+ return ts.factory.createTypeReferenceNode(
91
+ importer.external({
92
+ type: true,
93
+ library: "@nestia/fetcher",
94
+ instance:
95
+ route.output.contentType === "application/x-www-form-urlencoded"
96
+ ? "Resolved"
97
+ : "Primitive",
98
+ }),
99
+ [node],
100
+ );
101
+ }
102
+
103
+ const branches: IBranch[] = [
104
+ {
105
+ status: String(route.status ?? (route.method === "POST" ? 201 : 200)),
106
+ type: name(config)(importer)(route.output),
107
+ },
108
+ ...Object.entries(route.exceptions).map(([status, value]) => ({
109
+ status,
110
+ type: name(config)(importer)(value),
111
+ })),
112
+ ];
113
+ return ts.factory.createTypeReferenceNode(
114
+ importer.external({
115
+ type: true,
116
+ library: "@nestia/fetcher",
117
+ instance: "IPropagation",
118
+ }),
119
+ [
120
+ ts.factory.createTypeLiteralNode(
121
+ branches.map((b) =>
122
+ ts.factory.createPropertySignature(
123
+ undefined,
124
+ ts.factory.createNumericLiteral(b.status),
125
+ undefined,
126
+ b.type,
127
+ ),
128
+ ),
129
+ ),
130
+ ...(route.status
131
+ ? [
132
+ ts.factory.createLiteralTypeNode(
133
+ ts.factory.createNumericLiteral(route.status),
134
+ ),
135
+ ]
136
+ : []),
137
+ ],
138
+ );
139
+ };
140
+
141
+ export const responseBody =
142
+ (checker: ts.TypeChecker) =>
143
+ (config: INestiaConfig) =>
144
+ (importer: ImportDictionary) =>
145
+ (route: IRoute): ts.TypeNode =>
146
+ output(checker)({ ...config, propagate: false })(importer)(route);
147
+ }
148
+
149
+ interface IBranch {
150
+ status: string;
151
+ type: ts.TypeNode;
152
+ }