@jayfong/x-server 1.26.9 → 1.27.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/CHANGELOG.md +21 -0
- package/lib/_cjs/cli/api_generator.js +22 -3
- package/lib/_cjs/core/server.js +2 -1
- package/lib/cli/api_generator.js +22 -3
- package/lib/core/server.js +2 -1
- package/lib/core/types.d.ts +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.27.2](https://github.com/jfWorks/x-server/compare/v1.27.1...v1.27.2) (2022-05-11)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* api gen GET ([601d94a](https://github.com/jfWorks/x-server/commit/601d94a9abd4a33a91f805dae74a0a471ba2cd59))
|
|
11
|
+
|
|
12
|
+
### [1.27.1](https://github.com/jfWorks/x-server/compare/v1.27.0...v1.27.1) (2022-05-08)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Bug Fixes
|
|
16
|
+
|
|
17
|
+
* api ([d30109c](https://github.com/jfWorks/x-server/commit/d30109ce90db1f3f9c513b9867be6123bc6373e6))
|
|
18
|
+
|
|
19
|
+
## [1.27.0](https://github.com/jfWorks/x-server/compare/v1.26.9...v1.27.0) (2022-05-07)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* 添加 fastifyOptions ([0be0509](https://github.com/jfWorks/x-server/commit/0be0509adb2bfcc24ff0122b1f5d52a155370738))
|
|
25
|
+
|
|
5
26
|
### [1.26.9](https://github.com/jfWorks/x-server/compare/v1.26.8...v1.26.9) (2022-05-07)
|
|
6
27
|
|
|
7
28
|
|
|
@@ -186,7 +186,25 @@ class ApiGenerator {
|
|
|
186
186
|
|
|
187
187
|
for (const handle of handles) {
|
|
188
188
|
data[handle.category] = data[handle.category] || [];
|
|
189
|
-
data[handle.category].push(handle.handlerMethod === '
|
|
189
|
+
data[handle.category].push(handle.handlerMethod === 'GET' ? {
|
|
190
|
+
method: handle.method.toUpperCase(),
|
|
191
|
+
title: handle.name,
|
|
192
|
+
path: handle.path,
|
|
193
|
+
req_body_type: 'query',
|
|
194
|
+
res_body_type: 'json',
|
|
195
|
+
req_body_is_json_schema: false,
|
|
196
|
+
res_body_is_json_schema: true,
|
|
197
|
+
req_params: [],
|
|
198
|
+
req_query: handle.requestData.children.map(item => ({
|
|
199
|
+
required: item.required ? 1 : 0,
|
|
200
|
+
name: item.name,
|
|
201
|
+
desc: item.desc,
|
|
202
|
+
type: 'string'
|
|
203
|
+
})),
|
|
204
|
+
req_headers: [],
|
|
205
|
+
req_body_form: [],
|
|
206
|
+
res_body: JSON.stringify(handle.responseDataJsonSchema)
|
|
207
|
+
} : handle.handlerMethod === 'FILE' ? {
|
|
190
208
|
method: handle.method.toUpperCase(),
|
|
191
209
|
title: handle.name,
|
|
192
210
|
path: handle.path,
|
|
@@ -200,6 +218,7 @@ class ApiGenerator {
|
|
|
200
218
|
req_body_form: handle.requestData.children.map(item => ({
|
|
201
219
|
required: item.required ? 1 : 0,
|
|
202
220
|
name: item.name,
|
|
221
|
+
desc: item.desc,
|
|
203
222
|
type: item.type === 'file' ? 'file' : 'text'
|
|
204
223
|
})),
|
|
205
224
|
res_body: JSON.stringify(handle.responseDataJsonSchema)
|
|
@@ -241,7 +260,7 @@ class ApiGenerator {
|
|
|
241
260
|
|
|
242
261
|
for (const handlerList of handlerGroup) {
|
|
243
262
|
const handlerListSourceFile = this.getTypeBySymbol(handlerList).getProperties()[0].getDeclarations()[0].getSourceFile();
|
|
244
|
-
const basePath = `/${
|
|
263
|
+
const basePath = `/${handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1].replace(/(^|\/)index$/, '/').split('/').map(v => (0, _vtils.snakeCase)(v)).join('/')}/`.replace(/\/{2,}/g, '/');
|
|
245
264
|
|
|
246
265
|
for (const handler of handlerListSourceFile.getVariableStatements().filter(item => item.isExported())) {
|
|
247
266
|
// 重要:这一步必须,先调一遍 getText 获取看到的对象,后续对于复杂定义才不会报错
|
|
@@ -259,7 +278,7 @@ class ApiGenerator {
|
|
|
259
278
|
continue;
|
|
260
279
|
}
|
|
261
280
|
|
|
262
|
-
const handlerCategory = (0, _vtils.pascalCase)(basePath) || '
|
|
281
|
+
const handlerCategory = (0, _vtils.pascalCase)(basePath) || 'Index';
|
|
263
282
|
const handlerName = handlerComment.description || handlerPath;
|
|
264
283
|
const handlerMethod = methodType.getLiteralValueOrThrow();
|
|
265
284
|
const serverMethod = _http_method.HandlerMethodToHttpMethod[handlerMethod];
|
package/lib/_cjs/core/server.js
CHANGED
package/lib/cli/api_generator.js
CHANGED
|
@@ -170,7 +170,25 @@ export class ApiGenerator {
|
|
|
170
170
|
|
|
171
171
|
for (const handle of handles) {
|
|
172
172
|
data[handle.category] = data[handle.category] || [];
|
|
173
|
-
data[handle.category].push(handle.handlerMethod === '
|
|
173
|
+
data[handle.category].push(handle.handlerMethod === 'GET' ? {
|
|
174
|
+
method: handle.method.toUpperCase(),
|
|
175
|
+
title: handle.name,
|
|
176
|
+
path: handle.path,
|
|
177
|
+
req_body_type: 'query',
|
|
178
|
+
res_body_type: 'json',
|
|
179
|
+
req_body_is_json_schema: false,
|
|
180
|
+
res_body_is_json_schema: true,
|
|
181
|
+
req_params: [],
|
|
182
|
+
req_query: handle.requestData.children.map(item => ({
|
|
183
|
+
required: item.required ? 1 : 0,
|
|
184
|
+
name: item.name,
|
|
185
|
+
desc: item.desc,
|
|
186
|
+
type: 'string'
|
|
187
|
+
})),
|
|
188
|
+
req_headers: [],
|
|
189
|
+
req_body_form: [],
|
|
190
|
+
res_body: JSON.stringify(handle.responseDataJsonSchema)
|
|
191
|
+
} : handle.handlerMethod === 'FILE' ? {
|
|
174
192
|
method: handle.method.toUpperCase(),
|
|
175
193
|
title: handle.name,
|
|
176
194
|
path: handle.path,
|
|
@@ -184,6 +202,7 @@ export class ApiGenerator {
|
|
|
184
202
|
req_body_form: handle.requestData.children.map(item => ({
|
|
185
203
|
required: item.required ? 1 : 0,
|
|
186
204
|
name: item.name,
|
|
205
|
+
desc: item.desc,
|
|
187
206
|
type: item.type === 'file' ? 'file' : 'text'
|
|
188
207
|
})),
|
|
189
208
|
res_body: JSON.stringify(handle.responseDataJsonSchema)
|
|
@@ -225,7 +244,7 @@ export class ApiGenerator {
|
|
|
225
244
|
|
|
226
245
|
for (const handlerList of handlerGroup) {
|
|
227
246
|
const handlerListSourceFile = this.getTypeBySymbol(handlerList).getProperties()[0].getDeclarations()[0].getSourceFile();
|
|
228
|
-
const basePath = `/${
|
|
247
|
+
const basePath = `/${handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1].replace(/(^|\/)index$/, '/').split('/').map(v => snakeCase(v)).join('/')}/`.replace(/\/{2,}/g, '/');
|
|
229
248
|
|
|
230
249
|
for (const handler of handlerListSourceFile.getVariableStatements().filter(item => item.isExported())) {
|
|
231
250
|
// 重要:这一步必须,先调一遍 getText 获取看到的对象,后续对于复杂定义才不会报错
|
|
@@ -243,7 +262,7 @@ export class ApiGenerator {
|
|
|
243
262
|
continue;
|
|
244
263
|
}
|
|
245
264
|
|
|
246
|
-
const handlerCategory = pascalCase(basePath) || '
|
|
265
|
+
const handlerCategory = pascalCase(basePath) || 'Index';
|
|
247
266
|
const handlerName = handlerComment.description || handlerPath;
|
|
248
267
|
const handlerMethod = methodType.getLiteralValueOrThrow();
|
|
249
268
|
const serverMethod = HandlerMethodToHttpMethod[handlerMethod];
|
package/lib/core/server.js
CHANGED
package/lib/core/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { BasePlugin } from '../plugins/base';
|
|
3
3
|
import { BaseService } from '../services/base';
|
|
4
|
-
import { FastifyReply, FastifyRequest } from 'fastify';
|
|
4
|
+
import { FastifyReply, FastifyRequest, FastifyServerOptions } from 'fastify';
|
|
5
5
|
import { yup } from 'vtils/validator';
|
|
6
6
|
import type { AsyncOrSync, LiteralUnion, OneOrMore, RequiredDeep } from 'vtils/types';
|
|
7
7
|
import type { DisposeService } from '../services/dispose';
|
|
@@ -31,6 +31,10 @@ export declare namespace XServer {
|
|
|
31
31
|
* 监听端口
|
|
32
32
|
*/
|
|
33
33
|
port: number;
|
|
34
|
+
/**
|
|
35
|
+
* 透传给 Fastify 的选项
|
|
36
|
+
*/
|
|
37
|
+
fastifyOptions?: FastifyServerOptions;
|
|
34
38
|
/**
|
|
35
39
|
* 服务列表
|
|
36
40
|
*/
|