@nestia/sdk 3.1.0-dev.20240429 → 3.1.0-dev.20240430

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 (55) hide show
  1. package/lib/analyses/TypedWebSocketOperationAnalyzer.js +1 -1
  2. package/lib/analyses/TypedWebSocketOperationAnalyzer.js.map +1 -1
  3. package/lib/executable/sdk.js +11 -11
  4. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +18 -20
  5. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  6. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +30 -1
  7. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  8. package/lib/structures/ITypedWebSocketRoute.d.ts +1 -0
  9. package/package.json +3 -3
  10. package/src/NestiaSdkApplication.ts +257 -257
  11. package/src/analyses/AccessorAnalyzer.ts +67 -67
  12. package/src/analyses/ConfigAnalyzer.ts +147 -147
  13. package/src/analyses/GenericAnalyzer.ts +51 -51
  14. package/src/analyses/PathAnalyzer.ts +69 -69
  15. package/src/analyses/SecurityAnalyzer.ts +25 -25
  16. package/src/analyses/TypedWebSocketOperationAnalyzer.ts +1 -0
  17. package/src/executable/internal/CommandParser.ts +15 -15
  18. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  19. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  20. package/src/executable/sdk.ts +73 -73
  21. package/src/generates/CloneGenerator.ts +64 -64
  22. package/src/generates/E2eGenerator.ts +64 -64
  23. package/src/generates/SdkGenerator.ts +91 -91
  24. package/src/generates/internal/E2eFileProgrammer.ts +178 -178
  25. package/src/generates/internal/FilePrinter.ts +53 -53
  26. package/src/generates/internal/SdkAliasCollection.ts +157 -157
  27. package/src/generates/internal/SdkDistributionComposer.ts +100 -100
  28. package/src/generates/internal/SdkFileProgrammer.ts +119 -119
  29. package/src/generates/internal/SdkHttpCloneProgrammer.ts +154 -154
  30. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +298 -299
  31. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +505 -505
  32. package/src/generates/internal/SdkHttpRouteProgrammer.ts +82 -82
  33. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +363 -363
  34. package/src/generates/internal/SdkImportWizard.ts +55 -55
  35. package/src/generates/internal/SdkRouteDirectory.ts +18 -18
  36. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +42 -1
  37. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  38. package/src/index.ts +4 -4
  39. package/src/module.ts +2 -2
  40. package/src/structures/IErrorReport.ts +6 -6
  41. package/src/structures/INestiaProject.ts +13 -13
  42. package/src/structures/INormalizedInput.ts +20 -20
  43. package/src/structures/IReflectController.ts +17 -17
  44. package/src/structures/ITypeTuple.ts +6 -6
  45. package/src/structures/ITypedHttpRoute.ts +55 -55
  46. package/src/structures/ITypedWebSocketRoute.ts +1 -0
  47. package/src/structures/MethodType.ts +5 -5
  48. package/src/structures/ParamCategory.ts +1 -1
  49. package/src/utils/ArrayUtil.ts +26 -26
  50. package/src/utils/FileRetriever.ts +22 -22
  51. package/src/utils/MapUtil.ts +14 -14
  52. package/src/utils/PathUtil.ts +10 -10
  53. package/src/utils/SourceFinder.ts +66 -66
  54. package/src/utils/StringUtil.ts +6 -6
  55. package/src/utils/StripEnums.ts +5 -5
