@nestia/core 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.
- package/package.json +4 -4
- package/src/decorators/EncryptedBody.ts +105 -105
- package/src/decorators/EncryptedModule.ts +96 -96
- package/src/decorators/PlainBody.ts +75 -75
- package/src/decorators/SwaggerCustomizer.ts +116 -116
- package/src/decorators/TypedBody.ts +62 -62
- package/src/decorators/TypedException.ts +90 -90
- package/src/decorators/TypedFormData.ts +219 -219
- package/src/decorators/TypedQuery.ts +251 -251
- package/src/decorators/TypedRoute.ts +144 -144
- package/src/decorators/internal/get_path_and_querify.ts +106 -106
- package/src/decorators/internal/load_controller.ts +51 -51
- package/src/decorators/internal/validate_request_body.ts +72 -72
- package/src/decorators/internal/validate_request_form_data.ts +75 -75
- package/src/decorators/internal/validate_request_headers.ts +83 -83
- package/src/decorators/internal/validate_request_query.ts +71 -71
- package/src/module.ts +16 -16
- package/src/options/IRequestFormDataProps.ts +27 -27
- package/src/programmers/PlainBodyProgrammer.ts +52 -52
- package/src/programmers/TypedExceptionProgrammer.ts +71 -71
- package/src/programmers/TypedFormDataBodyProgrammer.ts +108 -108
- package/src/programmers/http/HttpQuerifyProgrammer.ts +96 -96
- package/src/structures/ISwagger.ts +91 -91
- package/src/structures/ISwaggerComponents.ts +29 -29
- package/src/structures/ISwaggerInfo.ts +80 -80
- package/src/structures/ISwaggerRoute.ts +50 -50
- package/src/structures/ISwaggerSecurityScheme.ts +65 -65
- package/src/transformers/NodeTransformer.ts +16 -16
- package/src/transformers/ParameterDecoratorTransformer.ts +120 -120
- package/src/transformers/TypedExceptionTransformer.ts +48 -48
- package/src/transformers/TypedRouteTransformer.ts +88 -88
- package/src/utils/Singleton.ts +20 -20
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
-
import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
|
|
6
|
-
import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
|
|
7
|
-
|
|
8
|
-
export namespace TypedRouteTransformer {
|
|
9
|
-
export const transform =
|
|
10
|
-
(project: INestiaTransformProject) =>
|
|
11
|
-
(type: ts.Type) =>
|
|
12
|
-
(decorator: ts.Decorator): ts.Decorator => {
|
|
13
|
-
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
14
|
-
|
|
15
|
-
// CHECK SIGNATURE
|
|
16
|
-
const signature: ts.Signature | undefined =
|
|
17
|
-
project.checker.getResolvedSignature(decorator.expression);
|
|
18
|
-
if (!signature || !signature.declaration) return decorator;
|
|
19
|
-
|
|
20
|
-
// CHECK TO BE TRANSFORMED
|
|
21
|
-
const modulo = (() => {
|
|
22
|
-
// CHECK FILENAME
|
|
23
|
-
const location: string = path.resolve(
|
|
24
|
-
signature.declaration.getSourceFile().fileName,
|
|
25
|
-
);
|
|
26
|
-
if (
|
|
27
|
-
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
28
|
-
SRC_PATHS.every((str) => location !== str)
|
|
29
|
-
)
|
|
30
|
-
return null;
|
|
31
|
-
|
|
32
|
-
// CHECK DUPLICATE BOOSTER
|
|
33
|
-
if (decorator.expression.arguments.length >= 2) return false;
|
|
34
|
-
else if (decorator.expression.arguments.length === 1) {
|
|
35
|
-
const last: ts.Expression =
|
|
36
|
-
decorator.expression.arguments[
|
|
37
|
-
decorator.expression.arguments.length - 1
|
|
38
|
-
];
|
|
39
|
-
const type: ts.Type = project.checker.getTypeAtLocation(last);
|
|
40
|
-
if (isObject(project.checker)(type)) return false;
|
|
41
|
-
}
|
|
42
|
-
return location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
|
|
43
|
-
? "TypedQuery"
|
|
44
|
-
: "TypedRoute";
|
|
45
|
-
})();
|
|
46
|
-
if (modulo === null) return decorator;
|
|
47
|
-
|
|
48
|
-
// CHECK TYPE NODE
|
|
49
|
-
const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
|
|
50
|
-
type,
|
|
51
|
-
undefined,
|
|
52
|
-
undefined,
|
|
53
|
-
);
|
|
54
|
-
if (typeNode === undefined) return decorator;
|
|
55
|
-
|
|
56
|
-
// DO TRANSFORM
|
|
57
|
-
return ts.factory.createDecorator(
|
|
58
|
-
ts.factory.updateCallExpression(
|
|
59
|
-
decorator.expression,
|
|
60
|
-
decorator.expression.expression,
|
|
61
|
-
decorator.expression.typeArguments,
|
|
62
|
-
[
|
|
63
|
-
...decorator.expression.arguments,
|
|
64
|
-
(modulo === "TypedQuery"
|
|
65
|
-
? TypedQueryRouteProgrammer
|
|
66
|
-
: TypedRouteProgrammer
|
|
67
|
-
).generate(project)(decorator.expression.expression)(type),
|
|
68
|
-
],
|
|
69
|
-
),
|
|
70
|
-
);
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const isObject =
|
|
74
|
-
(checker: ts.TypeChecker) =>
|
|
75
|
-
(type: ts.Type): boolean =>
|
|
76
|
-
(type.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
77
|
-
!(checker as any).isTupleType(type) &&
|
|
78
|
-
!(checker as any).isArrayType(type) &&
|
|
79
|
-
!(checker as any).isArrayLikeType(type);
|
|
80
|
-
|
|
81
|
-
const CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
|
|
82
|
-
const LIB_PATHS = CLASSES.map((cla) =>
|
|
83
|
-
path.join("@nestia", "core", "lib", "decorators", `${cla}.d.ts`),
|
|
84
|
-
);
|
|
85
|
-
const SRC_PATHS = CLASSES.map((cla) =>
|
|
86
|
-
path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
|
|
87
|
-
);
|
|
88
|
-
}
|
|
1
|
+
import path from "path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformProject } from "../options/INestiaTransformProject";
|
|
5
|
+
import { TypedQueryRouteProgrammer } from "../programmers/TypedQueryRouteProgrammer";
|
|
6
|
+
import { TypedRouteProgrammer } from "../programmers/TypedRouteProgrammer";
|
|
7
|
+
|
|
8
|
+
export namespace TypedRouteTransformer {
|
|
9
|
+
export const transform =
|
|
10
|
+
(project: INestiaTransformProject) =>
|
|
11
|
+
(type: ts.Type) =>
|
|
12
|
+
(decorator: ts.Decorator): ts.Decorator => {
|
|
13
|
+
if (!ts.isCallExpression(decorator.expression)) return decorator;
|
|
14
|
+
|
|
15
|
+
// CHECK SIGNATURE
|
|
16
|
+
const signature: ts.Signature | undefined =
|
|
17
|
+
project.checker.getResolvedSignature(decorator.expression);
|
|
18
|
+
if (!signature || !signature.declaration) return decorator;
|
|
19
|
+
|
|
20
|
+
// CHECK TO BE TRANSFORMED
|
|
21
|
+
const modulo = (() => {
|
|
22
|
+
// CHECK FILENAME
|
|
23
|
+
const location: string = path.resolve(
|
|
24
|
+
signature.declaration.getSourceFile().fileName,
|
|
25
|
+
);
|
|
26
|
+
if (
|
|
27
|
+
LIB_PATHS.every((str) => location.indexOf(str) === -1) &&
|
|
28
|
+
SRC_PATHS.every((str) => location !== str)
|
|
29
|
+
)
|
|
30
|
+
return null;
|
|
31
|
+
|
|
32
|
+
// CHECK DUPLICATE BOOSTER
|
|
33
|
+
if (decorator.expression.arguments.length >= 2) return false;
|
|
34
|
+
else if (decorator.expression.arguments.length === 1) {
|
|
35
|
+
const last: ts.Expression =
|
|
36
|
+
decorator.expression.arguments[
|
|
37
|
+
decorator.expression.arguments.length - 1
|
|
38
|
+
];
|
|
39
|
+
const type: ts.Type = project.checker.getTypeAtLocation(last);
|
|
40
|
+
if (isObject(project.checker)(type)) return false;
|
|
41
|
+
}
|
|
42
|
+
return location.split(path.sep).at(-1)?.split(".")[0] === "TypedQuery"
|
|
43
|
+
? "TypedQuery"
|
|
44
|
+
: "TypedRoute";
|
|
45
|
+
})();
|
|
46
|
+
if (modulo === null) return decorator;
|
|
47
|
+
|
|
48
|
+
// CHECK TYPE NODE
|
|
49
|
+
const typeNode: ts.TypeNode | undefined = project.checker.typeToTypeNode(
|
|
50
|
+
type,
|
|
51
|
+
undefined,
|
|
52
|
+
undefined,
|
|
53
|
+
);
|
|
54
|
+
if (typeNode === undefined) return decorator;
|
|
55
|
+
|
|
56
|
+
// DO TRANSFORM
|
|
57
|
+
return ts.factory.createDecorator(
|
|
58
|
+
ts.factory.updateCallExpression(
|
|
59
|
+
decorator.expression,
|
|
60
|
+
decorator.expression.expression,
|
|
61
|
+
decorator.expression.typeArguments,
|
|
62
|
+
[
|
|
63
|
+
...decorator.expression.arguments,
|
|
64
|
+
(modulo === "TypedQuery"
|
|
65
|
+
? TypedQueryRouteProgrammer
|
|
66
|
+
: TypedRouteProgrammer
|
|
67
|
+
).generate(project)(decorator.expression.expression)(type),
|
|
68
|
+
],
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const isObject =
|
|
74
|
+
(checker: ts.TypeChecker) =>
|
|
75
|
+
(type: ts.Type): boolean =>
|
|
76
|
+
(type.getFlags() & ts.TypeFlags.Object) !== 0 &&
|
|
77
|
+
!(checker as any).isTupleType(type) &&
|
|
78
|
+
!(checker as any).isArrayType(type) &&
|
|
79
|
+
!(checker as any).isArrayLikeType(type);
|
|
80
|
+
|
|
81
|
+
const CLASSES = ["EncryptedRoute", "TypedRoute", "TypedQuery"];
|
|
82
|
+
const LIB_PATHS = CLASSES.map((cla) =>
|
|
83
|
+
path.join("@nestia", "core", "lib", "decorators", `${cla}.d.ts`),
|
|
84
|
+
);
|
|
85
|
+
const SRC_PATHS = CLASSES.map((cla) =>
|
|
86
|
+
path.resolve(path.join(__dirname, "..", "decorators", `${cla}.ts`)),
|
|
87
|
+
);
|
|
88
|
+
}
|
package/src/utils/Singleton.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @internal
|
|
3
|
-
*/
|
|
4
|
-
export class Singleton<T> {
|
|
5
|
-
private value_: T | object;
|
|
6
|
-
|
|
7
|
-
public constructor(private readonly closure_: () => T) {
|
|
8
|
-
this.value_ = NOT_MOUNTED_YET;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
public get(): T {
|
|
12
|
-
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
13
|
-
return this.value_ as T;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
const NOT_MOUNTED_YET = {};
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/
|
|
4
|
+
export class Singleton<T> {
|
|
5
|
+
private value_: T | object;
|
|
6
|
+
|
|
7
|
+
public constructor(private readonly closure_: () => T) {
|
|
8
|
+
this.value_ = NOT_MOUNTED_YET;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get(): T {
|
|
12
|
+
if (this.value_ === NOT_MOUNTED_YET) this.value_ = this.closure_();
|
|
13
|
+
return this.value_ as T;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
const NOT_MOUNTED_YET = {};
|