@nestia/core 11.2.0 → 12.0.0-dev.20260520.1
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/MIGRATION.md +169 -0
- package/lib/adaptors/WebSocketAdaptor.js +7 -3
- package/lib/adaptors/WebSocketAdaptor.js.map +1 -1
- package/lib/decorators/DynamicModule.js.map +1 -1
- package/lib/decorators/EncryptedBody.js.map +1 -1
- package/lib/decorators/EncryptedController.js.map +1 -1
- package/lib/decorators/EncryptedModule.js.map +1 -1
- package/lib/decorators/EncryptedRoute.js.map +1 -1
- package/lib/decorators/HumanRoute.js.map +1 -1
- package/lib/decorators/NoTransformConfigurationError.js +5 -2
- package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
- package/lib/decorators/PlainBody.js.map +1 -1
- package/lib/decorators/SwaggerCustomizer.js.map +1 -1
- package/lib/decorators/SwaggerExample.js.map +1 -1
- package/lib/decorators/TypedBody.js.map +1 -1
- package/lib/decorators/TypedException.js.map +1 -1
- package/lib/decorators/TypedFormData.js.map +1 -1
- package/lib/decorators/TypedHeaders.js.map +1 -1
- package/lib/decorators/TypedParam.js +5 -2
- package/lib/decorators/TypedParam.js.map +1 -1
- package/lib/decorators/TypedQuery.js.map +1 -1
- package/lib/decorators/TypedRoute.js.map +1 -1
- package/lib/decorators/WebSocketRoute.js.map +1 -1
- package/lib/decorators/doNotThrowTransformError.js.map +1 -1
- package/lib/decorators/internal/get_path_and_querify.js +5 -2
- package/lib/decorators/internal/get_path_and_querify.js.map +1 -1
- package/lib/decorators/internal/get_path_and_stringify.js +5 -2
- package/lib/decorators/internal/get_path_and_stringify.js.map +1 -1
- package/lib/decorators/internal/get_text_body.js.map +1 -1
- package/lib/decorators/internal/headers_to_object.js.map +1 -1
- package/lib/decorators/internal/is_request_body_undefined.js.map +1 -1
- package/lib/decorators/internal/load_controller.js +48 -16
- package/lib/decorators/internal/load_controller.js.map +1 -1
- package/lib/decorators/internal/route_error.js +3 -3
- package/lib/decorators/internal/route_error.js.map +1 -1
- package/lib/decorators/internal/validate_request_body.js +5 -2
- package/lib/decorators/internal/validate_request_body.js.map +1 -1
- package/lib/decorators/internal/validate_request_form_data.js +5 -2
- package/lib/decorators/internal/validate_request_form_data.js.map +1 -1
- package/lib/decorators/internal/validate_request_headers.js +5 -2
- package/lib/decorators/internal/validate_request_headers.js.map +1 -1
- package/lib/decorators/internal/validate_request_query.js +30 -4
- package/lib/decorators/internal/validate_request_query.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/transform.d.ts +2 -5
- package/lib/transform.js +48 -28
- package/lib/transform.js.map +1 -1
- package/lib/utils/ArrayUtil.js.map +1 -1
- package/lib/utils/ExceptionManager.js.map +1 -1
- package/lib/utils/Singleton.js.map +1 -1
- package/lib/utils/SourceFinder.js.map +1 -1
- package/lib/utils/VersioningStrategy.js.map +1 -1
- package/native/cmd/ttsc-nestia/build.go +434 -0
- package/native/cmd/ttsc-nestia/cleanup.go +408 -0
- package/native/cmd/ttsc-nestia/core_querify.go +227 -0
- package/native/cmd/ttsc-nestia/core_transform.go +1713 -0
- package/native/cmd/ttsc-nestia/core_websocket.go +115 -0
- package/native/cmd/ttsc-nestia/main.go +72 -0
- package/native/cmd/ttsc-nestia/path_rewrite.go +285 -0
- package/native/cmd/ttsc-nestia/printer.go +244 -0
- package/native/cmd/ttsc-nestia/rewrite.go +662 -0
- package/native/cmd/ttsc-nestia/sdk_metadata_json.go +327 -0
- package/native/cmd/ttsc-nestia/sdk_transform.go +1541 -0
- package/native/cmd/ttsc-nestia/transform.go +387 -0
- package/native/cmd/ttsc-nestia/typia_fast.go +326 -0
- package/native/cmd/ttsc-nestia/typia_replacement.go +24 -0
- package/native/go.mod +32 -0
- package/native/go.sum +54 -0
- package/native/plugin/plan.go +102 -0
- package/native/transform.cjs +21 -0
- package/package.json +27 -22
- package/src/decorators/NoTransformConfigurationError.ts +5 -2
- package/src/decorators/internal/load_controller.ts +50 -19
- package/src/decorators/internal/validate_request_query.ts +21 -2
- package/src/transform.ts +82 -35
- package/lib/decorators/internal/NoTransformConfigureError.d.ts +0 -1
- package/lib/decorators/internal/NoTransformConfigureError.js +0 -7
- package/lib/decorators/internal/NoTransformConfigureError.js.map +0 -1
- package/lib/options/INestiaTransformOptions.d.ts +0 -13
- package/lib/options/INestiaTransformOptions.js +0 -3
- package/lib/options/INestiaTransformOptions.js.map +0 -1
- package/lib/options/INestiaTransformProject.d.ts +0 -5
- package/lib/options/INestiaTransformProject.js +0 -3
- package/lib/options/INestiaTransformProject.js.map +0 -1
- package/lib/programmers/PlainBodyProgrammer.d.ts +0 -9
- package/lib/programmers/PlainBodyProgrammer.js +0 -58
- package/lib/programmers/PlainBodyProgrammer.js.map +0 -1
- package/lib/programmers/TypedBodyProgrammer.d.ts +0 -9
- package/lib/programmers/TypedBodyProgrammer.js +0 -94
- package/lib/programmers/TypedBodyProgrammer.js.map +0 -1
- package/lib/programmers/TypedFormDataBodyProgrammer.d.ts +0 -9
- package/lib/programmers/TypedFormDataBodyProgrammer.js +0 -65
- package/lib/programmers/TypedFormDataBodyProgrammer.js.map +0 -1
- package/lib/programmers/TypedHeadersProgrammer.d.ts +0 -9
- package/lib/programmers/TypedHeadersProgrammer.js +0 -38
- package/lib/programmers/TypedHeadersProgrammer.js.map +0 -1
- package/lib/programmers/TypedParamProgrammer.d.ts +0 -10
- package/lib/programmers/TypedParamProgrammer.js +0 -32
- package/lib/programmers/TypedParamProgrammer.js.map +0 -1
- package/lib/programmers/TypedQueryBodyProgrammer.d.ts +0 -9
- package/lib/programmers/TypedQueryBodyProgrammer.js +0 -74
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +0 -1
- package/lib/programmers/TypedQueryProgrammer.d.ts +0 -9
- package/lib/programmers/TypedQueryProgrammer.js +0 -75
- package/lib/programmers/TypedQueryProgrammer.js.map +0 -1
- package/lib/programmers/TypedQueryRouteProgrammer.d.ts +0 -9
- package/lib/programmers/TypedQueryRouteProgrammer.js +0 -75
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +0 -1
- package/lib/programmers/TypedRouteProgrammer.d.ts +0 -9
- package/lib/programmers/TypedRouteProgrammer.js +0 -79
- package/lib/programmers/TypedRouteProgrammer.js.map +0 -1
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.d.ts +0 -9
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js +0 -39
- package/lib/programmers/http/HttpAssertQuerifyProgrammer.js.map +0 -1
- package/lib/programmers/http/HttpIsQuerifyProgrammer.d.ts +0 -9
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js +0 -36
- package/lib/programmers/http/HttpIsQuerifyProgrammer.js.map +0 -1
- package/lib/programmers/http/HttpQuerifyProgrammer.d.ts +0 -9
- package/lib/programmers/http/HttpQuerifyProgrammer.js +0 -50
- package/lib/programmers/http/HttpQuerifyProgrammer.js.map +0 -1
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.d.ts +0 -9
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js +0 -40
- package/lib/programmers/http/HttpValidateQuerifyProgrammer.js.map +0 -1
- package/lib/programmers/internal/CoreMetadataUtil.d.ts +0 -5
- package/lib/programmers/internal/CoreMetadataUtil.js +0 -19
- package/lib/programmers/internal/CoreMetadataUtil.js.map +0 -1
- package/lib/transformers/FileTransformer.d.ts +0 -5
- package/lib/transformers/FileTransformer.js +0 -80
- package/lib/transformers/FileTransformer.js.map +0 -1
- package/lib/transformers/MethodTransformer.d.ts +0 -8
- package/lib/transformers/MethodTransformer.js +0 -58
- package/lib/transformers/MethodTransformer.js.map +0 -1
- package/lib/transformers/NodeTransformer.d.ts +0 -8
- package/lib/transformers/NodeTransformer.js +0 -24
- package/lib/transformers/NodeTransformer.js.map +0 -1
- package/lib/transformers/ParameterDecoratorTransformer.d.ts +0 -9
- package/lib/transformers/ParameterDecoratorTransformer.js +0 -104
- package/lib/transformers/ParameterDecoratorTransformer.js.map +0 -1
- package/lib/transformers/ParameterTransformer.d.ts +0 -8
- package/lib/transformers/ParameterTransformer.js +0 -37
- package/lib/transformers/ParameterTransformer.js.map +0 -1
- package/lib/transformers/TypedRouteTransformer.d.ts +0 -9
- package/lib/transformers/TypedRouteTransformer.js +0 -68
- package/lib/transformers/TypedRouteTransformer.js.map +0 -1
- package/lib/transformers/WebSocketRouteTransformer.d.ts +0 -9
- package/lib/transformers/WebSocketRouteTransformer.js +0 -72
- package/lib/transformers/WebSocketRouteTransformer.js.map +0 -1
- package/src/decorators/internal/NoTransformConfigureError.ts +0 -2
- package/src/options/INestiaTransformOptions.ts +0 -34
- package/src/options/INestiaTransformProject.ts +0 -10
- package/src/programmers/PlainBodyProgrammer.ts +0 -72
- package/src/programmers/TypedBodyProgrammer.ts +0 -148
- package/src/programmers/TypedFormDataBodyProgrammer.ts +0 -118
- package/src/programmers/TypedHeadersProgrammer.ts +0 -65
- package/src/programmers/TypedParamProgrammer.ts +0 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +0 -113
- package/src/programmers/TypedQueryProgrammer.ts +0 -115
- package/src/programmers/TypedQueryRouteProgrammer.ts +0 -107
- package/src/programmers/TypedRouteProgrammer.ts +0 -103
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +0 -74
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +0 -77
- package/src/programmers/http/HttpQuerifyProgrammer.ts +0 -110
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +0 -78
- package/src/programmers/internal/CoreMetadataUtil.ts +0 -21
- package/src/transformers/FileTransformer.ts +0 -109
- package/src/transformers/MethodTransformer.ts +0 -103
- package/src/transformers/NodeTransformer.ts +0 -23
- package/src/transformers/ParameterDecoratorTransformer.ts +0 -143
- package/src/transformers/ParameterTransformer.ts +0 -57
- package/src/transformers/TypedRouteTransformer.ts +0 -85
- package/src/transformers/WebSocketRouteTransformer.ts +0 -120
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IProgrammerProps,
|
|
3
|
-
JsonAssertStringifyProgrammer,
|
|
4
|
-
JsonIsStringifyProgrammer,
|
|
5
|
-
JsonMetadataFactory,
|
|
6
|
-
JsonStringifyProgrammer,
|
|
7
|
-
JsonValidateStringifyProgrammer,
|
|
8
|
-
LlmParametersProgrammer,
|
|
9
|
-
} from "@typia/core";
|
|
10
|
-
import ts from "typescript";
|
|
11
|
-
|
|
12
|
-
import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
|
|
13
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
14
|
-
|
|
15
|
-
export namespace TypedRouteProgrammer {
|
|
16
|
-
export const generate = (props: {
|
|
17
|
-
context: INestiaTransformContext;
|
|
18
|
-
modulo: ts.LeftHandSideExpression;
|
|
19
|
-
type: ts.Type;
|
|
20
|
-
}): ts.Expression => {
|
|
21
|
-
// VALIDATE TYPE
|
|
22
|
-
if (props.context.options.llm) {
|
|
23
|
-
const llm: INestiaTransformOptions.ILlm | true =
|
|
24
|
-
props.context.options.llm;
|
|
25
|
-
JsonMetadataFactory.analyze({
|
|
26
|
-
method: "@nestia.core.TypedRoute",
|
|
27
|
-
checker: props.context.checker,
|
|
28
|
-
transformer: props.context.transformer,
|
|
29
|
-
type: props.type,
|
|
30
|
-
validate: (next) => {
|
|
31
|
-
if (next.metadata.size() === 0) return [];
|
|
32
|
-
return LlmParametersProgrammer.validate({
|
|
33
|
-
config: {
|
|
34
|
-
strict: llm === true ? false : (llm.strict ?? false),
|
|
35
|
-
},
|
|
36
|
-
metadata: next.metadata,
|
|
37
|
-
explore: next.explore,
|
|
38
|
-
});
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// GENERATE STRINGIFY PLAN
|
|
44
|
-
const parameter = (next: {
|
|
45
|
-
type: string;
|
|
46
|
-
key: string;
|
|
47
|
-
programmer: (next: IProgrammerProps) => ts.Expression;
|
|
48
|
-
}) =>
|
|
49
|
-
ts.factory.createObjectLiteralExpression([
|
|
50
|
-
ts.factory.createPropertyAssignment(
|
|
51
|
-
ts.factory.createIdentifier("type"),
|
|
52
|
-
ts.factory.createStringLiteral(next.type),
|
|
53
|
-
),
|
|
54
|
-
ts.factory.createPropertyAssignment(
|
|
55
|
-
ts.factory.createIdentifier(next.key),
|
|
56
|
-
next.programmer({
|
|
57
|
-
context: {
|
|
58
|
-
...props.context,
|
|
59
|
-
options: {}, // use default option
|
|
60
|
-
},
|
|
61
|
-
modulo: props.modulo,
|
|
62
|
-
type: props.type,
|
|
63
|
-
name: undefined,
|
|
64
|
-
}),
|
|
65
|
-
),
|
|
66
|
-
]);
|
|
67
|
-
|
|
68
|
-
// RETURNS
|
|
69
|
-
if (props.context.options.stringify === "is")
|
|
70
|
-
return parameter({
|
|
71
|
-
type: "is",
|
|
72
|
-
key: "is",
|
|
73
|
-
programmer: JsonIsStringifyProgrammer.write,
|
|
74
|
-
});
|
|
75
|
-
else if (props.context.options.stringify === "validate")
|
|
76
|
-
return parameter({
|
|
77
|
-
type: "validate",
|
|
78
|
-
key: "validate",
|
|
79
|
-
programmer: JsonValidateStringifyProgrammer.write,
|
|
80
|
-
});
|
|
81
|
-
else if (props.context.options.stringify === "stringify")
|
|
82
|
-
return parameter({
|
|
83
|
-
type: "stringify",
|
|
84
|
-
key: "stringify",
|
|
85
|
-
programmer: JsonStringifyProgrammer.write,
|
|
86
|
-
});
|
|
87
|
-
else if (props.context.options.stringify === "validate.log")
|
|
88
|
-
return parameter({
|
|
89
|
-
type: "validate.log",
|
|
90
|
-
key: "validate",
|
|
91
|
-
programmer: JsonValidateStringifyProgrammer.write,
|
|
92
|
-
});
|
|
93
|
-
else if (props.context.options.stringify === null)
|
|
94
|
-
return ts.factory.createNull();
|
|
95
|
-
|
|
96
|
-
// ASSERT IS DEFAULT
|
|
97
|
-
return parameter({
|
|
98
|
-
type: "assert",
|
|
99
|
-
key: "assert",
|
|
100
|
-
programmer: JsonAssertStringifyProgrammer.write,
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
AssertProgrammer,
|
|
3
|
-
ITypiaContext,
|
|
4
|
-
IdentifierFactory,
|
|
5
|
-
StatementFactory,
|
|
6
|
-
} from "@typia/core";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
|
|
9
|
-
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
10
|
-
|
|
11
|
-
export namespace HttpAssertQuerifyProgrammer {
|
|
12
|
-
export const write = (props: {
|
|
13
|
-
context: ITypiaContext;
|
|
14
|
-
modulo: ts.LeftHandSideExpression;
|
|
15
|
-
type: ts.Type;
|
|
16
|
-
}): ts.ArrowFunction =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[IdentifierFactory.parameter("input")],
|
|
21
|
-
undefined,
|
|
22
|
-
undefined,
|
|
23
|
-
ts.factory.createBlock([
|
|
24
|
-
StatementFactory.constant({
|
|
25
|
-
name: "assert",
|
|
26
|
-
value: AssertProgrammer.write({
|
|
27
|
-
context: {
|
|
28
|
-
...props.context,
|
|
29
|
-
options: {
|
|
30
|
-
...props.context.options,
|
|
31
|
-
functional: false,
|
|
32
|
-
numeric: false,
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
modulo: props.modulo,
|
|
36
|
-
config: {
|
|
37
|
-
equals: false,
|
|
38
|
-
guard: false,
|
|
39
|
-
},
|
|
40
|
-
type: props.type,
|
|
41
|
-
name: undefined,
|
|
42
|
-
}),
|
|
43
|
-
}),
|
|
44
|
-
StatementFactory.constant({
|
|
45
|
-
name: "stringify",
|
|
46
|
-
value: HttpQuerifyProgrammer.write({
|
|
47
|
-
context: {
|
|
48
|
-
...props.context,
|
|
49
|
-
options: {
|
|
50
|
-
...props.context.options,
|
|
51
|
-
functional: false,
|
|
52
|
-
numeric: false,
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
modulo: props.modulo,
|
|
56
|
-
type: props.type,
|
|
57
|
-
}),
|
|
58
|
-
}),
|
|
59
|
-
ts.factory.createReturnStatement(
|
|
60
|
-
ts.factory.createCallExpression(
|
|
61
|
-
ts.factory.createIdentifier("stringify"),
|
|
62
|
-
undefined,
|
|
63
|
-
[
|
|
64
|
-
ts.factory.createCallExpression(
|
|
65
|
-
ts.factory.createIdentifier("assert"),
|
|
66
|
-
undefined,
|
|
67
|
-
[ts.factory.createIdentifier("input")],
|
|
68
|
-
),
|
|
69
|
-
],
|
|
70
|
-
),
|
|
71
|
-
),
|
|
72
|
-
]),
|
|
73
|
-
);
|
|
74
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ITypiaContext,
|
|
3
|
-
IdentifierFactory,
|
|
4
|
-
IsProgrammer,
|
|
5
|
-
StatementFactory,
|
|
6
|
-
} from "@typia/core";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
|
|
9
|
-
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
10
|
-
|
|
11
|
-
export namespace HttpIsQuerifyProgrammer {
|
|
12
|
-
export const write = (props: {
|
|
13
|
-
context: ITypiaContext;
|
|
14
|
-
modulo: ts.LeftHandSideExpression;
|
|
15
|
-
type: ts.Type;
|
|
16
|
-
}): ts.ArrowFunction =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[IdentifierFactory.parameter("input")],
|
|
21
|
-
undefined,
|
|
22
|
-
undefined,
|
|
23
|
-
ts.factory.createBlock([
|
|
24
|
-
StatementFactory.constant({
|
|
25
|
-
name: "is",
|
|
26
|
-
value: IsProgrammer.write({
|
|
27
|
-
config: {
|
|
28
|
-
equals: false,
|
|
29
|
-
},
|
|
30
|
-
context: {
|
|
31
|
-
...props.context,
|
|
32
|
-
options: {
|
|
33
|
-
...props.context.options,
|
|
34
|
-
functional: false,
|
|
35
|
-
numeric: false,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
modulo: props.modulo,
|
|
39
|
-
type: props.type,
|
|
40
|
-
name: undefined,
|
|
41
|
-
}),
|
|
42
|
-
}),
|
|
43
|
-
StatementFactory.constant({
|
|
44
|
-
name: "stringify",
|
|
45
|
-
value: HttpQuerifyProgrammer.write({
|
|
46
|
-
context: {
|
|
47
|
-
...props.context,
|
|
48
|
-
options: {
|
|
49
|
-
...props.context.options,
|
|
50
|
-
functional: false,
|
|
51
|
-
numeric: false,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
modulo: props.modulo,
|
|
55
|
-
type: props.type,
|
|
56
|
-
}),
|
|
57
|
-
}),
|
|
58
|
-
ts.factory.createReturnStatement(
|
|
59
|
-
ts.factory.createConditionalExpression(
|
|
60
|
-
ts.factory.createCallExpression(
|
|
61
|
-
ts.factory.createIdentifier("is"),
|
|
62
|
-
undefined,
|
|
63
|
-
[ts.factory.createIdentifier("input")],
|
|
64
|
-
),
|
|
65
|
-
undefined,
|
|
66
|
-
ts.factory.createCallExpression(
|
|
67
|
-
ts.factory.createIdentifier("stringify"),
|
|
68
|
-
undefined,
|
|
69
|
-
[ts.factory.createIdentifier("input")],
|
|
70
|
-
),
|
|
71
|
-
undefined,
|
|
72
|
-
ts.factory.createNull(),
|
|
73
|
-
),
|
|
74
|
-
),
|
|
75
|
-
]),
|
|
76
|
-
);
|
|
77
|
-
}
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FunctionProgrammer,
|
|
3
|
-
HttpQueryProgrammer,
|
|
4
|
-
ITypiaContext,
|
|
5
|
-
IdentifierFactory,
|
|
6
|
-
MetadataCollection,
|
|
7
|
-
MetadataFactory,
|
|
8
|
-
MetadataObject,
|
|
9
|
-
MetadataSchema,
|
|
10
|
-
StatementFactory,
|
|
11
|
-
TransformerError,
|
|
12
|
-
} from "@typia/core";
|
|
13
|
-
import ts from "typescript";
|
|
14
|
-
|
|
15
|
-
export namespace HttpQuerifyProgrammer {
|
|
16
|
-
export const write = (props: {
|
|
17
|
-
context: ITypiaContext;
|
|
18
|
-
modulo: ts.LeftHandSideExpression;
|
|
19
|
-
type: ts.Type;
|
|
20
|
-
}): ts.ArrowFunction => {
|
|
21
|
-
// GET OBJECT TYPE
|
|
22
|
-
const functor: FunctionProgrammer = new FunctionProgrammer(
|
|
23
|
-
props.modulo.getText(),
|
|
24
|
-
);
|
|
25
|
-
const storage: MetadataCollection = new MetadataCollection();
|
|
26
|
-
const result = MetadataFactory.analyze({
|
|
27
|
-
checker: props.context.checker,
|
|
28
|
-
transformer: props.context.transformer,
|
|
29
|
-
options: {
|
|
30
|
-
escape: false,
|
|
31
|
-
constant: true,
|
|
32
|
-
absorb: true,
|
|
33
|
-
validate: HttpQueryProgrammer.validate,
|
|
34
|
-
},
|
|
35
|
-
type: props.type,
|
|
36
|
-
components: storage,
|
|
37
|
-
});
|
|
38
|
-
if (result.success === false)
|
|
39
|
-
throw TransformerError.from({
|
|
40
|
-
code: functor.method,
|
|
41
|
-
errors: result.errors,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const object: MetadataObject = result.data.objects[0]!;
|
|
45
|
-
return ts.factory.createArrowFunction(
|
|
46
|
-
undefined,
|
|
47
|
-
undefined,
|
|
48
|
-
[IdentifierFactory.parameter("input")],
|
|
49
|
-
undefined,
|
|
50
|
-
undefined,
|
|
51
|
-
ts.factory.createBlock(
|
|
52
|
-
[
|
|
53
|
-
...functor.declare(),
|
|
54
|
-
StatementFactory.constant({
|
|
55
|
-
name: "output",
|
|
56
|
-
value: ts.factory.createNewExpression(
|
|
57
|
-
ts.factory.createIdentifier("URLSearchParams"),
|
|
58
|
-
undefined,
|
|
59
|
-
[],
|
|
60
|
-
),
|
|
61
|
-
}),
|
|
62
|
-
...object.type.properties.map((p) =>
|
|
63
|
-
ts.factory.createExpressionStatement(
|
|
64
|
-
decode(p.key.constants[0]!.values[0]!.value as string)(p.value),
|
|
65
|
-
),
|
|
66
|
-
),
|
|
67
|
-
ts.factory.createReturnStatement(
|
|
68
|
-
ts.factory.createIdentifier("output"),
|
|
69
|
-
),
|
|
70
|
-
],
|
|
71
|
-
true,
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const decode =
|
|
77
|
-
(key: string) =>
|
|
78
|
-
(value: MetadataSchema): ts.CallExpression =>
|
|
79
|
-
!!value.arrays.length
|
|
80
|
-
? ts.factory.createCallExpression(
|
|
81
|
-
IdentifierFactory.access(
|
|
82
|
-
IdentifierFactory.access(
|
|
83
|
-
ts.factory.createIdentifier("input"),
|
|
84
|
-
key,
|
|
85
|
-
),
|
|
86
|
-
"forEach",
|
|
87
|
-
),
|
|
88
|
-
undefined,
|
|
89
|
-
[
|
|
90
|
-
ts.factory.createArrowFunction(
|
|
91
|
-
undefined,
|
|
92
|
-
undefined,
|
|
93
|
-
[IdentifierFactory.parameter("elem")],
|
|
94
|
-
undefined,
|
|
95
|
-
undefined,
|
|
96
|
-
append(key)(ts.factory.createIdentifier("elem")),
|
|
97
|
-
),
|
|
98
|
-
],
|
|
99
|
-
)
|
|
100
|
-
: append(key)(
|
|
101
|
-
IdentifierFactory.access(ts.factory.createIdentifier("input"), key),
|
|
102
|
-
);
|
|
103
|
-
|
|
104
|
-
const append = (key: string) => (elem: ts.Expression) =>
|
|
105
|
-
ts.factory.createCallExpression(
|
|
106
|
-
IdentifierFactory.access(ts.factory.createIdentifier("output"), "append"),
|
|
107
|
-
undefined,
|
|
108
|
-
[ts.factory.createStringLiteral(key), elem],
|
|
109
|
-
);
|
|
110
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ITypiaContext,
|
|
3
|
-
IdentifierFactory,
|
|
4
|
-
StatementFactory,
|
|
5
|
-
ValidateProgrammer,
|
|
6
|
-
} from "@typia/core";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
|
|
9
|
-
import { HttpQuerifyProgrammer } from "./HttpQuerifyProgrammer";
|
|
10
|
-
|
|
11
|
-
export namespace HttpValidateQuerifyProgrammer {
|
|
12
|
-
export const write = (props: {
|
|
13
|
-
context: ITypiaContext;
|
|
14
|
-
modulo: ts.LeftHandSideExpression;
|
|
15
|
-
type: ts.Type;
|
|
16
|
-
}): ts.ArrowFunction =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[IdentifierFactory.parameter("input")],
|
|
21
|
-
undefined,
|
|
22
|
-
undefined,
|
|
23
|
-
ts.factory.createBlock([
|
|
24
|
-
StatementFactory.constant({
|
|
25
|
-
name: "validate",
|
|
26
|
-
value: ValidateProgrammer.write({
|
|
27
|
-
config: {
|
|
28
|
-
equals: false,
|
|
29
|
-
},
|
|
30
|
-
context: {
|
|
31
|
-
...props.context,
|
|
32
|
-
options: {
|
|
33
|
-
...props.context.options,
|
|
34
|
-
functional: false,
|
|
35
|
-
numeric: true,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
modulo: props.modulo,
|
|
39
|
-
type: props.type,
|
|
40
|
-
name: undefined,
|
|
41
|
-
}),
|
|
42
|
-
}),
|
|
43
|
-
StatementFactory.constant({
|
|
44
|
-
name: "query",
|
|
45
|
-
value: HttpQuerifyProgrammer.write({
|
|
46
|
-
context: {
|
|
47
|
-
...props.context,
|
|
48
|
-
options: {
|
|
49
|
-
...props.context.options,
|
|
50
|
-
functional: false,
|
|
51
|
-
numeric: false,
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
modulo: props.modulo,
|
|
55
|
-
type: props.type,
|
|
56
|
-
}),
|
|
57
|
-
}),
|
|
58
|
-
StatementFactory.constant({
|
|
59
|
-
name: "output",
|
|
60
|
-
value: ts.factory.createCallExpression(
|
|
61
|
-
ts.factory.createIdentifier("query"),
|
|
62
|
-
undefined,
|
|
63
|
-
[ts.factory.createIdentifier("input")],
|
|
64
|
-
),
|
|
65
|
-
}),
|
|
66
|
-
ts.factory.createReturnStatement(
|
|
67
|
-
ts.factory.createAsExpression(
|
|
68
|
-
ts.factory.createCallExpression(
|
|
69
|
-
ts.factory.createIdentifier("validate"),
|
|
70
|
-
undefined,
|
|
71
|
-
[ts.factory.createIdentifier("output")],
|
|
72
|
-
),
|
|
73
|
-
ts.factory.createTypeReferenceNode("any"),
|
|
74
|
-
),
|
|
75
|
-
),
|
|
76
|
-
]),
|
|
77
|
-
);
|
|
78
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
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,109 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,23 +0,0 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
4
|
-
import { MethodTransformer } from "./MethodTransformer";
|
|
5
|
-
import { ParameterTransformer } from "./ParameterTransformer";
|
|
6
|
-
|
|
7
|
-
export namespace NodeTransformer {
|
|
8
|
-
export const transform = (props: {
|
|
9
|
-
context: INestiaTransformContext;
|
|
10
|
-
node: ts.Node;
|
|
11
|
-
}): ts.Node =>
|
|
12
|
-
ts.isMethodDeclaration(props.node)
|
|
13
|
-
? MethodTransformer.transform({
|
|
14
|
-
context: props.context,
|
|
15
|
-
method: props.node,
|
|
16
|
-
})
|
|
17
|
-
: ts.isParameter(props.node)
|
|
18
|
-
? ParameterTransformer.transform({
|
|
19
|
-
context: props.context,
|
|
20
|
-
param: props.node,
|
|
21
|
-
})
|
|
22
|
-
: props.node;
|
|
23
|
-
}
|