@@ -1,157 +1,157 @@
1
- import ts from "typescript";
2
- import typia from "typia";
3
-
4
- import { INestiaProject } from "../../structures/INestiaProject";
5
- import { IReflectHttpOperation } from "../../structures/IReflectHttpOperation";
6
- import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
- import { ImportDictionary } from "./ImportDictionary";
8
- import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
9
-
10
- export namespace SdkAliasCollection {
11
- export const name =
12
- (project: INestiaProject) =>
13
- (importer: ImportDictionary) =>
14
- (p: ITypedHttpRoute.IParameter | ITypedHttpRoute.IOutput): ts.TypeNode =>
15
- p.metadata
16
- ? SdkTypeProgrammer.write(project)(importer)(p.metadata)
17
- : ts.factory.createTypeReferenceNode(p.typeName);
18
-
19
- export const headers =
20
- (project: INestiaProject) =>
21
- (importer: ImportDictionary) =>
22
- (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
23
- const type: ts.TypeNode = name(project)(importer)(param);
24
- if (project.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
- (project: INestiaProject) =>
37
- (importer: ImportDictionary) =>
38
- (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
39
- const type: ts.TypeNode = name(project)(importer)(param);
40
- if (project.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
- (project: INestiaProject) =>
53
- (importer: ImportDictionary) =>
54
- (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
55
- const type: ts.TypeNode = name(project)(importer)(param);
56
- if (project.config.clone === true || project.config.primitive === false)
57
- return type;
58
- return ts.factory.createTypeReferenceNode(
59
- importer.external({
60
- type: true,
61
- library: "@nestia/fetcher",
62
- instance:
63
- typia.is<IReflectHttpOperation.IBodyParameter>(param) &&
64
- param.contentType === "multipart/form-data"
65
- ? "Resolved"
66
- : "Primitive",
67
- }),
68
- [type],
69
- );
70
- };
71
-
72
- export const output =
73
- (project: INestiaProject) =>
74
- (importer: ImportDictionary) =>
75
- (route: ITypedHttpRoute): ts.TypeNode => {
76
- if (project.config.propagate !== true) {
77
- const node: ts.TypeNode = name(project)(importer)(route.output);
78
- const type = project.checker.getTypeAtLocation(node);
79
- const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
80
-
81
- if (
82
- project.config.clone === true ||
83
- project.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(project)(importer)(route.output),
107
- },
108
- ...Object.entries(route.exceptions).map(([status, value]) => ({
109
- status,
110
- type: name(project)(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
- (project: INestiaProject) =>
143
- (importer: ImportDictionary) =>
144
- (route: ITypedHttpRoute): ts.TypeNode =>
145
- output({
146
- ...project,
147
- config: {
148
- ...project.config,
149
- propagate: false,
150
- },
151
- })(importer)(route);
152
- }
153
-
154
- interface IBranch {
155
- status: string;
156
- type: ts.TypeNode;
157
- }
1
+ import ts from "typescript";
2
+ import typia from "typia";
3
+
4
+ import { INestiaProject } from "../../structures/INestiaProject";
5
+ import { IReflectHttpOperation } from "../../structures/IReflectHttpOperation";
6
+ import { ITypedHttpRoute } from "../../structures/ITypedHttpRoute";
7
+ import { ImportDictionary } from "./ImportDictionary";
8
+ import { SdkTypeProgrammer } from "./SdkTypeProgrammer";
9
+
10
+ export namespace SdkAliasCollection {
11
+ export const name =
12
+ (project: INestiaProject) =>
13
+ (importer: ImportDictionary) =>
14
+ (p: ITypedHttpRoute.IParameter | ITypedHttpRoute.IOutput): ts.TypeNode =>
15
+ p.metadata
16
+ ? SdkTypeProgrammer.write(project)(importer)(p.metadata)
17
+ : ts.factory.createTypeReferenceNode(p.typeName);
18
+
19
+ export const headers =
20
+ (project: INestiaProject) =>
21
+ (importer: ImportDictionary) =>
22
+ (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
23
+ const type: ts.TypeNode = name(project)(importer)(param);
24
+ if (project.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
+ (project: INestiaProject) =>
37
+ (importer: ImportDictionary) =>
38
+ (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
39
+ const type: ts.TypeNode = name(project)(importer)(param);
40
+ if (project.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
+ (project: INestiaProject) =>
53
+ (importer: ImportDictionary) =>
54
+ (param: ITypedHttpRoute.IParameter): ts.TypeNode => {
55
+ const type: ts.TypeNode = name(project)(importer)(param);
56
+ if (project.config.clone === true || project.config.primitive === false)
57
+ return type;
58
+ return ts.factory.createTypeReferenceNode(
59
+ importer.external({
60
+ type: true,
61
+ library: "@nestia/fetcher",
62
+ instance:
63
+ typia.is<IReflectHttpOperation.IBodyParameter>(param) &&
64
+ param.contentType === "multipart/form-data"
65
+ ? "Resolved"
66
+ : "Primitive",
67
+ }),
68
+ [type],
69
+ );
70
+ };
71
+
72
+ export const output =
73
+ (project: INestiaProject) =>
74
+ (importer: ImportDictionary) =>
75
+ (route: ITypedHttpRoute): ts.TypeNode => {
76
+ if (project.config.propagate !== true) {
77
+ const node: ts.TypeNode = name(project)(importer)(route.output);
78
+ const type = project.checker.getTypeAtLocation(node);
79
+ const filter = (flag: ts.TypeFlags) => (type.getFlags() & flag) !== 0;
80
+
81
+ if (
82
+ project.config.clone === true ||
83
+ project.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(project)(importer)(route.output),
107
+ },
108
+ ...Object.entries(route.exceptions).map(([status, value]) => ({
109
+ status,
110
+ type: name(project)(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
+ (project: INestiaProject) =>
143
+ (importer: ImportDictionary) =>
144
+ (route: ITypedHttpRoute): ts.TypeNode =>
145
+ output({
146
+ ...project,
147
+ config: {
148
+ ...project.config,
149
+ propagate: false,
150
+ },
151
+ })(importer)(route);
152
+ }
153
+
154
+ interface IBranch {
155
+ status: string;
156
+ type: ts.TypeNode;
157
+ }
@@ -1,100 +1,100 @@
1
- import cp from "child_process";
2
- import fs from "fs";
3
- import path from "path";
4
- import typia from "typia";
5
-
6
- import { INestiaConfig } from "../../INestiaConfig";
7
-
8
- export namespace SdkDistributionComposer {
9
- export const compose = async (config: INestiaConfig, websocket: boolean) => {
10
- if (!fs.existsSync(config.distribute!))
11
- await fs.promises.mkdir(config.distribute!);
12
-
13
- const root: string = process.cwd();
14
- const output: string = path.resolve(config.output!);
15
- process.chdir(config.distribute!);
16
-
17
- const exit = () => process.chdir(root);
18
- if (await configured()) return exit();
19
-
20
- // COPY FILES
21
- console.log("Composing SDK distribution environments...");
22
- for (const file of await fs.promises.readdir(BUNDLE))
23
- await fs.promises.copyFile(`${BUNDLE}/${file}`, file);
24
-
25
- // CONFIGURE PATHS
26
- for (const file of ["package.json", "tsconfig.json"])
27
- await replace({ root, output })(file);
28
-
29
- // INSTALL PACKAGES
30
- const versions: IDependencies = await dependencies();
31
- execute("npm install --save-dev rimraf");
32
- execute(
33
- `npm install --save @nestia/fetcher@${versions["@nestia/fetcher"]}`,
34
- );
35
- execute(`npm install --save typia@${versions["typia"]}`);
36
- if (websocket) execute(`npm install --save tgrid@${versions["tgrid"]}`);
37
- execute("npx typia setup --manager npm");
38
-
39
- exit();
40
- };
41
-
42
- const configured = async (): Promise<boolean> =>
43
- ["package.json", "tsconfig.json"].every(fs.existsSync) &&
44
- (await (async () => {
45
- const content = JSON.parse(
46
- await fs.promises.readFile("package.json", "utf8"),
47
- );
48
- return !!content.dependencies?.["@nestia/fetcher"];
49
- })());
50
-
51
- const execute = (command: string) => {
52
- console.log(` - ${command}`);
53
- cp.execSync(command, { stdio: "ignore" });
54
- };
55
-
56
- const replace =
57
- (props: { root: string; output: string }) =>
58
- async (file: string): Promise<void> => {
59
- const relative = (from: string) => (to: string) =>
60
- path.relative(from, to).split("\\").join("/");
61
- const root: string = relative(process.cwd())(props.root);
62
- const output: string = relative(process.cwd())(props.output);
63
- const current: string = relative(props.root)(process.cwd());
64
-
65
- const content: string = await fs.promises.readFile(file, "utf8");
66
- await fs.promises.writeFile(
67
- file,
68
- content
69
- .split("${root}")
70
- .join(root)
71
- .split("${output}")
72
- .join(output)
73
- .split("${current}")
74
- .join(current),
75
- "utf8",
76
- );
77
- };
78
-
79
- const dependencies = async (): Promise<IDependencies> => {
80
- const content: string = await fs.promises.readFile(
81
- __dirname + "/../../../package.json",
82
- "utf8",
83
- );
84
- const json: {
85
- dependencies: Record<string, string>;
86
- devDependencies: Record<string, string>;
87
- } = JSON.parse(content);
88
- return typia.assert<IDependencies>({
89
- ...json.devDependencies,
90
- ...json.dependencies,
91
- });
92
- };
93
- }
94
-
95
- interface IDependencies {
96
- "@nestia/fetcher": string;
97
- typia: string;
98
- tgrid: string;
99
- }
100
- const BUNDLE = __dirname + "/../../../assets/bundle/distribute";
1
+ import cp from "child_process";
2
+ import fs from "fs";
3
+ import path from "path";
4
+ import typia from "typia";
5
+
6
+ import { INestiaConfig } from "../../INestiaConfig";
7
+
8
+ export namespace SdkDistributionComposer {
9
+ export const compose = async (config: INestiaConfig, websocket: boolean) => {
10
+ if (!fs.existsSync(config.distribute!))
11
+ await fs.promises.mkdir(config.distribute!);
12
+
13
+ const root: string = process.cwd();
14
+ const output: string = path.resolve(config.output!);
15
+ process.chdir(config.distribute!);
16
+
17
+ const exit = () => process.chdir(root);
18
+ if (await configured()) return exit();
19
+
20
+ // COPY FILES
21
+ console.log("Composing SDK distribution environments...");
22
+ for (const file of await fs.promises.readdir(BUNDLE))
23
+ await fs.promises.copyFile(`${BUNDLE}/${file}`, file);
24
+
25
+ // CONFIGURE PATHS
26
+ for (const file of ["package.json", "tsconfig.json"])
27
+ await replace({ root, output })(file);
28
+
29
+ // INSTALL PACKAGES
30
+ const versions: IDependencies = await dependencies();
31
+ execute("npm install --save-dev rimraf");
32
+ execute(
33
+ `npm install --save @nestia/fetcher@${versions["@nestia/fetcher"]}`,
34
+ );
35
+ execute(`npm install --save typia@${versions["typia"]}`);
36
+ if (websocket) execute(`npm install --save tgrid@${versions["tgrid"]}`);
37
+ execute("npx typia setup --manager npm");
38
+
39
+ exit();
40
+ };
41
+
42
+ const configured = async (): Promise<boolean> =>
43
+ ["package.json", "tsconfig.json"].every(fs.existsSync) &&
44
+ (await (async () => {
45
+ const content = JSON.parse(
46
+ await fs.promises.readFile("package.json", "utf8"),
47
+ );
48
+ return !!content.dependencies?.["@nestia/fetcher"];
49
+ })());
50
+
51
+ const execute = (command: string) => {
52
+ console.log(` - ${command}`);
53
+ cp.execSync(command, { stdio: "ignore" });
54
+ };
55
+
56
+ const replace =
57
+ (props: { root: string; output: string }) =>
58
+ async (file: string): Promise<void> => {
59
+ const relative = (from: string) => (to: string) =>
60
+ path.relative(from, to).split("\\").join("/");
61
+ const root: string = relative(process.cwd())(props.root);
62
+ const output: string = relative(process.cwd())(props.output);
63
+ const current: string = relative(props.root)(process.cwd());
64
+
65
+ const content: string = await fs.promises.readFile(file, "utf8");
66
+ await fs.promises.writeFile(
67
+ file,
68
+ content
69
+ .split("${root}")
70
+ .join(root)
71
+ .split("${output}")
72
+ .join(output)
73
+ .split("${current}")
74
+ .join(current),
75
+ "utf8",
76
+ );
77
+ };
78
+
79
+ const dependencies = async (): Promise<IDependencies> => {
80
+ const content: string = await fs.promises.readFile(
81
+ __dirname + "/../../../package.json",
82
+ "utf8",
83
+ );
84
+ const json: {
85
+ dependencies: Record<string, string>;
86
+ devDependencies: Record<string, string>;
87
+ } = JSON.parse(content);
88
+ return typia.assert<IDependencies>({
89
+ ...json.devDependencies,
90
+ ...json.dependencies,
91
+ });
92
+ };
93
+ }
94
+
95
+ interface IDependencies {
96
+ "@nestia/fetcher": string;
97
+ typia: string;
98
+ tgrid: string;
99
+ }
100
+ const BUNDLE = __dirname + "/../../../assets/bundle/distribute";