@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.
- package/LICENSE +21 -21
- package/README.md +93 -93
- package/lib/decorators/NoTransformConfigurationError.d.ts +1 -24
- package/lib/decorators/NoTransformConfigurationError.js +2 -0
- package/lib/decorators/NoTransformConfigurationError.js.map +1 -1
- package/lib/decorators/doNotThrowTransformError.d.ts +1 -0
- package/lib/decorators/doNotThrowTransformError.js +9 -0
- package/lib/decorators/doNotThrowTransformError.js.map +1 -0
- package/lib/module.d.ts +1 -1
- package/lib/module.js +1 -1
- package/lib/module.js.map +1 -1
- package/lib/options/INestiaTransformOptions.d.ts +1 -1
- package/lib/programmers/PlainBodyProgrammer.js +1 -1
- package/lib/programmers/PlainBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedBodyProgrammer.js +6 -3
- package/lib/programmers/TypedBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryBodyProgrammer.js +9 -4
- package/lib/programmers/TypedQueryBodyProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryProgrammer.js +9 -4
- package/lib/programmers/TypedQueryProgrammer.js.map +1 -1
- package/lib/programmers/TypedQueryRouteProgrammer.js +14 -8
- package/lib/programmers/TypedQueryRouteProgrammer.js.map +1 -1
- package/lib/programmers/TypedRouteProgrammer.js +11 -6
- package/lib/programmers/TypedRouteProgrammer.js.map +1 -1
- package/package.json +8 -8
- package/src/adaptors/WebSocketAdaptor.ts +429 -429
- package/src/decorators/EncryptedBody.ts +96 -96
- package/src/decorators/EncryptedController.ts +40 -40
- package/src/decorators/EncryptedModule.ts +98 -98
- package/src/decorators/EncryptedRoute.ts +212 -212
- package/src/decorators/HumanRoute.ts +21 -21
- package/src/decorators/NoTransformConfigurationError.ts +37 -34
- package/src/decorators/SwaggerCustomizer.ts +97 -97
- package/src/decorators/TypedFormData.ts +187 -187
- package/src/decorators/TypedRoute.ts +196 -196
- package/src/decorators/doNotThrowTransformError.ts +5 -0
- package/src/decorators/internal/headers_to_object.ts +11 -11
- package/src/module.ts +23 -23
- package/src/options/INestiaTransformOptions.ts +34 -34
- package/src/options/INestiaTransformProject.ts +10 -10
- package/src/programmers/PlainBodyProgrammer.ts +72 -72
- package/src/programmers/TypedBodyProgrammer.ts +148 -144
- package/src/programmers/TypedFormDataBodyProgrammer.ts +118 -118
- package/src/programmers/TypedHeadersProgrammer.ts +65 -65
- package/src/programmers/TypedParamProgrammer.ts +33 -33
- package/src/programmers/TypedQueryBodyProgrammer.ts +113 -111
- package/src/programmers/TypedQueryProgrammer.ts +115 -113
- package/src/programmers/TypedQueryRouteProgrammer.ts +107 -104
- package/src/programmers/TypedRouteProgrammer.ts +103 -96
- package/src/programmers/http/HttpAssertQuerifyProgrammer.ts +74 -74
- package/src/programmers/http/HttpIsQuerifyProgrammer.ts +77 -77
- package/src/programmers/http/HttpQuerifyProgrammer.ts +110 -110
- package/src/programmers/http/HttpValidateQuerifyProgrammer.ts +78 -78
- package/src/programmers/internal/CoreMetadataUtil.ts +21 -21
- package/src/transform.ts +35 -35
- package/src/transformers/FileTransformer.ts +109 -109
- package/src/transformers/MethodTransformer.ts +103 -103
- package/src/transformers/ParameterDecoratorTransformer.ts +143 -143
- package/src/transformers/TypedRouteTransformer.ts +85 -85
- package/src/transformers/WebSocketRouteTransformer.ts +120 -120
|
@@ -1,118 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpAssertFormDataProgrammer,
|
|
3
|
-
HttpFormDataProgrammer,
|
|
4
|
-
HttpIsFormDataProgrammer,
|
|
5
|
-
HttpValidateFormDataProgrammer,
|
|
6
|
-
ITypiaContext,
|
|
7
|
-
LiteralFactory,
|
|
8
|
-
MetadataCollection,
|
|
9
|
-
MetadataFactory,
|
|
10
|
-
MetadataSchema,
|
|
11
|
-
TransformerError,
|
|
12
|
-
} from "@typia/core";
|
|
13
|
-
import ts from "typescript";
|
|
14
|
-
|
|
15
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
16
|
-
import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
17
|
-
|
|
18
|
-
export namespace TypedFormDataBodyProgrammer {
|
|
19
|
-
export const generate = (props: {
|
|
20
|
-
context: INestiaTransformContext;
|
|
21
|
-
modulo: ts.LeftHandSideExpression;
|
|
22
|
-
type: ts.Type;
|
|
23
|
-
}): ts.ObjectLiteralExpression => {
|
|
24
|
-
// VALIDATE TYPE
|
|
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: HttpFormDataProgrammer.validate,
|
|
34
|
-
},
|
|
35
|
-
type: props.type,
|
|
36
|
-
components: storage,
|
|
37
|
-
});
|
|
38
|
-
if (result.success === false)
|
|
39
|
-
throw TransformerError.from({
|
|
40
|
-
code: "nestia.core.TypedFormData.Body",
|
|
41
|
-
errors: result.errors,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const files: IRequestFormDataProps.IFile[] =
|
|
45
|
-
result.data.objects[0]!.type.properties.filter(
|
|
46
|
-
(p) =>
|
|
47
|
-
isFile(p.value) || p.value.arrays.some((a) => isFile(a.type.value)),
|
|
48
|
-
).map((p) => ({
|
|
49
|
-
name: p.key.constants[0]!.values[0]!.value as string,
|
|
50
|
-
limit: !!p.value.natives.length ? 1 : null,
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
// GENERATE VALIDATION PLAN
|
|
54
|
-
const parameter =
|
|
55
|
-
(key: IRequestFormDataProps<any>["validator"]["type"]) =>
|
|
56
|
-
(
|
|
57
|
-
programmer: (next: {
|
|
58
|
-
context: ITypiaContext;
|
|
59
|
-
modulo: ts.LeftHandSideExpression;
|
|
60
|
-
type: ts.Type;
|
|
61
|
-
name: string | undefined;
|
|
62
|
-
}) => ts.Expression,
|
|
63
|
-
) =>
|
|
64
|
-
ts.factory.createObjectLiteralExpression(
|
|
65
|
-
[
|
|
66
|
-
ts.factory.createPropertyAssignment(
|
|
67
|
-
ts.factory.createIdentifier("files"),
|
|
68
|
-
LiteralFactory.write(files),
|
|
69
|
-
),
|
|
70
|
-
ts.factory.createPropertyAssignment(
|
|
71
|
-
ts.factory.createIdentifier("validator"),
|
|
72
|
-
ts.factory.createObjectLiteralExpression(
|
|
73
|
-
[
|
|
74
|
-
ts.factory.createPropertyAssignment(
|
|
75
|
-
ts.factory.createIdentifier("type"),
|
|
76
|
-
ts.factory.createStringLiteral(key),
|
|
77
|
-
),
|
|
78
|
-
ts.factory.createPropertyAssignment(
|
|
79
|
-
ts.factory.createIdentifier(key),
|
|
80
|
-
programmer({
|
|
81
|
-
context: {
|
|
82
|
-
...props.context,
|
|
83
|
-
options: {
|
|
84
|
-
numeric: false,
|
|
85
|
-
finite: false,
|
|
86
|
-
functional: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
modulo: props.modulo,
|
|
90
|
-
type: props.type,
|
|
91
|
-
name: undefined,
|
|
92
|
-
}),
|
|
93
|
-
),
|
|
94
|
-
],
|
|
95
|
-
true,
|
|
96
|
-
),
|
|
97
|
-
),
|
|
98
|
-
],
|
|
99
|
-
true,
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
// RETURNS
|
|
103
|
-
const category = props.context.options.validate;
|
|
104
|
-
if (category === "is" || category === "equals")
|
|
105
|
-
return parameter("is")(HttpIsFormDataProgrammer.write);
|
|
106
|
-
else if (
|
|
107
|
-
category === "validate" ||
|
|
108
|
-
category === "validateEquals" ||
|
|
109
|
-
category === "validateClone" ||
|
|
110
|
-
category === "validatePrune"
|
|
111
|
-
)
|
|
112
|
-
return parameter("validate")(HttpValidateFormDataProgrammer.write);
|
|
113
|
-
return parameter("assert")(HttpAssertFormDataProgrammer.write);
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const isFile = (meta: MetadataSchema) =>
|
|
118
|
-
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertFormDataProgrammer,
|
|
3
|
+
HttpFormDataProgrammer,
|
|
4
|
+
HttpIsFormDataProgrammer,
|
|
5
|
+
HttpValidateFormDataProgrammer,
|
|
6
|
+
ITypiaContext,
|
|
7
|
+
LiteralFactory,
|
|
8
|
+
MetadataCollection,
|
|
9
|
+
MetadataFactory,
|
|
10
|
+
MetadataSchema,
|
|
11
|
+
TransformerError,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import ts from "typescript";
|
|
14
|
+
|
|
15
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
16
|
+
import { IRequestFormDataProps } from "../options/IRequestFormDataProps";
|
|
17
|
+
|
|
18
|
+
export namespace TypedFormDataBodyProgrammer {
|
|
19
|
+
export const generate = (props: {
|
|
20
|
+
context: INestiaTransformContext;
|
|
21
|
+
modulo: ts.LeftHandSideExpression;
|
|
22
|
+
type: ts.Type;
|
|
23
|
+
}): ts.ObjectLiteralExpression => {
|
|
24
|
+
// VALIDATE TYPE
|
|
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: HttpFormDataProgrammer.validate,
|
|
34
|
+
},
|
|
35
|
+
type: props.type,
|
|
36
|
+
components: storage,
|
|
37
|
+
});
|
|
38
|
+
if (result.success === false)
|
|
39
|
+
throw TransformerError.from({
|
|
40
|
+
code: "nestia.core.TypedFormData.Body",
|
|
41
|
+
errors: result.errors,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const files: IRequestFormDataProps.IFile[] =
|
|
45
|
+
result.data.objects[0]!.type.properties.filter(
|
|
46
|
+
(p) =>
|
|
47
|
+
isFile(p.value) || p.value.arrays.some((a) => isFile(a.type.value)),
|
|
48
|
+
).map((p) => ({
|
|
49
|
+
name: p.key.constants[0]!.values[0]!.value as string,
|
|
50
|
+
limit: !!p.value.natives.length ? 1 : null,
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
// GENERATE VALIDATION PLAN
|
|
54
|
+
const parameter =
|
|
55
|
+
(key: IRequestFormDataProps<any>["validator"]["type"]) =>
|
|
56
|
+
(
|
|
57
|
+
programmer: (next: {
|
|
58
|
+
context: ITypiaContext;
|
|
59
|
+
modulo: ts.LeftHandSideExpression;
|
|
60
|
+
type: ts.Type;
|
|
61
|
+
name: string | undefined;
|
|
62
|
+
}) => ts.Expression,
|
|
63
|
+
) =>
|
|
64
|
+
ts.factory.createObjectLiteralExpression(
|
|
65
|
+
[
|
|
66
|
+
ts.factory.createPropertyAssignment(
|
|
67
|
+
ts.factory.createIdentifier("files"),
|
|
68
|
+
LiteralFactory.write(files),
|
|
69
|
+
),
|
|
70
|
+
ts.factory.createPropertyAssignment(
|
|
71
|
+
ts.factory.createIdentifier("validator"),
|
|
72
|
+
ts.factory.createObjectLiteralExpression(
|
|
73
|
+
[
|
|
74
|
+
ts.factory.createPropertyAssignment(
|
|
75
|
+
ts.factory.createIdentifier("type"),
|
|
76
|
+
ts.factory.createStringLiteral(key),
|
|
77
|
+
),
|
|
78
|
+
ts.factory.createPropertyAssignment(
|
|
79
|
+
ts.factory.createIdentifier(key),
|
|
80
|
+
programmer({
|
|
81
|
+
context: {
|
|
82
|
+
...props.context,
|
|
83
|
+
options: {
|
|
84
|
+
numeric: false,
|
|
85
|
+
finite: false,
|
|
86
|
+
functional: false,
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
modulo: props.modulo,
|
|
90
|
+
type: props.type,
|
|
91
|
+
name: undefined,
|
|
92
|
+
}),
|
|
93
|
+
),
|
|
94
|
+
],
|
|
95
|
+
true,
|
|
96
|
+
),
|
|
97
|
+
),
|
|
98
|
+
],
|
|
99
|
+
true,
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
// RETURNS
|
|
103
|
+
const category = props.context.options.validate;
|
|
104
|
+
if (category === "is" || category === "equals")
|
|
105
|
+
return parameter("is")(HttpIsFormDataProgrammer.write);
|
|
106
|
+
else if (
|
|
107
|
+
category === "validate" ||
|
|
108
|
+
category === "validateEquals" ||
|
|
109
|
+
category === "validateClone" ||
|
|
110
|
+
category === "validatePrune"
|
|
111
|
+
)
|
|
112
|
+
return parameter("validate")(HttpValidateFormDataProgrammer.write);
|
|
113
|
+
return parameter("assert")(HttpAssertFormDataProgrammer.write);
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const isFile = (meta: MetadataSchema) =>
|
|
118
|
+
meta.natives.some(({ name }) => name === "File" || name === "Blob");
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpAssertHeadersProgrammer,
|
|
3
|
-
HttpIsHeadersProgrammer,
|
|
4
|
-
HttpValidateHeadersProgrammer,
|
|
5
|
-
ITypiaContext,
|
|
6
|
-
} from "@typia/core";
|
|
7
|
-
import ts from "typescript";
|
|
8
|
-
|
|
9
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
10
|
-
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
11
|
-
|
|
12
|
-
export namespace TypedHeadersProgrammer {
|
|
13
|
-
export const generate = (props: {
|
|
14
|
-
context: INestiaTransformContext;
|
|
15
|
-
modulo: ts.LeftHandSideExpression;
|
|
16
|
-
type: ts.Type;
|
|
17
|
-
}): ts.Expression => {
|
|
18
|
-
// GENERATE VALIDATION PLAN
|
|
19
|
-
const parameter =
|
|
20
|
-
(key: IRequestHeadersValidator<any>["type"]) =>
|
|
21
|
-
(
|
|
22
|
-
programmer: (next: {
|
|
23
|
-
context: ITypiaContext;
|
|
24
|
-
modulo: ts.LeftHandSideExpression;
|
|
25
|
-
type: ts.Type;
|
|
26
|
-
name: string | undefined;
|
|
27
|
-
}) => ts.Expression,
|
|
28
|
-
) =>
|
|
29
|
-
ts.factory.createObjectLiteralExpression([
|
|
30
|
-
ts.factory.createPropertyAssignment(
|
|
31
|
-
ts.factory.createIdentifier("type"),
|
|
32
|
-
ts.factory.createStringLiteral(key),
|
|
33
|
-
),
|
|
34
|
-
ts.factory.createPropertyAssignment(
|
|
35
|
-
ts.factory.createIdentifier(key),
|
|
36
|
-
programmer({
|
|
37
|
-
context: {
|
|
38
|
-
...props.context,
|
|
39
|
-
options: {
|
|
40
|
-
numeric: false,
|
|
41
|
-
finite: false,
|
|
42
|
-
functional: false,
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
modulo: props.modulo,
|
|
46
|
-
type: props.type,
|
|
47
|
-
name: undefined,
|
|
48
|
-
}),
|
|
49
|
-
),
|
|
50
|
-
]);
|
|
51
|
-
|
|
52
|
-
// RETURNS
|
|
53
|
-
const category = props.context.options.validate;
|
|
54
|
-
if (category === "is" || category === "equals")
|
|
55
|
-
return parameter("is")(HttpIsHeadersProgrammer.write);
|
|
56
|
-
else if (
|
|
57
|
-
category === "validate" ||
|
|
58
|
-
category === "validateEquals" ||
|
|
59
|
-
category === "validateClone" ||
|
|
60
|
-
category === "validatePrune"
|
|
61
|
-
)
|
|
62
|
-
return parameter("validate")(HttpValidateHeadersProgrammer.write);
|
|
63
|
-
return parameter("assert")(HttpAssertHeadersProgrammer.write);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertHeadersProgrammer,
|
|
3
|
+
HttpIsHeadersProgrammer,
|
|
4
|
+
HttpValidateHeadersProgrammer,
|
|
5
|
+
ITypiaContext,
|
|
6
|
+
} from "@typia/core";
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
|
|
9
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
10
|
+
import { IRequestHeadersValidator } from "../options/IRequestHeadersValidator";
|
|
11
|
+
|
|
12
|
+
export namespace TypedHeadersProgrammer {
|
|
13
|
+
export const generate = (props: {
|
|
14
|
+
context: INestiaTransformContext;
|
|
15
|
+
modulo: ts.LeftHandSideExpression;
|
|
16
|
+
type: ts.Type;
|
|
17
|
+
}): ts.Expression => {
|
|
18
|
+
// GENERATE VALIDATION PLAN
|
|
19
|
+
const parameter =
|
|
20
|
+
(key: IRequestHeadersValidator<any>["type"]) =>
|
|
21
|
+
(
|
|
22
|
+
programmer: (next: {
|
|
23
|
+
context: ITypiaContext;
|
|
24
|
+
modulo: ts.LeftHandSideExpression;
|
|
25
|
+
type: ts.Type;
|
|
26
|
+
name: string | undefined;
|
|
27
|
+
}) => ts.Expression,
|
|
28
|
+
) =>
|
|
29
|
+
ts.factory.createObjectLiteralExpression([
|
|
30
|
+
ts.factory.createPropertyAssignment(
|
|
31
|
+
ts.factory.createIdentifier("type"),
|
|
32
|
+
ts.factory.createStringLiteral(key),
|
|
33
|
+
),
|
|
34
|
+
ts.factory.createPropertyAssignment(
|
|
35
|
+
ts.factory.createIdentifier(key),
|
|
36
|
+
programmer({
|
|
37
|
+
context: {
|
|
38
|
+
...props.context,
|
|
39
|
+
options: {
|
|
40
|
+
numeric: false,
|
|
41
|
+
finite: false,
|
|
42
|
+
functional: false,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
modulo: props.modulo,
|
|
46
|
+
type: props.type,
|
|
47
|
+
name: undefined,
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
]);
|
|
51
|
+
|
|
52
|
+
// RETURNS
|
|
53
|
+
const category = props.context.options.validate;
|
|
54
|
+
if (category === "is" || category === "equals")
|
|
55
|
+
return parameter("is")(HttpIsHeadersProgrammer.write);
|
|
56
|
+
else if (
|
|
57
|
+
category === "validate" ||
|
|
58
|
+
category === "validateEquals" ||
|
|
59
|
+
category === "validateClone" ||
|
|
60
|
+
category === "validatePrune"
|
|
61
|
+
)
|
|
62
|
+
return parameter("validate")(HttpValidateHeadersProgrammer.write);
|
|
63
|
+
return parameter("assert")(HttpAssertHeadersProgrammer.write);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import { HttpParameterProgrammer } from "@typia/core";
|
|
2
|
-
import ts from "typescript";
|
|
3
|
-
|
|
4
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
5
|
-
|
|
6
|
-
export namespace TypedParamProgrammer {
|
|
7
|
-
export const generate = (props: {
|
|
8
|
-
context: INestiaTransformContext;
|
|
9
|
-
modulo: ts.LeftHandSideExpression;
|
|
10
|
-
arguments: readonly ts.Expression[];
|
|
11
|
-
type: ts.Type;
|
|
12
|
-
}): readonly ts.Expression[] => {
|
|
13
|
-
// ALREADY BEING TRANSFORMED
|
|
14
|
-
if (props.arguments.length !== 1) return props.arguments;
|
|
15
|
-
return [
|
|
16
|
-
props.arguments[0]!,
|
|
17
|
-
HttpParameterProgrammer.write({
|
|
18
|
-
context: {
|
|
19
|
-
...props.context,
|
|
20
|
-
options: {
|
|
21
|
-
numeric: true,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
modulo: props.modulo,
|
|
25
|
-
type: props.type,
|
|
26
|
-
name: undefined,
|
|
27
|
-
}),
|
|
28
|
-
...(props.context.options?.validate?.startsWith("validate")
|
|
29
|
-
? [ts.factory.createTrue()]
|
|
30
|
-
: []),
|
|
31
|
-
];
|
|
32
|
-
};
|
|
33
|
-
}
|
|
1
|
+
import { HttpParameterProgrammer } from "@typia/core";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
|
|
4
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
5
|
+
|
|
6
|
+
export namespace TypedParamProgrammer {
|
|
7
|
+
export const generate = (props: {
|
|
8
|
+
context: INestiaTransformContext;
|
|
9
|
+
modulo: ts.LeftHandSideExpression;
|
|
10
|
+
arguments: readonly ts.Expression[];
|
|
11
|
+
type: ts.Type;
|
|
12
|
+
}): readonly ts.Expression[] => {
|
|
13
|
+
// ALREADY BEING TRANSFORMED
|
|
14
|
+
if (props.arguments.length !== 1) return props.arguments;
|
|
15
|
+
return [
|
|
16
|
+
props.arguments[0]!,
|
|
17
|
+
HttpParameterProgrammer.write({
|
|
18
|
+
context: {
|
|
19
|
+
...props.context,
|
|
20
|
+
options: {
|
|
21
|
+
numeric: true,
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
modulo: props.modulo,
|
|
25
|
+
type: props.type,
|
|
26
|
+
name: undefined,
|
|
27
|
+
}),
|
|
28
|
+
...(props.context.options?.validate?.startsWith("validate")
|
|
29
|
+
? [ts.factory.createTrue()]
|
|
30
|
+
: []),
|
|
31
|
+
];
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -1,111 +1,113 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HttpAssertQueryProgrammer,
|
|
3
|
-
HttpIsQueryProgrammer,
|
|
4
|
-
HttpQueryProgrammer,
|
|
5
|
-
HttpValidateQueryProgrammer,
|
|
6
|
-
ITypiaContext,
|
|
7
|
-
LlmSchemaProgrammer,
|
|
8
|
-
MetadataCollection,
|
|
9
|
-
MetadataFactory,
|
|
10
|
-
MetadataSchema,
|
|
11
|
-
TransformerError,
|
|
12
|
-
} from "@typia/core";
|
|
13
|
-
import { ValidationPipe } from "@typia/interface";
|
|
14
|
-
import ts from "typescript";
|
|
15
|
-
|
|
16
|
-
import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
|
|
17
|
-
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
18
|
-
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
19
|
-
|
|
20
|
-
export namespace TypedQueryBodyProgrammer {
|
|
21
|
-
export const generate = (props: {
|
|
22
|
-
context: INestiaTransformContext;
|
|
23
|
-
modulo: ts.LeftHandSideExpression;
|
|
24
|
-
type: ts.Type;
|
|
25
|
-
}): ts.ObjectLiteralExpression => {
|
|
26
|
-
// VALIDATE TYPE
|
|
27
|
-
if (props.context.options.llm) {
|
|
28
|
-
const llm: INestiaTransformOptions.ILlm =
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
ts.
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
category === "
|
|
106
|
-
category === "
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
1
|
+
import {
|
|
2
|
+
HttpAssertQueryProgrammer,
|
|
3
|
+
HttpIsQueryProgrammer,
|
|
4
|
+
HttpQueryProgrammer,
|
|
5
|
+
HttpValidateQueryProgrammer,
|
|
6
|
+
ITypiaContext,
|
|
7
|
+
LlmSchemaProgrammer,
|
|
8
|
+
MetadataCollection,
|
|
9
|
+
MetadataFactory,
|
|
10
|
+
MetadataSchema,
|
|
11
|
+
TransformerError,
|
|
12
|
+
} from "@typia/core";
|
|
13
|
+
import { ValidationPipe } from "@typia/interface";
|
|
14
|
+
import ts from "typescript";
|
|
15
|
+
|
|
16
|
+
import { INestiaTransformOptions } from "../options/INestiaTransformOptions";
|
|
17
|
+
import { INestiaTransformContext } from "../options/INestiaTransformProject";
|
|
18
|
+
import { IRequestQueryValidator } from "../options/IRequestQueryValidator";
|
|
19
|
+
|
|
20
|
+
export namespace TypedQueryBodyProgrammer {
|
|
21
|
+
export const generate = (props: {
|
|
22
|
+
context: INestiaTransformContext;
|
|
23
|
+
modulo: ts.LeftHandSideExpression;
|
|
24
|
+
type: ts.Type;
|
|
25
|
+
}): ts.ObjectLiteralExpression => {
|
|
26
|
+
// VALIDATE TYPE
|
|
27
|
+
if (props.context.options.llm) {
|
|
28
|
+
const llm: INestiaTransformOptions.ILlm | true =
|
|
29
|
+
props.context.options.llm;
|
|
30
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
31
|
+
MetadataFactory.analyze({
|
|
32
|
+
checker: props.context.checker,
|
|
33
|
+
transformer: props.context.transformer,
|
|
34
|
+
options: {
|
|
35
|
+
escape: false,
|
|
36
|
+
constant: true,
|
|
37
|
+
absorb: true,
|
|
38
|
+
validate: (next) => {
|
|
39
|
+
const errors: string[] = HttpQueryProgrammer.validate({
|
|
40
|
+
metadata: next.metadata,
|
|
41
|
+
explore: next.explore,
|
|
42
|
+
allowOptional: true,
|
|
43
|
+
});
|
|
44
|
+
errors.push(
|
|
45
|
+
...LlmSchemaProgrammer.validate({
|
|
46
|
+
config: {
|
|
47
|
+
strict: llm === true ? false : (llm.strict ?? false),
|
|
48
|
+
},
|
|
49
|
+
metadata: next.metadata,
|
|
50
|
+
explore: next.explore,
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
return errors;
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
components: new MetadataCollection(),
|
|
57
|
+
type: props.type,
|
|
58
|
+
});
|
|
59
|
+
if (result.success === false)
|
|
60
|
+
throw TransformerError.from({
|
|
61
|
+
code: props.modulo.getText(),
|
|
62
|
+
errors: result.errors,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// GENERATE VALIDATION PLAN
|
|
67
|
+
const parameter =
|
|
68
|
+
(key: IRequestQueryValidator<any>["type"]) =>
|
|
69
|
+
(
|
|
70
|
+
programmer: (next: {
|
|
71
|
+
context: ITypiaContext;
|
|
72
|
+
modulo: ts.LeftHandSideExpression;
|
|
73
|
+
type: ts.Type;
|
|
74
|
+
name: string | undefined;
|
|
75
|
+
}) => ts.Expression,
|
|
76
|
+
) =>
|
|
77
|
+
ts.factory.createObjectLiteralExpression([
|
|
78
|
+
ts.factory.createPropertyAssignment(
|
|
79
|
+
ts.factory.createIdentifier("type"),
|
|
80
|
+
ts.factory.createStringLiteral(key),
|
|
81
|
+
),
|
|
82
|
+
ts.factory.createPropertyAssignment(
|
|
83
|
+
ts.factory.createIdentifier(key),
|
|
84
|
+
programmer({
|
|
85
|
+
context: {
|
|
86
|
+
...props.context,
|
|
87
|
+
options: {
|
|
88
|
+
numeric: false,
|
|
89
|
+
finite: false,
|
|
90
|
+
functional: false,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
modulo: props.modulo,
|
|
94
|
+
type: props.type,
|
|
95
|
+
name: undefined,
|
|
96
|
+
}),
|
|
97
|
+
),
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
// RETURNS
|
|
101
|
+
const category = props.context.options.validate;
|
|
102
|
+
if (category === "is" || category === "equals")
|
|
103
|
+
return parameter("is")(HttpIsQueryProgrammer.write);
|
|
104
|
+
else if (
|
|
105
|
+
category === "validate" ||
|
|
106
|
+
category === "validateEquals" ||
|
|
107
|
+
category === "validateClone" ||
|
|
108
|
+
category === "validatePrune"
|
|
109
|
+
)
|
|
110
|
+
return parameter("validate")(HttpValidateQueryProgrammer.write);
|
|
111
|
+
return parameter("assert")(HttpAssertQueryProgrammer.write);
|
|
112
|
+
};
|
|
113
|
+
}
|