@nestia/core 11.0.0-dev.20260313-5 → 11.0.0

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 (60) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +93 -93
  3. package/lib/decorators/NoTransformConfigurationError.d.ts +1 -24
  4. package/lib/decorators/NoTransformConfigurationError.js +2 -0
  5. package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
  6. package/lib/decorators/doNotThrowTransformError.d.ts +1 -0
  7. package/lib/decorators/doNotThrowTransformError.js +9 -0
  8. package/lib/decorators/doNotThrowTransformError.js.map +1 -0
  9. package/lib/module.d.ts +1 -1
  10. package/lib/module.js +1 -1
  11. package/lib/module.js.map +1 -1
  12. package/lib/options/INestiaTransformOptions.d.ts +1 -1
  13. package/lib/programmers/PlainBodyProgrammer.js +1 -1
  14. package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
  15. package/lib/programmers/TypedBodyProgrammer.js +6 -3
  16. package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
  17. package/lib/programmers/TypedQueryBodyProgrammer.js +9 -4
  18. package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
  19. package/lib/programmers/TypedQueryProgrammer.js +9 -4
  20. package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
  21. package/lib/programmers/TypedQueryRouteProgrammer.js +14 -8
  22. package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
  23. package/lib/programmers/TypedRouteProgrammer.js +11 -6
  24. package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
  25. package/package.json +8 -8
  26. package/src/adaptors/WebSocketAdaptor.ts +429 -429
  27. package/src/decorators/EncryptedBody.ts +96 -96
  28. package/src/decorators/EncryptedController.ts +40 -40
  29. package/src/decorators/EncryptedModule.ts +98 -98
  30. package/src/decorators/EncryptedRoute.ts +212 -212
  31. package/src/decorators/HumanRoute.ts +21 -21
  32. package/src/decorators/NoTransformConfigurationError.ts +37 -34
  33. package/src/decorators/SwaggerCustomizer.ts +97 -97
  34. package/src/decorators/TypedFormData.ts +187 -187
  35. package/src/decorators/TypedRoute.ts +196 -196
  36. package/src/decorators/doNotThrowTransformError.ts +5 -0
  37. package/src/decorators/internal/headers_to_object.ts +11 -11
  38. package/src/module.ts +23 -23
  39. package/src/options/INestiaTransformOptions.ts +34 -34
  40. package/src/options/INestiaTransformProject.ts +10 -10
  41. package/src/programmers/PlainBodyProgrammer.ts +72 -72
  42. package/src/programmers/TypedBodyProgrammer.ts +148 -144
  43. package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
  44. package/src/programmers/TypedHeadersProgrammer.ts +65 -65
  45. package/src/programmers/TypedParamProgrammer.ts +33 -33
  46. package/src/programmers/TypedQueryBodyProgrammer.ts +113 -111
  47. package/src/programmers/TypedQueryProgrammer.ts +115 -113
  48. package/src/programmers/TypedQueryRouteProgrammer.ts +107 -104
  49. package/src/programmers/TypedRouteProgrammer.ts +103 -96
  50. package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
  51. package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
  52. package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
  53. package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
  54. package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
  55. package/src/transform.ts +35 -35
  56. package/src/transformers/FileTransformer.ts +109 -109
  57. package/src/transformers/MethodTransformer.ts +103 -103
  58. package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
  59. package/src/transformers/TypedRouteTransformer.ts +85 -85
  60. package/src/transformers/WebSocketRouteTransformer.ts +120 -120
