@nestia/sdk 1.0.1 → 1.0.2
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/assets/config/nestia.config.ts +16 -25
- package/lib/INestiaConfig.d.ts +36 -21
- package/lib/analyses/ControllerAnalyzer.js +21 -1
- package/lib/analyses/ControllerAnalyzer.js.map +1 -1
- package/lib/executable/internal/NestiaSdkConfig.js +168 -14
- package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
- package/lib/generates/FunctionGenerator.js +29 -9
- package/lib/generates/FunctionGenerator.js.map +1 -1
- package/lib/generates/SwaggerGenerator.d.ts +1 -1
- package/lib/generates/SwaggerGenerator.js +27 -7
- package/lib/generates/SwaggerGenerator.js.map +1 -1
- package/lib/structures/IRoute.d.ts +8 -0
- package/lib/structures/ISwaggerDocument.d.ts +95 -0
- package/lib/structures/{ISwagger.js → ISwaggerDocument.js} +1 -1
- package/lib/structures/ISwaggerDocument.js.map +1 -0
- package/package.json +3 -3
- package/src/INestiaConfig.ts +44 -21
- package/src/analyses/ControllerAnalyzer.ts +21 -1
- package/src/generates/FunctionGenerator.ts +49 -11
- package/src/generates/SwaggerGenerator.ts +47 -18
- package/src/structures/IRoute.ts +4 -0
- package/src/structures/ISwaggerDocument.ts +117 -0
- package/lib/structures/ISwagger.d.ts +0 -48
- package/lib/structures/ISwagger.js.map +0 -1
- package/src/structures/ISwagger.ts +0 -55
|
@@ -25,6 +25,7 @@ const MapUtil_1 = require("../utils/MapUtil");
|
|
|
25
25
|
var SwaggerGenerator;
|
|
26
26
|
(function (SwaggerGenerator) {
|
|
27
27
|
function generate(checker, config, routeList) {
|
|
28
|
+
var _a;
|
|
28
29
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
30
|
// PREPARE ASSETS
|
|
30
31
|
const parsed = path_1.default.parse(config.output);
|
|
@@ -50,10 +51,13 @@ var SwaggerGenerator;
|
|
|
50
51
|
const application = ApplicationProgrammer_1.ApplicationProgrammer.generate(tupleList.map(({ metadata }) => metadata), {
|
|
51
52
|
purpose: "swagger",
|
|
52
53
|
});
|
|
53
|
-
swagger.components = Object.assign(Object.assign({}, (swagger.components
|
|
54
|
+
swagger.components = Object.assign(Object.assign({}, ((_a = swagger.components) !== null && _a !== void 0 ? _a : {})), { schemas: application.components.schemas });
|
|
54
55
|
tupleList.forEach(({ schema }, index) => {
|
|
55
56
|
Object.assign(schema, application.schemas[index]);
|
|
56
57
|
});
|
|
58
|
+
// CONFIGURE SECURITY
|
|
59
|
+
if (config.security)
|
|
60
|
+
fill_security(config.security, swagger);
|
|
57
61
|
// ERASE IJsonComponents.IObject.$id
|
|
58
62
|
for (const obj of Object.values(swagger.components.schemas))
|
|
59
63
|
if (obj.$id)
|
|
@@ -116,17 +120,34 @@ var SwaggerGenerator;
|
|
|
116
120
|
: undefined,
|
|
117
121
|
responses: generate_response_body(checker, collection, tupleList, route),
|
|
118
122
|
description: CommentFactory_1.CommentFactory.generate(route.comments),
|
|
123
|
+
"x-nestia-jsDocTags": route.tags,
|
|
119
124
|
};
|
|
120
125
|
}
|
|
126
|
+
function fill_security(security, swagger) {
|
|
127
|
+
var _a;
|
|
128
|
+
(_a = swagger.security) !== null && _a !== void 0 ? _a : (swagger.security = []);
|
|
129
|
+
swagger.components.securitySchemes = {};
|
|
130
|
+
for (const [key, value] of Object.entries(security)) {
|
|
131
|
+
swagger.security.push(key);
|
|
132
|
+
swagger.components.securitySchemes[key] = emend_security(value);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
function emend_security(input) {
|
|
136
|
+
var _a, _b;
|
|
137
|
+
if (input.type === "apiKey")
|
|
138
|
+
return Object.assign(Object.assign({}, input), { in: (_a = input.in) !== null && _a !== void 0 ? _a : "header", name: (_b = input.name) !== null && _b !== void 0 ? _b : "Authorization" });
|
|
139
|
+
return input;
|
|
140
|
+
}
|
|
121
141
|
/* ---------------------------------------------------------
|
|
122
142
|
REQUEST & RESPONSE
|
|
123
143
|
--------------------------------------------------------- */
|
|
124
144
|
function generate_parameter(checker, collection, tupleList, route, parameter) {
|
|
145
|
+
var _a;
|
|
125
146
|
const schema = generate_schema(checker, collection, tupleList, parameter.type.type);
|
|
126
147
|
if (schema === null)
|
|
127
148
|
throw new Error(`Error on NestiaApplication.sdk(): invalid parameter type on ${route.symbol}#${parameter.name}`);
|
|
128
149
|
return {
|
|
129
|
-
name: parameter.field
|
|
150
|
+
name: (_a = parameter.field) !== null && _a !== void 0 ? _a : parameter.name,
|
|
130
151
|
in: parameter.category === "param" ? "path" : parameter.category,
|
|
131
152
|
description: get_parametric_description(route, "param", parameter.name) ||
|
|
132
153
|
"",
|
|
@@ -135,13 +156,13 @@ var SwaggerGenerator;
|
|
|
135
156
|
};
|
|
136
157
|
}
|
|
137
158
|
function generate_request_body(checker, collection, tupleList, route, parameter) {
|
|
159
|
+
var _a;
|
|
138
160
|
const schema = generate_schema(checker, collection, tupleList, parameter.type.type);
|
|
139
161
|
if (schema === null)
|
|
140
162
|
throw new Error(`Error on NestiaApplication.sdk(): invalid request body type on ${route.symbol}.`);
|
|
141
163
|
return {
|
|
142
164
|
description: warning.get(parameter.encrypted).get("request") +
|
|
143
|
-
(get_parametric_description(route, "param", parameter.name)
|
|
144
|
-
""),
|
|
165
|
+
((_a = get_parametric_description(route, "param", parameter.name)) !== null && _a !== void 0 ? _a : ""),
|
|
145
166
|
content: {
|
|
146
167
|
"application/json": {
|
|
147
168
|
schema,
|
|
@@ -151,15 +172,14 @@ var SwaggerGenerator;
|
|
|
151
172
|
};
|
|
152
173
|
}
|
|
153
174
|
function generate_response_body(checker, collection, tupleList, route) {
|
|
175
|
+
var _a, _b;
|
|
154
176
|
// OUTPUT WITH SUCCESS STATUS
|
|
155
177
|
const status = route.method === "GET" || route.method === "DELETE" ? "200" : "201";
|
|
156
178
|
const schema = generate_schema(checker, collection, tupleList, route.output.type);
|
|
157
179
|
const success = {
|
|
158
180
|
[status]: {
|
|
159
181
|
description: warning.get(route.encrypted).get("response", route.method) +
|
|
160
|
-
(get_parametric_description(route, "return")
|
|
161
|
-
get_parametric_description(route, "returns") ||
|
|
162
|
-
""),
|
|
182
|
+
((_b = (_a = get_parametric_description(route, "return")) !== null && _a !== void 0 ? _a : get_parametric_description(route, "returns")) !== null && _b !== void 0 ? _b : ""),
|
|
163
183
|
content: schema === null || route.output.name === "void"
|
|
164
184
|
? undefined
|
|
165
185
|
: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SwaggerGenerator.js","sourceRoot":"","sources":["../../src/generates/SwaggerGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAA4B;AAC5B,qDAAkD;AAClD,qEAAkE;AAGlE,uEAAoE;AACpE,+EAA4E;AAC5E,yEAAsE;AAEtE,uFAAoF;AAKpF,8CAA2C;AAE3C,IAAiB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"SwaggerGenerator.js","sourceRoot":"","sources":["../../src/generates/SwaggerGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,4CAAoB;AACpB,gDAA4B;AAC5B,qDAAkD;AAClD,qEAAkE;AAGlE,uEAAoE;AACpE,+EAA4E;AAC5E,yEAAsE;AAEtE,uFAAoF;AAKpF,8CAA2C;AAE3C,IAAiB,gBAAgB,CAgXhC;AAhXD,WAAiB,gBAAgB;IAC7B,SAAsB,QAAQ,CAC1B,OAAuB,EACvB,MAAoC,EACpC,SAAmB;;;YAEnB,iBAAiB;YACjB,MAAM,MAAM,GAAwB,cAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAClE,MAAM,QAAQ,GAAW,CAAC,CAAC,MAAM,CAAC,GAAG;gBACjC,CAAC,CAAC,cAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC;gBACjC,CAAC,CAAC,cAAQ,CAAC,IAAI,CAAC,cAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,cAA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,CAAC,CAAC,oCAAoC,CAAC;QAE/C,MAAM,SAAS,GACX,IAAI,KAAK,SAAS;YACd,CAAC,CAAC,wEAAwE;YAC1E,CAAC,CAAC,mBAAmB,MAAO,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,MAAO;iBACjD,SAAS,CAAC,CAAC,CAAC;iBACZ,WAAW,EAAE,2DAA2D,CAAC;QAExF,OAAO;EACjB,OAAO;;MAEH,IAAI,8GAA8G,SAAS;;;;;;CAMhI,CAAC;IACM,CAAC,CACJ,CAAC;AACN,CAAC,CAAC,CAAC"}
|
|
@@ -12,6 +12,14 @@ export interface IRoute {
|
|
|
12
12
|
symbol: string;
|
|
13
13
|
comments: ts.SymbolDisplayPart[];
|
|
14
14
|
tags: ts.JSDocTagInfo[];
|
|
15
|
+
setHeaders: Array<{
|
|
16
|
+
type: "setter";
|
|
17
|
+
source: string;
|
|
18
|
+
target?: string;
|
|
19
|
+
} | {
|
|
20
|
+
type: "assigner";
|
|
21
|
+
source: string;
|
|
22
|
+
}>;
|
|
15
23
|
}
|
|
16
24
|
export declare namespace IRoute {
|
|
17
25
|
interface IParameter {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { IJsonComponents, IJsonSchema } from "typia";
|
|
2
|
+
import { IJsDocTagInfo } from "typia/lib/metadata/IJsDocTagInfo";
|
|
3
|
+
export interface ISwaggerDocument {
|
|
4
|
+
openapi: "3.0";
|
|
5
|
+
servers: ISwaggerDocument.IServer[];
|
|
6
|
+
info: ISwaggerDocument.IInfo;
|
|
7
|
+
components: ISwaggerDocument.IComponents;
|
|
8
|
+
security?: string[];
|
|
9
|
+
paths: Record<string, ISwaggerDocument.IPath>;
|
|
10
|
+
}
|
|
11
|
+
export declare namespace ISwaggerDocument {
|
|
12
|
+
interface IServer {
|
|
13
|
+
url: string;
|
|
14
|
+
description?: string;
|
|
15
|
+
}
|
|
16
|
+
interface IInfo {
|
|
17
|
+
version: string;
|
|
18
|
+
title: string;
|
|
19
|
+
}
|
|
20
|
+
interface IComponents extends IJsonComponents {
|
|
21
|
+
securitySchemes?: Record<string, ISecurityScheme>;
|
|
22
|
+
}
|
|
23
|
+
type ISecurityScheme = ISecurityScheme.IHttpBasic | ISecurityScheme.IHttpBearer | ISecurityScheme.IApiKey | ISecurityScheme.IOpenId | ISecurityScheme.IOAuth2;
|
|
24
|
+
namespace ISecurityScheme {
|
|
25
|
+
interface IHttpBasic {
|
|
26
|
+
type: "http";
|
|
27
|
+
schema: "basic";
|
|
28
|
+
}
|
|
29
|
+
interface IHttpBearer {
|
|
30
|
+
type: "http";
|
|
31
|
+
scheme: "bearer";
|
|
32
|
+
bearerFormat?: string;
|
|
33
|
+
}
|
|
34
|
+
interface IApiKey {
|
|
35
|
+
type: "apiKey";
|
|
36
|
+
in: "header" | "query" | "cookie";
|
|
37
|
+
name: string;
|
|
38
|
+
}
|
|
39
|
+
interface IOpenId {
|
|
40
|
+
type: "openIdConnect";
|
|
41
|
+
openIdConnectUrl: string;
|
|
42
|
+
}
|
|
43
|
+
interface IOAuth2 {
|
|
44
|
+
type: "oauth2";
|
|
45
|
+
flows: IOAuth2.IFlowSet;
|
|
46
|
+
description?: string;
|
|
47
|
+
}
|
|
48
|
+
namespace IOAuth2 {
|
|
49
|
+
interface IFlowSet {
|
|
50
|
+
authorizationCode?: IFlow;
|
|
51
|
+
implicit?: Omit<IFlow, "tokenUrl">;
|
|
52
|
+
password?: Omit<IFlow, "authorizationUrl">;
|
|
53
|
+
clientCredentials?: Omit<IFlow, "authorizationUrl">;
|
|
54
|
+
}
|
|
55
|
+
interface IFlow {
|
|
56
|
+
authorizationUrl: string;
|
|
57
|
+
tokenUrl: string;
|
|
58
|
+
refreshUrl: string;
|
|
59
|
+
scopes?: Record<string, string>;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
type IPath = Record<string, IRoute>;
|
|
64
|
+
interface IRoute {
|
|
65
|
+
tags: string[];
|
|
66
|
+
parameters: IParameter[];
|
|
67
|
+
requestBody?: IRequestBody;
|
|
68
|
+
responses: IResponseBody;
|
|
69
|
+
summary?: string;
|
|
70
|
+
description: string;
|
|
71
|
+
security?: string[];
|
|
72
|
+
"x-nestia-jsDocTags": IJsDocTagInfo[];
|
|
73
|
+
}
|
|
74
|
+
interface IParameter {
|
|
75
|
+
name: string;
|
|
76
|
+
in: string;
|
|
77
|
+
schema: IJsonSchema;
|
|
78
|
+
required: true;
|
|
79
|
+
description: string;
|
|
80
|
+
}
|
|
81
|
+
interface IRequestBody {
|
|
82
|
+
description: string;
|
|
83
|
+
content: IJsonContent;
|
|
84
|
+
required: true;
|
|
85
|
+
}
|
|
86
|
+
type IResponseBody = Record<string, {
|
|
87
|
+
description: string;
|
|
88
|
+
content?: IJsonContent;
|
|
89
|
+
}>;
|
|
90
|
+
interface IJsonContent {
|
|
91
|
+
"application/json": {
|
|
92
|
+
schema: IJsonSchema;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ISwaggerDocument.js","sourceRoot":"","sources":["../../src/structures/ISwaggerDocument.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestia/sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Nestia SDK and Swagger generator",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/samchon/nestia",
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@nestia/core": "^1.0.
|
|
35
|
+
"@nestia/core": "^1.0.7",
|
|
36
36
|
"@nestia/fetcher": "^1.0.0",
|
|
37
37
|
"@trivago/prettier-plugin-sort-imports": "^4.0.0",
|
|
38
38
|
"@types/cli": "^0.11.21",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tsconfck": "^2.0.1",
|
|
61
61
|
"tsconfig-paths": "^4.1.1",
|
|
62
62
|
"tstl": "^2.5.13",
|
|
63
|
-
"typia": "^3.4.
|
|
63
|
+
"typia": "^3.4.22"
|
|
64
64
|
},
|
|
65
65
|
"files": [
|
|
66
66
|
"assets",
|
package/src/INestiaConfig.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import ts from "typescript";
|
|
2
2
|
|
|
3
|
+
import { ISwaggerDocument } from "./structures/ISwaggerDocument";
|
|
3
4
|
import type { StripEnums } from "./utils/StripEnums";
|
|
4
5
|
|
|
5
6
|
/**
|
|
@@ -43,26 +44,23 @@ export interface INestiaConfig {
|
|
|
43
44
|
compilerOptions?: StripEnums<ts.CompilerOptions>;
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
|
-
* Whether to
|
|
47
|
+
* Whether to assert parameter types or not.
|
|
47
48
|
*
|
|
48
|
-
* If you configure this property to be `true`, all of the function parameters
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
* type safety even in the runtime level.
|
|
49
|
+
* If you configure this property to be `true`, all of the function parameters
|
|
50
|
+
* would be checked through [typia](https://github.com/samchon/typia#runtime-validators).
|
|
51
|
+
* This option would make your SDK library slower, but would enahcne the type safety
|
|
52
|
+
* even in the runtime level.
|
|
53
53
|
*
|
|
54
54
|
* @default false
|
|
55
55
|
*/
|
|
56
56
|
assert?: boolean;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
|
-
* Whether to
|
|
60
|
-
*
|
|
61
|
-
* If you configure this property to be `true`, all of the function parameters would be
|
|
62
|
-
* validate through the [`typia.assert()`](https://github.com/samchon/typia). function.
|
|
59
|
+
* Whether to optimize JSON string conversion 10x faster or not.
|
|
63
60
|
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
61
|
+
* If you configure this property to be `true`, the SDK library would utilize the
|
|
62
|
+
* [typia](https://github.com/samchon/typia#enhanced-json)
|
|
63
|
+
* and the JSON string conversion speed really be 10x faster.
|
|
66
64
|
*
|
|
67
65
|
* @default false
|
|
68
66
|
*/
|
|
@@ -72,13 +70,12 @@ export interface INestiaConfig {
|
|
|
72
70
|
* Whether to wrap DTO by primitive type.
|
|
73
71
|
*
|
|
74
72
|
* If you don't configure this property as `false`, all of DTOs in the
|
|
75
|
-
* SDK library would be automatically wrapped by {@link
|
|
76
|
-
* type.
|
|
73
|
+
* SDK library would be automatically wrapped by {@link Primitive} type.
|
|
77
74
|
*
|
|
78
|
-
* For refenrece, if a DTO type be capsuled by the {@link
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
75
|
+
* For refenrece, if a DTO type be capsuled by the {@link Primitive} type,
|
|
76
|
+
* all of methods in the DTO type would be automatically erased. Also, if
|
|
77
|
+
* the DTO has a `toJSON()` method, the DTO type would be automatically
|
|
78
|
+
* converted to return type of the `toJSON()` method.
|
|
82
79
|
*
|
|
83
80
|
* @default true
|
|
84
81
|
*/
|
|
@@ -89,7 +86,7 @@ export interface INestiaConfig {
|
|
|
89
86
|
*
|
|
90
87
|
* If not specified, you can't build the `swagger.json`.
|
|
91
88
|
*/
|
|
92
|
-
swagger?: INestiaConfig.
|
|
89
|
+
swagger?: INestiaConfig.ISwaggerConfig;
|
|
93
90
|
}
|
|
94
91
|
export namespace INestiaConfig {
|
|
95
92
|
/**
|
|
@@ -111,7 +108,7 @@ export namespace INestiaConfig {
|
|
|
111
108
|
/**
|
|
112
109
|
* Building `swagger.json` is also possible.
|
|
113
110
|
*/
|
|
114
|
-
export interface
|
|
111
|
+
export interface ISwaggerConfig {
|
|
115
112
|
/**
|
|
116
113
|
* Output path of the `swagger.json`.
|
|
117
114
|
*
|
|
@@ -120,5 +117,31 @@ export namespace INestiaConfig {
|
|
|
120
117
|
* `swagger.json` file would be renamed to it.
|
|
121
118
|
*/
|
|
122
119
|
output: string;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Security schemes.
|
|
123
|
+
*/
|
|
124
|
+
security?: Record<string, ISwaggerConfig.ISecurityScheme>;
|
|
125
|
+
}
|
|
126
|
+
export namespace ISwaggerConfig {
|
|
127
|
+
export type ISecurityScheme =
|
|
128
|
+
| IApiKey
|
|
129
|
+
| Exclude<
|
|
130
|
+
ISwaggerDocument.ISecurityScheme,
|
|
131
|
+
ISwaggerDocument.ISecurityScheme.IApiKey
|
|
132
|
+
>;
|
|
133
|
+
export interface IApiKey {
|
|
134
|
+
type: "apiKey";
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @default header
|
|
138
|
+
*/
|
|
139
|
+
in?: "header" | "query" | "cookie";
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @default Authorization
|
|
143
|
+
*/
|
|
144
|
+
name?: string;
|
|
145
|
+
}
|
|
123
146
|
}
|
|
124
147
|
}
|
|
@@ -125,6 +125,7 @@ export namespace ControllerAnalyzer {
|
|
|
125
125
|
.map((pair) => [pair.first, pair.second.toJSON()]);
|
|
126
126
|
|
|
127
127
|
// CONSTRUCT COMMON DATA
|
|
128
|
+
const tags = signature.getJsDocTags();
|
|
128
129
|
const common: Omit<IRoute, "path"> = {
|
|
129
130
|
...func,
|
|
130
131
|
parameters,
|
|
@@ -133,7 +134,26 @@ export namespace ControllerAnalyzer {
|
|
|
133
134
|
|
|
134
135
|
symbol: `${controller.name}.${func.name}()`,
|
|
135
136
|
comments: signature.getDocumentationComment(undefined),
|
|
136
|
-
tags
|
|
137
|
+
tags,
|
|
138
|
+
setHeaders: tags
|
|
139
|
+
.filter(
|
|
140
|
+
(t) =>
|
|
141
|
+
t.text?.length &&
|
|
142
|
+
t.text[0].text &&
|
|
143
|
+
(t.name === "setHeader" || t.name === "assignHeaders"),
|
|
144
|
+
)
|
|
145
|
+
.map((t) =>
|
|
146
|
+
t.name === "setHeader"
|
|
147
|
+
? {
|
|
148
|
+
type: "setter",
|
|
149
|
+
source: t.text![0].text.split(" ")[0].trim(),
|
|
150
|
+
target: t.text![0].text.split(" ")[1]?.trim(),
|
|
151
|
+
}
|
|
152
|
+
: {
|
|
153
|
+
type: "assigner",
|
|
154
|
+
source: t.text![0].text,
|
|
155
|
+
},
|
|
156
|
+
),
|
|
137
157
|
};
|
|
138
158
|
|
|
139
159
|
// CONFIGURE PATHS
|
|
@@ -47,21 +47,53 @@ export namespace FunctionGenerator {
|
|
|
47
47
|
const assertions: string =
|
|
48
48
|
config.assert === true && route.parameters.length !== 0
|
|
49
49
|
? route.parameters
|
|
50
|
-
.map(
|
|
50
|
+
.map(
|
|
51
|
+
(param) =>
|
|
52
|
+
` typia.assert<typeof ${param.name}>(${param.name});`,
|
|
53
|
+
)
|
|
51
54
|
.join("\n") + "\n\n"
|
|
52
55
|
: "";
|
|
53
56
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
"
|
|
57
|
-
assertions +
|
|
58
|
-
" return Fetcher.fetch\n" +
|
|
57
|
+
// FUNCTION CALL STATEMENT
|
|
58
|
+
const caller: string =
|
|
59
|
+
"Fetcher.fetch\n" +
|
|
59
60
|
" (\n" +
|
|
60
61
|
fetchArguments.map((param) => ` ${param}`).join(",\n") +
|
|
61
62
|
"\n" +
|
|
62
|
-
" )
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
" )";
|
|
64
|
+
if (route.setHeaders.length === 0)
|
|
65
|
+
return `{\n${assertions} return ${caller};\n}`;
|
|
66
|
+
|
|
67
|
+
// SET HEADERS
|
|
68
|
+
const content: string[] = [
|
|
69
|
+
`{\n`,
|
|
70
|
+
assertions,
|
|
71
|
+
` const output: ${route.name}.Output = await ${caller};\n`,
|
|
72
|
+
"\n",
|
|
73
|
+
` // configure header(s)\n`,
|
|
74
|
+
` connection.headers ??= {};\n`,
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
for (const header of route.setHeaders) {
|
|
78
|
+
if (header.type === "assigner")
|
|
79
|
+
content.push(
|
|
80
|
+
" ",
|
|
81
|
+
`Object.assign(connection.headers, ${access(
|
|
82
|
+
"output",
|
|
83
|
+
header.source,
|
|
84
|
+
)});\n`,
|
|
85
|
+
);
|
|
86
|
+
else
|
|
87
|
+
content.push(
|
|
88
|
+
" ",
|
|
89
|
+
`${access(
|
|
90
|
+
"connection.headers",
|
|
91
|
+
header.target ?? header.source,
|
|
92
|
+
)} = ${access("output", header.source)};\n`,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
content.push("\n", " return output;\n", "}");
|
|
96
|
+
return content.join("");
|
|
65
97
|
}
|
|
66
98
|
|
|
67
99
|
function filter_parameters(
|
|
@@ -77,6 +109,10 @@ export namespace FunctionGenerator {
|
|
|
77
109
|
return parameters;
|
|
78
110
|
}
|
|
79
111
|
|
|
112
|
+
function access(x: string, y: string): string {
|
|
113
|
+
return y[0] === "[" ? `${x}${y}` : `${x}.${y}`;
|
|
114
|
+
}
|
|
115
|
+
|
|
80
116
|
/* ---------------------------------------------------------
|
|
81
117
|
HEAD & TAIL
|
|
82
118
|
--------------------------------------------------------- */
|
|
@@ -171,7 +207,9 @@ export namespace FunctionGenerator {
|
|
|
171
207
|
comments.map((str) => ` * ${str}`).join("\n") +
|
|
172
208
|
"\n" +
|
|
173
209
|
" */\n" +
|
|
174
|
-
`export
|
|
210
|
+
`export${route.setHeaders ? " async" : ""} function ${
|
|
211
|
+
route.name
|
|
212
|
+
}\n` +
|
|
175
213
|
` (\n` +
|
|
176
214
|
`${parameters.map((str) => ` ${str}`).join(",\n")}\n` +
|
|
177
215
|
` ): Promise<${output}>`
|
|
@@ -228,7 +266,7 @@ export namespace FunctionGenerator {
|
|
|
228
266
|
(route.method === "POST" ||
|
|
229
267
|
route.method === "PUT" ||
|
|
230
268
|
route.method === "PATCH")
|
|
231
|
-
? ` export const stringify = typia.
|
|
269
|
+
? ` export const stringify = (input: Input) => typia.assertStringify(input);\n`
|
|
232
270
|
: "") +
|
|
233
271
|
"}"
|
|
234
272
|
);
|