@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 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 === 'FILE' ? {
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 = `/${(0, _vtils.snakeCase)(handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1]).replace(/_/g, '/')}/`.replace(/\/{2,}/g, '/');
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) || 'ROOT';
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];
@@ -45,7 +45,8 @@ class Server {
45
45
  this.fastify = (0, _fastify.default)({
46
46
  logger: process.env.NODE_ENV === 'development' ? {
47
47
  prettyPrint: true
48
- } : false
48
+ } : false,
49
+ ...this.options.fastifyOptions
49
50
  });
50
51
  }
51
52
 
@@ -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 === 'FILE' ? {
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 = `/${snakeCase(handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1]).replace(/_/g, '/')}/`.replace(/\/{2,}/g, '/');
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) || 'ROOT';
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];
@@ -32,7 +32,8 @@ export class Server {
32
32
  this.fastify = Fastify({
33
33
  logger: process.env.NODE_ENV === 'development' ? {
34
34
  prettyPrint: true
35
- } : false
35
+ } : false,
36
+ ...this.options.fastifyOptions
36
37
  });
37
38
  }
38
39
 
@@ -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
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "1.26.9",
3
+ "version": "1.27.2",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",