@jayfong/x-server 2.111.0 → 2.113.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.
|
@@ -258,6 +258,7 @@ class ApiGenerator {
|
|
|
258
258
|
const isIntersection = type.isIntersection();
|
|
259
259
|
const intersectionTypes = isIntersection && type.types || [];
|
|
260
260
|
const isDate = valueSymbolName === 'Date';
|
|
261
|
+
const isRegExp = valueSymbolName === 'RegExp';
|
|
261
262
|
const isBigIntLiteral = hasTypeFlag(_tsMorph.ts.TypeFlags.BigIntLiteral);
|
|
262
263
|
const isBigInt = hasTypeFlag(_tsMorph.ts.TypeFlags.BigInt) || isBigIntLiteral;
|
|
263
264
|
const isArray = valueSymbolName === 'Array' || valueSymbolName === 'ReadonlyArray';
|
|
@@ -266,7 +267,9 @@ class ApiGenerator {
|
|
|
266
267
|
// BigInt 类型视为字符串
|
|
267
268
|
isBigInt ||
|
|
268
269
|
// Date 类型视为字符串
|
|
269
|
-
isDate
|
|
270
|
+
isDate ||
|
|
271
|
+
// RegExp 类型视为字符串
|
|
272
|
+
isRegExp;
|
|
270
273
|
const isNumberLiteral = hasTypeFlag(_tsMorph.ts.TypeFlags.NumberLiteral);
|
|
271
274
|
const isNumber = hasTypeFlag(_tsMorph.ts.TypeFlags.Number) || isNumberLiteral;
|
|
272
275
|
const isBoolean = hasTypeFlag(_tsMorph.ts.TypeFlags.Boolean) || hasTypeFlag(_tsMorph.ts.TypeFlags.BooleanLiteral);
|
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
package/lib/_cjs/core/handler.js
CHANGED
|
@@ -22,6 +22,7 @@ class Handler {
|
|
|
22
22
|
this.options = options;
|
|
23
23
|
this.requestDataSchema = void 0;
|
|
24
24
|
this.requestDataSchemaVae = void 0;
|
|
25
|
+
this.requestHandle = void 0;
|
|
25
26
|
this.handle = async (data, ctx) => {
|
|
26
27
|
// 前置 hook
|
|
27
28
|
if (Handler.hooks.length) {
|
|
@@ -72,7 +73,7 @@ class Handler {
|
|
|
72
73
|
}
|
|
73
74
|
}
|
|
74
75
|
try {
|
|
75
|
-
let res = await this.
|
|
76
|
+
let res = await this.requestHandle(data, ctx);
|
|
76
77
|
if (res instanceof _http_redirect.HttpRedirect) {
|
|
77
78
|
ctx.redirect(res.url, res.permanently);
|
|
78
79
|
return {};
|
|
@@ -188,6 +189,24 @@ class Handler {
|
|
|
188
189
|
} else if (options.requestDataSchema) {
|
|
189
190
|
this.requestDataSchema = options.requestDataSchema(_validator.yup);
|
|
190
191
|
}
|
|
192
|
+
if (options.concurrency != null) {
|
|
193
|
+
if (typeof options.concurrency === 'number') {
|
|
194
|
+
this.requestHandle = (0, _vtils.asyncLimit)(async (data, ctx) => options.handle(data, ctx), {
|
|
195
|
+
concurrency: options.concurrency
|
|
196
|
+
});
|
|
197
|
+
} else {
|
|
198
|
+
const {
|
|
199
|
+
count,
|
|
200
|
+
groupBy
|
|
201
|
+
} = options.concurrency;
|
|
202
|
+
this.requestHandle = (0, _vtils.asyncLimit)(async (data, ctx) => options.handle(data, ctx), {
|
|
203
|
+
concurrency: count,
|
|
204
|
+
groupBy: groupBy
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
} else {
|
|
208
|
+
this.requestHandle = options.handle;
|
|
209
|
+
}
|
|
191
210
|
}
|
|
192
211
|
static addHook(hook) {
|
|
193
212
|
this.hooks.push(hook);
|
package/lib/cli/api_generator.js
CHANGED
|
@@ -253,6 +253,7 @@ export class ApiGenerator {
|
|
|
253
253
|
const isIntersection = type.isIntersection();
|
|
254
254
|
const intersectionTypes = isIntersection && type.types || [];
|
|
255
255
|
const isDate = valueSymbolName === 'Date';
|
|
256
|
+
const isRegExp = valueSymbolName === 'RegExp';
|
|
256
257
|
const isBigIntLiteral = hasTypeFlag(ts.TypeFlags.BigIntLiteral);
|
|
257
258
|
const isBigInt = hasTypeFlag(ts.TypeFlags.BigInt) || isBigIntLiteral;
|
|
258
259
|
const isArray = valueSymbolName === 'Array' || valueSymbolName === 'ReadonlyArray';
|
|
@@ -261,7 +262,9 @@ export class ApiGenerator {
|
|
|
261
262
|
// BigInt 类型视为字符串
|
|
262
263
|
isBigInt ||
|
|
263
264
|
// Date 类型视为字符串
|
|
264
|
-
isDate
|
|
265
|
+
isDate ||
|
|
266
|
+
// RegExp 类型视为字符串
|
|
267
|
+
isRegExp;
|
|
265
268
|
const isNumberLiteral = hasTypeFlag(ts.TypeFlags.NumberLiteral);
|
|
266
269
|
const isNumber = hasTypeFlag(ts.TypeFlags.Number) || isNumberLiteral;
|
|
267
270
|
const isBoolean = hasTypeFlag(ts.TypeFlags.Boolean) || hasTypeFlag(ts.TypeFlags.BooleanLiteral);
|
package/lib/core/handler.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare class Handler<TReqData extends any = void, TResData extends any =
|
|
|
6
6
|
readonly options: XHandler.Options<TReqData, TResData, TReqMethod>;
|
|
7
7
|
private requestDataSchema;
|
|
8
8
|
readonly requestDataSchemaVae: vae.VaeSchemaOf<TReqDataRequired>;
|
|
9
|
+
private requestHandle;
|
|
9
10
|
constructor(options: XHandler.Options<TReqData, TResData, TReqMethod>);
|
|
10
11
|
handle: XHandler.Handle<TReqData, TResData, TReqMethod>;
|
|
11
12
|
private handleHttp;
|
package/lib/core/handler.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { HTTPError as GotHTTPError, ParseError as GotParseError, RequestError as GotRequestError, TimeoutError as GotTimeoutError } from 'got';
|
|
2
2
|
import LZString from 'lz-string';
|
|
3
|
-
import { base64UrlEncode, DataPacker, rot13, toSingleLineString } from 'vtils';
|
|
3
|
+
import { asyncLimit, base64UrlEncode, DataPacker, rot13, toSingleLineString } from 'vtils';
|
|
4
4
|
import * as vae from 'vtils/vae';
|
|
5
5
|
import { getZhCN, yup } from 'vtils/validator';
|
|
6
6
|
import { HttpError } from "../core/http_error";
|
|
@@ -16,6 +16,7 @@ export class Handler {
|
|
|
16
16
|
this.options = options;
|
|
17
17
|
this.requestDataSchema = void 0;
|
|
18
18
|
this.requestDataSchemaVae = void 0;
|
|
19
|
+
this.requestHandle = void 0;
|
|
19
20
|
this.handle = async (data, ctx) => {
|
|
20
21
|
// 前置 hook
|
|
21
22
|
if (Handler.hooks.length) {
|
|
@@ -66,7 +67,7 @@ export class Handler {
|
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
try {
|
|
69
|
-
let res = await this.
|
|
70
|
+
let res = await this.requestHandle(data, ctx);
|
|
70
71
|
if (res instanceof HttpRedirect) {
|
|
71
72
|
ctx.redirect(res.url, res.permanently);
|
|
72
73
|
return {};
|
|
@@ -182,6 +183,24 @@ export class Handler {
|
|
|
182
183
|
} else if (options.requestDataSchema) {
|
|
183
184
|
this.requestDataSchema = options.requestDataSchema(yup);
|
|
184
185
|
}
|
|
186
|
+
if (options.concurrency != null) {
|
|
187
|
+
if (typeof options.concurrency === 'number') {
|
|
188
|
+
this.requestHandle = asyncLimit(async (data, ctx) => options.handle(data, ctx), {
|
|
189
|
+
concurrency: options.concurrency
|
|
190
|
+
});
|
|
191
|
+
} else {
|
|
192
|
+
const {
|
|
193
|
+
count,
|
|
194
|
+
groupBy
|
|
195
|
+
} = options.concurrency;
|
|
196
|
+
this.requestHandle = asyncLimit(async (data, ctx) => options.handle(data, ctx), {
|
|
197
|
+
concurrency: count,
|
|
198
|
+
groupBy: groupBy
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
this.requestHandle = options.handle;
|
|
203
|
+
}
|
|
185
204
|
}
|
|
186
205
|
static addHook(hook) {
|
|
187
206
|
this.hooks.push(hook);
|
package/lib/core/types.d.ts
CHANGED
|
@@ -167,6 +167,15 @@ export declare namespace XHandler {
|
|
|
167
167
|
* @default 默认为服务的设置
|
|
168
168
|
*/
|
|
169
169
|
useAsyncContext?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* 并发控制
|
|
172
|
+
*/
|
|
173
|
+
concurrency?: number | {
|
|
174
|
+
/** 并发数量 */
|
|
175
|
+
count?: number;
|
|
176
|
+
/** 分组函数 */
|
|
177
|
+
groupBy?: (data: TReqData, ctx: Context) => string;
|
|
178
|
+
};
|
|
170
179
|
/**
|
|
171
180
|
* 处理器
|
|
172
181
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jayfong/x-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.113.0",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "lib/_cjs/index.js",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"unplugin-macros": "^0.16.0",
|
|
80
80
|
"utf-8-validate": "^5.0.9",
|
|
81
81
|
"vscode-generate-index-standalone": "^1.7.1",
|
|
82
|
-
"vtils": "^4.
|
|
82
|
+
"vtils": "^4.138.0",
|
|
83
83
|
"yaml": "^2.3.1",
|
|
84
84
|
"yargs": "^17.4.1"
|
|
85
85
|
},
|