@@ -1,21 +1,21 @@
1
- import { MetadataSchema } from "@typia/core";
2
-
3
- export namespace CoreMetadataUtil {
4
- export const atomics = (
5
- meta: MetadataSchema,
6
- ): Set<"boolean" | "bigint" | "number" | "string"> =>
7
- new Set([
8
- ...meta.atomics.map((a) => a.type),
9
- ...meta.constants.map((c) => c.type),
10
- ...(meta.templates.length ? (["string"] as const) : []),
11
- ]);
12
-
13
- export const isUnion = (meta: MetadataSchema): boolean =>
14
- atomics(meta).size +
15
- meta.arrays.length +
16
- meta.tuples.length +
17
- meta.natives.length +
18
- meta.maps.length +
19
- meta.objects.length >
20
- 1;
21
- }
1
+ import { MetadataSchema } from "@typia/core";
2
+
3
+ export namespace CoreMetadataUtil {
4
+ export const atomics = (
5
+ meta: MetadataSchema,
6
+ ): Set<"boolean" | "bigint" | "number" | "string"> =>
7
+ new Set([
8
+ ...meta.atomics.map((a) => a.type),
9
+ ...meta.constants.map((c) => c.type),
10
+ ...(meta.templates.length ? (["string"] as const) : []),
11
+ ]);
12
+
13
+ export const isUnion = (meta: MetadataSchema): boolean =>
14
+ atomics(meta).size +
15
+ meta.arrays.length +
16
+ meta.tuples.length +
17
+ meta.natives.length +
18
+ meta.maps.length +
19
+ meta.objects.length >
20
+ 1;
21
+ }
package/src/transform.ts CHANGED
@@ -1,35 +1,35 @@
1
- import { ITypiaContext } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
- import { FileTransformer } from "./transformers/FileTransformer";
6
-
7
- export const transform = (
8
- program: ts.Program,
9
- options: INestiaTransformOptions | undefined,
10
- extras: ITypiaContext["extras"],
11
- ): ts.TransformerFactory<ts.SourceFile> => {
12
- const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
13
- const strict: boolean =
14
- compilerOptions.strictNullChecks !== undefined
15
- ? !!compilerOptions.strictNullChecks
16
- : !!compilerOptions.strict;
17
- if (strict === false)
18
- extras.addDiagnostic({
19
- category: ts.DiagnosticCategory.Error,
20
- code: "(@nestia/core)" as any,
21
- file: undefined,
22
- start: undefined,
23
- length: undefined,
24
- messageText: "strict mode is required.",
25
- });
26
- return FileTransformer.transform({
27
- program,
28
- compilerOptions,
29
- checker: program.getTypeChecker(),
30
- printer: ts.createPrinter(),
31
- options: options ?? {},
32
- extras,
33
- });
34
- };
35
- export default transform;
1
+ import { ITypiaContext } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformOptions } from "./options/INestiaTransformOptions";
5
+ import { FileTransformer } from "./transformers/FileTransformer";
6
+
7
+ export const transform = (
8
+ program: ts.Program,
9
+ options: INestiaTransformOptions | undefined,
10
+ extras: ITypiaContext["extras"],
11
+ ): ts.TransformerFactory<ts.SourceFile> => {
12
+ const compilerOptions: ts.CompilerOptions = program.getCompilerOptions();
13
+ const strict: boolean =
14
+ compilerOptions.strictNullChecks !== undefined
15
+ ? !!compilerOptions.strictNullChecks
16
+ : !!compilerOptions.strict;
17
+ if (strict === false)
18
+ extras.addDiagnostic({
19
+ category: ts.DiagnosticCategory.Error,
20
+ code: "(@nestia/core)" as any,
21
+ file: undefined,
22
+ start: undefined,
23
+ length: undefined,
24
+ messageText: "strict mode is required.",
25
+ });
26
+ return FileTransformer.transform({
27
+ program,
28
+ compilerOptions,
29
+ checker: program.getTypeChecker(),
30
+ printer: ts.createPrinter(),
31
+ options: options ?? {},
32
+ extras,
33
+ });
34
+ };
35
+ export default transform;
@@ -1,109 +1,109 @@
1
- import { ImportProgrammer, TransformerError } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
- import { NodeTransformer } from "./NodeTransformer";
6
-
7
- export namespace FileTransformer {
8
- export const transform =
9
- (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
10
- (transformer: ts.TransformationContext) =>
11
- (file: ts.SourceFile): ts.SourceFile => {
12
- if (file.isDeclarationFile) return file;
13
- const importer = new ImportProgrammer({
14
- internalPrefix: "nestia_core_transform",
15
- });
16
- file = ts.visitEachChild(
17
- file,
18
- (node) =>
19
- iterate_node({
20
- context: {
21
- ...context,
22
- transformer,
23
- importer,
24
- },
25
- file,
26
- node,
27
- }),
28
- transformer,
29
- );
30
- const index: number = find_import_injection_index(file);
31
- return ts.factory.updateSourceFile(
32
- file,
33
- [
34
- ...file.statements.slice(0, index),
35
- ...importer.toStatements(),
36
- ...file.statements.slice(index),
37
- ],
38
- false,
39
- file.referencedFiles,
40
- file.typeReferenceDirectives,
41
- file.hasNoDefaultLib,
42
- file.libReferenceDirectives,
43
- );
44
- };
45
-
46
- const iterate_node = (props: {
47
- context: INestiaTransformContext;
48
- file: ts.SourceFile;
49
- node: ts.Node;
50
- }): ts.Node =>
51
- ts.visitEachChild(
52
- try_transform_node(props) ?? props.node,
53
- (child) =>
54
- iterate_node({
55
- context: props.context,
56
- file: props.file,
57
- node: child,
58
- }),
59
- props.context.transformer,
60
- );
61
-
62
- const try_transform_node = (props: {
63
- context: INestiaTransformContext;
64
- file: ts.SourceFile;
65
- node: ts.Node;
66
- }): ts.Node | null => {
67
- try {
68
- return NodeTransformer.transform(props);
69
- } catch (exp) {
70
- // ONLY ACCEPT TRANSFORMER-ERROR
71
- if (!isTransformerError(exp)) throw exp;
72
-
73
- // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
74
- (props.node as any).parent ??= props.file;
75
-
76
- // REPORT DIAGNOSTIC
77
- const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
78
- key: exp.code,
79
- category: ts.DiagnosticCategory.Error,
80
- message: exp.message,
81
- code: `(${exp.code})` as any,
82
- });
83
- props.context.extras.addDiagnostic(diagnostic);
84
- return null;
85
- }
86
- };
87
-
88
- const find_import_injection_index = (file: ts.SourceFile): number => {
89
- let i: number = 0;
90
- for (; i < file.statements.length; ++i) {
91
- const stmt: ts.Statement = file.statements[i]!;
92
- if (
93
- ts.isExpressionStatement(stmt) &&
94
- ts.isStringLiteralLike(stmt.expression) &&
95
- stmt.expression.text.startsWith("use ")
96
- )
97
- continue;
98
- break;
99
- }
100
- return i;
101
- };
102
- }
103
-
104
- const isTransformerError = (error: any): error is TransformerError =>
105
- typeof error === "object" &&
106
- error !== null &&
107
- error.constructor.name === "TransformerError" &&
108
- typeof error.code === "string" &&
109
- typeof error.message === "string";
1
+ import { ImportProgrammer, TransformerError } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
5
+ import { NodeTransformer } from "./NodeTransformer";
6
+
7
+ export namespace FileTransformer {
8
+ export const transform =
9
+ (context: Omit<INestiaTransformContext, "importer" | "transformer">) =>
10
+ (transformer: ts.TransformationContext) =>
11
+ (file: ts.SourceFile): ts.SourceFile => {
12
+ if (file.isDeclarationFile) return file;
13
+ const importer = new ImportProgrammer({
14
+ internalPrefix: "nestia_core_transform",
15
+ });
16
+ file = ts.visitEachChild(
17
+ file,
18
+ (node) =>
19
+ iterate_node({
20
+ context: {
21
+ ...context,
22
+ transformer,
23
+ importer,
24
+ },
25
+ file,
26
+ node,
27
+ }),
28
+ transformer,
29
+ );
30
+ const index: number = find_import_injection_index(file);
31
+ return ts.factory.updateSourceFile(
32
+ file,
33
+ [
34
+ ...file.statements.slice(0, index),
35
+ ...importer.toStatements(),
36
+ ...file.statements.slice(index),
37
+ ],
38
+ false,
39
+ file.referencedFiles,
40
+ file.typeReferenceDirectives,
41
+ file.hasNoDefaultLib,
42
+ file.libReferenceDirectives,
43
+ );
44
+ };
45
+
46
+ const iterate_node = (props: {
47
+ context: INestiaTransformContext;
48
+ file: ts.SourceFile;
49
+ node: ts.Node;
50
+ }): ts.Node =>
51
+ ts.visitEachChild(
52
+ try_transform_node(props) ?? props.node,
53
+ (child) =>
54
+ iterate_node({
55
+ context: props.context,
56
+ file: props.file,
57
+ node: child,
58
+ }),
59
+ props.context.transformer,
60
+ );
61
+
62
+ const try_transform_node = (props: {
63
+ context: INestiaTransformContext;
64
+ file: ts.SourceFile;
65
+ node: ts.Node;
66
+ }): ts.Node | null => {
67
+ try {
68
+ return NodeTransformer.transform(props);
69
+ } catch (exp) {
70
+ // ONLY ACCEPT TRANSFORMER-ERROR
71
+ if (!isTransformerError(exp)) throw exp;
72
+
73
+ // AVOID SPECIAL BUG OF TYPESCRIPT COMPILER API
74
+ (props.node as any).parent ??= props.file;
75
+
76
+ // REPORT DIAGNOSTIC
77
+ const diagnostic = (ts as any).createDiagnosticForNode(props.node, {
78
+ key: exp.code,
79
+ category: ts.DiagnosticCategory.Error,
80
+ message: exp.message,
81
+ code: `(${exp.code})` as any,
82
+ });
83
+ props.context.extras.addDiagnostic(diagnostic);
84
+ return null;
85
+ }
86
+ };
87
+
88
+ const find_import_injection_index = (file: ts.SourceFile): number => {
89
+ let i: number = 0;
90
+ for (; i < file.statements.length; ++i) {
91
+ const stmt: ts.Statement = file.statements[i]!;
92
+ if (
93
+ ts.isExpressionStatement(stmt) &&
94
+ ts.isStringLiteralLike(stmt.expression) &&
95
+ stmt.expression.text.startsWith("use ")
96
+ )
97
+ continue;
98
+ break;
99
+ }
100
+ return i;
101
+ };
102
+ }
103
+
104
+ const isTransformerError = (error: any): error is TransformerError =>
105
+ typeof error === "object" &&
106
+ error !== null &&
107
+ error.constructor.name === "TransformerError" &&
108
+ typeof error.code === "string" &&
109
+ typeof error.message === "string";
@@ -1,103 +1,103 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
- import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
- import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
-
7
- export namespace MethodTransformer {
8
- export const transform = (props: {
9
- context: INestiaTransformContext;
10
- method: ts.MethodDeclaration;
11
- }): ts.MethodDeclaration => {
12
- const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
- ? ts.getDecorators(props.method)
14
- : (props.method as any).decorators;
15
- if (!decorators?.length) return props.method;
16
-
17
- const signature: ts.Signature | undefined =
18
- props.context.checker.getSignatureFromDeclaration(props.method);
19
- const original: ts.Type | undefined =
20
- signature && props.context.checker.getReturnTypeOfSignature(signature);
21
- const type: ts.Type | undefined =
22
- original && get_escaped_type(props.context.checker)(original);
23
-
24
- if (type === undefined) return props.method;
25
-
26
- const operator = (decorator: ts.Decorator): ts.Decorator => {
27
- decorator = TypedRouteTransformer.transform({
28
- context: props.context,
29
- decorator,
30
- type,
31
- });
32
- decorator = WebSocketRouteTransformer.validate({
33
- context: props.context,
34
- method: props.method,
35
- decorator,
36
- });
37
- return decorator;
38
- };
39
- if (ts.getDecorators !== undefined)
40
- return ts.factory.updateMethodDeclaration(
41
- props.method,
42
- (props.method.modifiers || []).map((mod) =>
43
- ts.isDecorator(mod) ? operator(mod) : mod,
44
- ),
45
- props.method.asteriskToken,
46
- props.method.name,
47
- props.method.questionToken,
48
- props.method.typeParameters,
49
- props.method.parameters,
50
- props.method.type,
51
- props.method.body,
52
- );
53
- // eslint-disable-next-line
54
- return (ts.factory.updateMethodDeclaration as any)(
55
- props.method,
56
- decorators.map(operator),
57
- (props.method as any).modifiers,
58
- props.method.asteriskToken,
59
- props.method.name,
60
- props.method.questionToken,
61
- props.method.typeParameters,
62
- props.method.parameters,
63
- props.method.type,
64
- props.method.body,
65
- );
66
- };
67
- }
68
-
69
- const get_escaped_type =
70
- (checker: ts.TypeChecker) =>
71
- (type: ts.Type): ts.Type => {
72
- const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
- return symbol && get_name(symbol) === "Promise"
74
- ? escape_promise(checker)(type)
75
- : type;
76
- };
77
-
78
- const escape_promise =
79
- (checker: ts.TypeChecker) =>
80
- (type: ts.Type): ts.Type => {
81
- const generic: readonly ts.Type[] = checker.getTypeArguments(
82
- type as ts.TypeReference,
83
- );
84
- if (generic.length !== 1)
85
- throw new Error(
86
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
- );
88
- return generic[0]!;
89
- };
90
-
91
- const get_name = (symbol: ts.Symbol): string =>
92
- explore_name(symbol.getDeclarations()![0]!.parent)(
93
- symbol.escapedName.toString(),
94
- );
95
-
96
- const explore_name =
97
- (decl: ts.Node) =>
98
- (name: string): string =>
99
- ts.isModuleBlock(decl)
100
- ? explore_name(decl.parent.parent)(
101
- `${decl.parent.name.getFullText().trim()}.${name}`,
102
- )
103
- : name;
1
+ import ts from "typescript";
2
+
3
+ import { INestiaTransformContext } from "../options/INestiaTransformProject";
4
+ import { TypedRouteTransformer } from "./TypedRouteTransformer";
5
+ import { WebSocketRouteTransformer } from "./WebSocketRouteTransformer";
6
+
7
+ export namespace MethodTransformer {
8
+ export const transform = (props: {
9
+ context: INestiaTransformContext;
10
+ method: ts.MethodDeclaration;
11
+ }): ts.MethodDeclaration => {
12
+ const decorators: readonly ts.Decorator[] | undefined = ts.getDecorators
13
+ ? ts.getDecorators(props.method)
14
+ : (props.method as any).decorators;
15
+ if (!decorators?.length) return props.method;
16
+
17
+ const signature: ts.Signature | undefined =
18
+ props.context.checker.getSignatureFromDeclaration(props.method);
19
+ const original: ts.Type | undefined =
20
+ signature && props.context.checker.getReturnTypeOfSignature(signature);
21
+ const type: ts.Type | undefined =
22
+ original && get_escaped_type(props.context.checker)(original);
23
+
24
+ if (type === undefined) return props.method;
25
+
26
+ const operator = (decorator: ts.Decorator): ts.Decorator => {
27
+ decorator = TypedRouteTransformer.transform({
28
+ context: props.context,
29
+ decorator,
30
+ type,
31
+ });
32
+ decorator = WebSocketRouteTransformer.validate({
33
+ context: props.context,
34
+ method: props.method,
35
+ decorator,
36
+ });
37
+ return decorator;
38
+ };
39
+ if (ts.getDecorators !== undefined)
40
+ return ts.factory.updateMethodDeclaration(
41
+ props.method,
42
+ (props.method.modifiers || []).map((mod) =>
43
+ ts.isDecorator(mod) ? operator(mod) : mod,
44
+ ),
45
+ props.method.asteriskToken,
46
+ props.method.name,
47
+ props.method.questionToken,
48
+ props.method.typeParameters,
49
+ props.method.parameters,
50
+ props.method.type,
51
+ props.method.body,
52
+ );
53
+ // eslint-disable-next-line
54
+ return (ts.factory.updateMethodDeclaration as any)(
55
+ props.method,
56
+ decorators.map(operator),
57
+ (props.method as any).modifiers,
58
+ props.method.asteriskToken,
59
+ props.method.name,
60
+ props.method.questionToken,
61
+ props.method.typeParameters,
62
+ props.method.parameters,
63
+ props.method.type,
64
+ props.method.body,
65
+ );
66
+ };
67
+ }
68
+
69
+ const get_escaped_type =
70
+ (checker: ts.TypeChecker) =>
71
+ (type: ts.Type): ts.Type => {
72
+ const symbol: ts.Symbol | undefined = type.getSymbol() || type.aliasSymbol;
73
+ return symbol && get_name(symbol) === "Promise"
74
+ ? escape_promise(checker)(type)
75
+ : type;
76
+ };
77
+
78
+ const escape_promise =
79
+ (checker: ts.TypeChecker) =>
80
+ (type: ts.Type): ts.Type => {
81
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
82
+ type as ts.TypeReference,
83
+ );
84
+ if (generic.length !== 1)
85
+ throw new Error(
86
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
87
+ );
88
+ return generic[0]!;
89
+ };
90
+
91
+ const get_name = (symbol: ts.Symbol): string =>
92
+ explore_name(symbol.getDeclarations()![0]!.parent)(
93
+ symbol.escapedName.toString(),
94
+ );
95
+
96
+ const explore_name =
97
+ (decl: ts.Node) =>
98
+ (name: string): string =>
99
+ ts.isModuleBlock(decl)
100
+ ? explore_name(decl.parent.parent)(
101
+ `${decl.parent.name.getFullText().trim()}.${name}`,
102
+ )
103
+ : name;