@nestia/sdk 3.0.0 → 3.0.1-dev.20240412

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestia/sdk",
3
- "version": "3.0.0",
3
+ "version": "3.0.1-dev.20240412",
4
4
  "description": "Nestia SDK and Swagger generator",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
@@ -32,8 +32,8 @@
32
32
  },
33
33
  "homepage": "https://nestia.io",
34
34
  "dependencies": {
35
- "@nestia/fetcher": "^3.0.0",
36
- "@samchon/openapi": "^0.1.2",
35
+ "@nestia/fetcher": "^3.0.1-dev.20240412",
36
+ "@samchon/openapi": "^0.1.4",
37
37
  "cli": "^1.0.1",
38
38
  "get-function-location": "^2.0.0",
39
39
  "glob": "^7.2.0",
@@ -43,15 +43,15 @@
43
43
  "tsconfig-paths": "^4.1.1",
44
44
  "ts-node": ">=10.6.0",
45
45
  "tstl": "^3.0.0",
46
- "typia": "^6.0.0"
46
+ "typia": "^6.0.1"
47
47
  },
48
48
  "peerDependencies": {
49
- "@nestia/fetcher": ">=3.0.0",
49
+ "@nestia/fetcher": ">=3.0.1-dev.20240412",
50
50
  "@nestjs/common": ">=7.0.1",
51
51
  "@nestjs/core": ">=7.0.1",
52
52
  "reflect-metadata": ">=0.1.12",
53
53
  "ts-node": ">=10.6.0",
54
- "typia": ">=6.0.0 <7.0.0"
54
+ "typia": ">=6.0.1 <7.0.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@nestia/e2e": "^0.4.1",
@@ -1,148 +1,148 @@
1
- import path from "path";
2
- import ts from "typescript";
3
- import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
- import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
- import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
-
7
- import { IController } from "../structures/IController";
8
- import { INestiaProject } from "../structures/INestiaProject";
9
- import { IRoute } from "../structures/IRoute";
10
- import { ITypeTuple } from "../structures/ITypeTuple";
11
- import { GenericAnalyzer } from "./GenericAnalyzer";
12
- import { ImportAnalyzer } from "./ImportAnalyzer";
13
-
14
- export namespace ExceptionAnalyzer {
15
- export const analyze =
16
- (project: INestiaProject) =>
17
- (
18
- genericDict: GenericAnalyzer.Dictionary,
19
- importDict: ImportAnalyzer.Dictionary,
20
- ) =>
21
- (controller: IController, func: IController.IFunction) =>
22
- (
23
- declaration: ts.MethodDeclaration,
24
- ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
25
- const output: Record<
26
- number | "2XX" | "3XX" | "4XX" | "5XX",
27
- IRoute.IOutput
28
- > = {} as any;
29
- for (const decorator of declaration.modifiers ?? [])
30
- if (ts.isDecorator(decorator))
31
- analyzeTyped(project)(genericDict, importDict)(controller, func)(
32
- output,
33
- )(decorator);
34
- return output;
35
- };
36
-
37
- const analyzeTyped =
38
- (project: INestiaProject) =>
39
- (
40
- genericDict: GenericAnalyzer.Dictionary,
41
- importDict: ImportAnalyzer.Dictionary,
42
- ) =>
43
- (controller: IController, func: IController.IFunction) =>
44
- (output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
45
- (decorator: ts.Decorator): boolean => {
46
- // CHECK DECORATOR
47
- if (!ts.isCallExpression(decorator.expression)) return false;
48
- else if ((decorator.expression.typeArguments ?? []).length !== 1)
49
- return false;
50
-
51
- // CHECK SIGNATURE
52
- const signature: ts.Signature | undefined =
53
- project.checker.getResolvedSignature(decorator.expression);
54
- if (!signature || !signature.declaration) return false;
55
- else if (
56
- path
57
- .resolve(signature.declaration.getSourceFile().fileName)
58
- .indexOf(TYPED_EXCEPTION_PATH) === -1
59
- )
60
- return false;
61
-
62
- // GET TYPE INFO
63
- const status: string | null = getStatus(project.checker)(
64
- decorator.expression.arguments[0] ?? null,
65
- );
66
- if (status === null) return false;
67
-
68
- const node: ts.TypeNode = decorator.expression.typeArguments![0];
69
- const type: ts.Type = project.checker.getTypeFromTypeNode(node);
70
- if (type.isTypeParameter()) {
71
- project.errors.push({
72
- file: controller.file,
73
- controller: controller.name,
74
- function: func.name,
75
- message: "TypedException() without generic argument specification.",
76
- });
77
- return false;
78
- }
79
-
80
- const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
81
- project.checker,
82
- genericDict,
83
- importDict,
84
- type,
85
- );
86
- if (
87
- tuple === null ||
88
- (project.config.clone !== true &&
89
- (tuple.typeName === "__type" || tuple.typeName === "__object"))
90
- ) {
91
- project.errors.push({
92
- file: controller.file,
93
- controller: controller.name,
94
- function: func.name,
95
- message: "TypeException() with implicit (unnamed) type.",
96
- });
97
- return false;
98
- }
99
-
100
- // DO ASSIGN
101
- const matched: IController.IException[] = Object.entries(func.exceptions)
102
- .filter(([key]) => status === key)
103
- .map(([_key, value]) => value);
104
- for (const m of matched)
105
- output[m.status] = {
106
- type: tuple.type,
107
- typeName: tuple.typeName,
108
- contentType: "application/json",
109
- description: m.description,
110
- };
111
- return true;
112
- };
113
-
114
- const getStatus =
115
- (checker: ts.TypeChecker) =>
116
- (expression: ts.Expression | null): string | null => {
117
- if (expression === null) return null;
118
-
119
- const type: ts.Type = checker.getTypeAtLocation(expression);
120
- const result = MetadataFactory.analyze(checker)({
121
- escape: true,
122
- constant: true,
123
- absorb: true,
124
- })(new MetadataCollection())(type);
125
- if (false === result.success) return null;
126
-
127
- const meta: Metadata = result.data;
128
- if (meta.constants.length === 1)
129
- return meta.constants[0].values[0].value.toString();
130
- else if (meta.escaped && meta.escaped.returns.constants.length === 1)
131
- return meta.escaped.returns.constants[0].values[0].value.toString();
132
- else if (ts.isStringLiteral(expression)) return expression.text;
133
- else if (ts.isNumericLiteral(expression)) {
134
- const value: number = Number(expression.text.split("_").join(""));
135
- if (false === isNaN(value)) return value.toString();
136
- }
137
- return null;
138
- };
139
- }
140
-
141
- const TYPED_EXCEPTION_PATH = path.join(
142
- "node_modules",
143
- "@nestia",
144
- "core",
145
- "lib",
146
- "decorators",
147
- "TypedException.d.ts",
148
- );
1
+ import path from "path";
2
+ import ts from "typescript";
3
+ import { MetadataCollection } from "typia/lib/factories/MetadataCollection";
4
+ import { MetadataFactory } from "typia/lib/factories/MetadataFactory";
5
+ import { Metadata } from "typia/lib/schemas/metadata/Metadata";
6
+
7
+ import { IController } from "../structures/IController";
8
+ import { INestiaProject } from "../structures/INestiaProject";
9
+ import { IRoute } from "../structures/IRoute";
10
+ import { ITypeTuple } from "../structures/ITypeTuple";
11
+ import { GenericAnalyzer } from "./GenericAnalyzer";
12
+ import { ImportAnalyzer } from "./ImportAnalyzer";
13
+
14
+ export namespace ExceptionAnalyzer {
15
+ export const analyze =
16
+ (project: INestiaProject) =>
17
+ (
18
+ genericDict: GenericAnalyzer.Dictionary,
19
+ importDict: ImportAnalyzer.Dictionary,
20
+ ) =>
21
+ (controller: IController, func: IController.IFunction) =>
22
+ (
23
+ declaration: ts.MethodDeclaration,
24
+ ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput> => {
25
+ const output: Record<
26
+ number | "2XX" | "3XX" | "4XX" | "5XX",
27
+ IRoute.IOutput
28
+ > = {} as any;
29
+ for (const decorator of declaration.modifiers ?? [])
30
+ if (ts.isDecorator(decorator))
31
+ analyzeTyped(project)(genericDict, importDict)(controller, func)(
32
+ output,
33
+ )(decorator);
34
+ return output;
35
+ };
36
+
37
+ const analyzeTyped =
38
+ (project: INestiaProject) =>
39
+ (
40
+ genericDict: GenericAnalyzer.Dictionary,
41
+ importDict: ImportAnalyzer.Dictionary,
42
+ ) =>
43
+ (controller: IController, func: IController.IFunction) =>
44
+ (output: Record<number | "2XX" | "3XX" | "4XX" | "5XX", IRoute.IOutput>) =>
45
+ (decorator: ts.Decorator): boolean => {
46
+ // CHECK DECORATOR
47
+ if (!ts.isCallExpression(decorator.expression)) return false;
48
+ else if ((decorator.expression.typeArguments ?? []).length !== 1)
49
+ return false;
50
+
51
+ // CHECK SIGNATURE
52
+ const signature: ts.Signature | undefined =
53
+ project.checker.getResolvedSignature(decorator.expression);
54
+ if (!signature || !signature.declaration) return false;
55
+ else if (
56
+ path
57
+ .resolve(signature.declaration.getSourceFile().fileName)
58
+ .indexOf(TYPED_EXCEPTION_PATH) === -1
59
+ )
60
+ return false;
61
+
62
+ // GET TYPE INFO
63
+ const status: string | null = getStatus(project.checker)(
64
+ decorator.expression.arguments[0] ?? null,
65
+ );
66
+ if (status === null) return false;
67
+
68
+ const node: ts.TypeNode = decorator.expression.typeArguments![0];
69
+ const type: ts.Type = project.checker.getTypeFromTypeNode(node);
70
+ if (type.isTypeParameter()) {
71
+ project.errors.push({
72
+ file: controller.file,
73
+ controller: controller.name,
74
+ function: func.name,
75
+ message: "TypedException() without generic argument specification.",
76
+ });
77
+ return false;
78
+ }
79
+
80
+ const tuple: ITypeTuple | null = ImportAnalyzer.analyze(
81
+ project.checker,
82
+ genericDict,
83
+ importDict,
84
+ type,
85
+ );
86
+ if (
87
+ tuple === null ||
88
+ (project.config.clone !== true &&
89
+ (tuple.typeName === "__type" || tuple.typeName === "__object"))
90
+ ) {
91
+ project.errors.push({
92
+ file: controller.file,
93
+ controller: controller.name,
94
+ function: func.name,
95
+ message: "TypeException() with implicit (unnamed) type.",
96
+ });
97
+ return false;
98
+ }
99
+
100
+ // DO ASSIGN
101
+ const matched: IController.IException[] = Object.entries(func.exceptions)
102
+ .filter(([key]) => status === key)
103
+ .map(([_key, value]) => value);
104
+ for (const m of matched)
105
+ output[m.status] = {
106
+ type: tuple.type,
107
+ typeName: tuple.typeName,
108
+ contentType: "application/json",
109
+ description: m.description,
110
+ };
111
+ return true;
112
+ };
113
+
114
+ const getStatus =
115
+ (checker: ts.TypeChecker) =>
116
+ (expression: ts.Expression | null): string | null => {
117
+ if (expression === null) return null;
118
+
119
+ const type: ts.Type = checker.getTypeAtLocation(expression);
120
+ const result = MetadataFactory.analyze(checker)({
121
+ escape: true,
122
+ constant: true,
123
+ absorb: true,
124
+ })(new MetadataCollection())(type);
125
+ if (false === result.success) return null;
126
+
127
+ const meta: Metadata = result.data;
128
+ if (meta.constants.length === 1)
129
+ return meta.constants[0].values[0].value.toString();
130
+ else if (meta.escaped && meta.escaped.returns.constants.length === 1)
131
+ return meta.escaped.returns.constants[0].values[0].value.toString();
132
+ else if (ts.isStringLiteral(expression)) return expression.text;
133
+ else if (ts.isNumericLiteral(expression)) {
134
+ const value: number = Number(expression.text.split("_").join(""));
135
+ if (false === isNaN(value)) return value.toString();
136
+ }
137
+ return null;
138
+ };
139
+ }
140
+
141
+ const TYPED_EXCEPTION_PATH = path.join(
142
+ "node_modules",
143
+ "@nestia",
144
+ "core",
145
+ "lib",
146
+ "decorators",
147
+ "TypedException.d.ts",
148
+ );