@kevisual/router 0.0.53 → 0.0.55
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/dist/router-browser.d.ts +12 -14
- package/dist/router-browser.js +26 -108
- package/dist/router.d.ts +146 -166
- package/dist/router.js +9113 -9170
- package/package.json +3 -3
- package/src/browser.ts +3 -3
- package/src/index.ts +9 -11
- package/src/{connect.ts → modules/connect.ts} +1 -1
- package/src/route.ts +20 -0
package/dist/router-browser.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import * as node_querystring from 'node:querystring';
|
|
3
|
-
import { IncomingMessage } from 'node:http';
|
|
4
2
|
import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
|
|
5
3
|
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
6
4
|
|
|
@@ -109,6 +107,16 @@ type RouteOpts<U = {}, T = SimpleObject$1> = {
|
|
|
109
107
|
};
|
|
110
108
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
111
109
|
declare const pickValue: readonly ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
110
|
+
type Skill<T = SimpleObject$1> = {
|
|
111
|
+
skill: string;
|
|
112
|
+
title: string;
|
|
113
|
+
summary?: string;
|
|
114
|
+
args?: {
|
|
115
|
+
[key: string]: any;
|
|
116
|
+
};
|
|
117
|
+
} & T;
|
|
118
|
+
/** */
|
|
119
|
+
declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
|
|
112
120
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
113
121
|
declare class Route<U = {
|
|
114
122
|
[key: string]: any;
|
|
@@ -432,16 +440,6 @@ declare class CustomError extends Error {
|
|
|
432
440
|
};
|
|
433
441
|
}
|
|
434
442
|
|
|
435
|
-
declare const parseBody: <T = Record<string, any>>(req: IncomingMessage) => Promise<T>;
|
|
436
|
-
declare const parseSearch: (req: IncomingMessage) => node_querystring.ParsedUrlQuery;
|
|
437
|
-
/**
|
|
438
|
-
* 把url当个key 的 value 的字符串转成json
|
|
439
|
-
* @param value
|
|
440
|
-
*/
|
|
441
|
-
declare const parseSearchValue: (value?: string, opts?: {
|
|
442
|
-
decode?: boolean;
|
|
443
|
-
}) => any;
|
|
444
|
-
|
|
445
443
|
type RouteObject = {
|
|
446
444
|
[key: string]: RouteOpts$1;
|
|
447
445
|
};
|
|
@@ -512,5 +510,5 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
|
512
510
|
|
|
513
511
|
declare const App: typeof QueryRouterServer;
|
|
514
512
|
|
|
515
|
-
export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema,
|
|
516
|
-
export type { RouteArray, RouteContext, RouteObject, RouteOpts, Rule, Run, Schema };
|
|
513
|
+
export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, util };
|
|
514
|
+
export type { RouteArray, RouteContext, RouteObject, RouteOpts, Rule, Run, Schema, Skill };
|
package/dist/router-browser.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import url from 'node:url';
|
|
2
|
-
|
|
3
1
|
const urlAlphabet =
|
|
4
2
|
'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
|
|
5
3
|
|
|
@@ -147,6 +145,13 @@ const listenProcess = async ({ app, emitter, params, timeout = 10 * 60 * 60 * 10
|
|
|
147
145
|
};
|
|
148
146
|
|
|
149
147
|
const pickValue = ['path', 'key', 'id', 'description', 'type', 'middleware', 'metadata'];
|
|
148
|
+
/** */
|
|
149
|
+
const createSkill = (skill) => {
|
|
150
|
+
return {
|
|
151
|
+
args: {},
|
|
152
|
+
...skill
|
|
153
|
+
};
|
|
154
|
+
};
|
|
150
155
|
class Route {
|
|
151
156
|
/**
|
|
152
157
|
* 一级路径
|
|
@@ -3770,7 +3775,7 @@ function initializeContext(params) {
|
|
|
3770
3775
|
external: params?.external ?? undefined,
|
|
3771
3776
|
};
|
|
3772
3777
|
}
|
|
3773
|
-
function process
|
|
3778
|
+
function process(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
3774
3779
|
var _a;
|
|
3775
3780
|
const def = schema._zod.def;
|
|
3776
3781
|
// check for schema in seens
|
|
@@ -3814,7 +3819,7 @@ function process$1(schema, ctx, _params = { path: [], schemaPath: [] }) {
|
|
|
3814
3819
|
// Also set ref if processor didn't (for inheritance)
|
|
3815
3820
|
if (!result.ref)
|
|
3816
3821
|
result.ref = parent;
|
|
3817
|
-
process
|
|
3822
|
+
process(parent, ctx, params);
|
|
3818
3823
|
ctx.seen.get(parent).isParent = true;
|
|
3819
3824
|
}
|
|
3820
3825
|
}
|
|
@@ -4161,14 +4166,14 @@ function isTransforming(_schema, _ctx) {
|
|
|
4161
4166
|
*/
|
|
4162
4167
|
const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
4163
4168
|
const ctx = initializeContext({ ...params, processors });
|
|
4164
|
-
process
|
|
4169
|
+
process(schema, ctx);
|
|
4165
4170
|
extractDefs(ctx, schema);
|
|
4166
4171
|
return finalize(ctx, schema);
|
|
4167
4172
|
};
|
|
4168
4173
|
const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params) => {
|
|
4169
4174
|
const { libraryOptions, target } = params ?? {};
|
|
4170
4175
|
const ctx = initializeContext({ ...(libraryOptions ?? {}), target, io, processors });
|
|
4171
|
-
process
|
|
4176
|
+
process(schema, ctx);
|
|
4172
4177
|
extractDefs(ctx, schema);
|
|
4173
4178
|
return finalize(ctx, schema);
|
|
4174
4179
|
};
|
|
@@ -4307,7 +4312,7 @@ const arrayProcessor = (schema, ctx, _json, params) => {
|
|
|
4307
4312
|
if (typeof maximum === "number")
|
|
4308
4313
|
json.maxItems = maximum;
|
|
4309
4314
|
json.type = "array";
|
|
4310
|
-
json.items = process
|
|
4315
|
+
json.items = process(def.element, ctx, { ...params, path: [...params.path, "items"] });
|
|
4311
4316
|
};
|
|
4312
4317
|
const objectProcessor = (schema, ctx, _json, params) => {
|
|
4313
4318
|
const json = _json;
|
|
@@ -4316,7 +4321,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
4316
4321
|
json.properties = {};
|
|
4317
4322
|
const shape = def.shape;
|
|
4318
4323
|
for (const key in shape) {
|
|
4319
|
-
json.properties[key] = process
|
|
4324
|
+
json.properties[key] = process(shape[key], ctx, {
|
|
4320
4325
|
...params,
|
|
4321
4326
|
path: [...params.path, "properties", key],
|
|
4322
4327
|
});
|
|
@@ -4346,7 +4351,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
4346
4351
|
json.additionalProperties = false;
|
|
4347
4352
|
}
|
|
4348
4353
|
else if (def.catchall) {
|
|
4349
|
-
json.additionalProperties = process
|
|
4354
|
+
json.additionalProperties = process(def.catchall, ctx, {
|
|
4350
4355
|
...params,
|
|
4351
4356
|
path: [...params.path, "additionalProperties"],
|
|
4352
4357
|
});
|
|
@@ -4357,7 +4362,7 @@ const unionProcessor = (schema, ctx, json, params) => {
|
|
|
4357
4362
|
// Exclusive unions (inclusive === false) use oneOf (exactly one match) instead of anyOf (one or more matches)
|
|
4358
4363
|
// This includes both z.xor() and discriminated unions
|
|
4359
4364
|
const isExclusive = def.inclusive === false;
|
|
4360
|
-
const options = def.options.map((x, i) => process
|
|
4365
|
+
const options = def.options.map((x, i) => process(x, ctx, {
|
|
4361
4366
|
...params,
|
|
4362
4367
|
path: [...params.path, isExclusive ? "oneOf" : "anyOf", i],
|
|
4363
4368
|
}));
|
|
@@ -4370,11 +4375,11 @@ const unionProcessor = (schema, ctx, json, params) => {
|
|
|
4370
4375
|
};
|
|
4371
4376
|
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
4372
4377
|
const def = schema._zod.def;
|
|
4373
|
-
const a = process
|
|
4378
|
+
const a = process(def.left, ctx, {
|
|
4374
4379
|
...params,
|
|
4375
4380
|
path: [...params.path, "allOf", 0],
|
|
4376
4381
|
});
|
|
4377
|
-
const b = process
|
|
4382
|
+
const b = process(def.right, ctx, {
|
|
4378
4383
|
...params,
|
|
4379
4384
|
path: [...params.path, "allOf", 1],
|
|
4380
4385
|
});
|
|
@@ -4387,7 +4392,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
4387
4392
|
};
|
|
4388
4393
|
const nullableProcessor = (schema, ctx, json, params) => {
|
|
4389
4394
|
const def = schema._zod.def;
|
|
4390
|
-
const inner = process
|
|
4395
|
+
const inner = process(def.innerType, ctx, params);
|
|
4391
4396
|
const seen = ctx.seen.get(schema);
|
|
4392
4397
|
if (ctx.target === "openapi-3.0") {
|
|
4393
4398
|
seen.ref = def.innerType;
|
|
@@ -4399,20 +4404,20 @@ const nullableProcessor = (schema, ctx, json, params) => {
|
|
|
4399
4404
|
};
|
|
4400
4405
|
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
4401
4406
|
const def = schema._zod.def;
|
|
4402
|
-
process
|
|
4407
|
+
process(def.innerType, ctx, params);
|
|
4403
4408
|
const seen = ctx.seen.get(schema);
|
|
4404
4409
|
seen.ref = def.innerType;
|
|
4405
4410
|
};
|
|
4406
4411
|
const defaultProcessor = (schema, ctx, json, params) => {
|
|
4407
4412
|
const def = schema._zod.def;
|
|
4408
|
-
process
|
|
4413
|
+
process(def.innerType, ctx, params);
|
|
4409
4414
|
const seen = ctx.seen.get(schema);
|
|
4410
4415
|
seen.ref = def.innerType;
|
|
4411
4416
|
json.default = JSON.parse(JSON.stringify(def.defaultValue));
|
|
4412
4417
|
};
|
|
4413
4418
|
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
4414
4419
|
const def = schema._zod.def;
|
|
4415
|
-
process
|
|
4420
|
+
process(def.innerType, ctx, params);
|
|
4416
4421
|
const seen = ctx.seen.get(schema);
|
|
4417
4422
|
seen.ref = def.innerType;
|
|
4418
4423
|
if (ctx.io === "input")
|
|
@@ -4420,7 +4425,7 @@ const prefaultProcessor = (schema, ctx, json, params) => {
|
|
|
4420
4425
|
};
|
|
4421
4426
|
const catchProcessor = (schema, ctx, json, params) => {
|
|
4422
4427
|
const def = schema._zod.def;
|
|
4423
|
-
process
|
|
4428
|
+
process(def.innerType, ctx, params);
|
|
4424
4429
|
const seen = ctx.seen.get(schema);
|
|
4425
4430
|
seen.ref = def.innerType;
|
|
4426
4431
|
let catchValue;
|
|
@@ -4435,20 +4440,20 @@ const catchProcessor = (schema, ctx, json, params) => {
|
|
|
4435
4440
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
4436
4441
|
const def = schema._zod.def;
|
|
4437
4442
|
const innerType = ctx.io === "input" ? (def.in._zod.def.type === "transform" ? def.out : def.in) : def.out;
|
|
4438
|
-
process
|
|
4443
|
+
process(innerType, ctx, params);
|
|
4439
4444
|
const seen = ctx.seen.get(schema);
|
|
4440
4445
|
seen.ref = innerType;
|
|
4441
4446
|
};
|
|
4442
4447
|
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
4443
4448
|
const def = schema._zod.def;
|
|
4444
|
-
process
|
|
4449
|
+
process(def.innerType, ctx, params);
|
|
4445
4450
|
const seen = ctx.seen.get(schema);
|
|
4446
4451
|
seen.ref = def.innerType;
|
|
4447
4452
|
json.readOnly = true;
|
|
4448
4453
|
};
|
|
4449
4454
|
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
4450
4455
|
const def = schema._zod.def;
|
|
4451
|
-
process
|
|
4456
|
+
process(def.innerType, ctx, params);
|
|
4452
4457
|
const seen = ctx.seen.get(schema);
|
|
4453
4458
|
seen.ref = def.innerType;
|
|
4454
4459
|
};
|
|
@@ -5207,93 +5212,6 @@ const createSchema = (rule) => {
|
|
|
5207
5212
|
}
|
|
5208
5213
|
};
|
|
5209
5214
|
|
|
5210
|
-
typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
|
5211
|
-
// @ts-ignore
|
|
5212
|
-
typeof Deno !== 'undefined' && typeof Deno.version === 'object' && typeof Deno.version.deno === 'string';
|
|
5213
|
-
// @ts-ignore
|
|
5214
|
-
const isBun = typeof Bun !== 'undefined' && typeof Bun.version === 'string';
|
|
5215
|
-
|
|
5216
|
-
const parseBody = async (req) => {
|
|
5217
|
-
const resolveBody = (body) => {
|
|
5218
|
-
// 获取 Content-Type 头信息
|
|
5219
|
-
const contentType = req.headers['content-type'] || '';
|
|
5220
|
-
const resolve = (data) => {
|
|
5221
|
-
return data;
|
|
5222
|
-
};
|
|
5223
|
-
// 处理 application/json
|
|
5224
|
-
if (contentType.includes('application/json')) {
|
|
5225
|
-
return resolve(JSON.parse(body));
|
|
5226
|
-
}
|
|
5227
|
-
// 处理 application/x-www-form-urlencoded
|
|
5228
|
-
if (contentType.includes('application/x-www-form-urlencoded')) {
|
|
5229
|
-
const formData = new URLSearchParams(body);
|
|
5230
|
-
const result = {};
|
|
5231
|
-
formData.forEach((value, key) => {
|
|
5232
|
-
// 尝试将值解析为 JSON,如果失败则保留原始字符串
|
|
5233
|
-
try {
|
|
5234
|
-
result[key] = JSON.parse(value);
|
|
5235
|
-
}
|
|
5236
|
-
catch {
|
|
5237
|
-
result[key] = value;
|
|
5238
|
-
}
|
|
5239
|
-
});
|
|
5240
|
-
return resolve(result);
|
|
5241
|
-
}
|
|
5242
|
-
// 默认尝试 JSON 解析
|
|
5243
|
-
try {
|
|
5244
|
-
return resolve(JSON.parse(body));
|
|
5245
|
-
}
|
|
5246
|
-
catch {
|
|
5247
|
-
return resolve({});
|
|
5248
|
-
}
|
|
5249
|
-
};
|
|
5250
|
-
if (isBun) {
|
|
5251
|
-
// @ts-ignore
|
|
5252
|
-
const body = req.body;
|
|
5253
|
-
if (body) {
|
|
5254
|
-
return resolveBody(body);
|
|
5255
|
-
}
|
|
5256
|
-
return {};
|
|
5257
|
-
}
|
|
5258
|
-
return new Promise((resolve, reject) => {
|
|
5259
|
-
const arr = [];
|
|
5260
|
-
req.on('data', (chunk) => {
|
|
5261
|
-
arr.push(chunk);
|
|
5262
|
-
});
|
|
5263
|
-
req.on('end', () => {
|
|
5264
|
-
try {
|
|
5265
|
-
const body = Buffer.concat(arr).toString();
|
|
5266
|
-
resolve(resolveBody(body));
|
|
5267
|
-
}
|
|
5268
|
-
catch (e) {
|
|
5269
|
-
resolve({});
|
|
5270
|
-
}
|
|
5271
|
-
});
|
|
5272
|
-
});
|
|
5273
|
-
};
|
|
5274
|
-
const parseSearch = (req) => {
|
|
5275
|
-
const parsedUrl = url.parse(req.url, true);
|
|
5276
|
-
return parsedUrl.query;
|
|
5277
|
-
};
|
|
5278
|
-
/**
|
|
5279
|
-
* 把url当个key 的 value 的字符串转成json
|
|
5280
|
-
* @param value
|
|
5281
|
-
*/
|
|
5282
|
-
const parseSearchValue = (value, opts) => {
|
|
5283
|
-
if (!value)
|
|
5284
|
-
return {};
|
|
5285
|
-
const decode = opts?.decode ?? false;
|
|
5286
|
-
if (decode) {
|
|
5287
|
-
value = decodeURIComponent(value);
|
|
5288
|
-
}
|
|
5289
|
-
try {
|
|
5290
|
-
return JSON.parse(value);
|
|
5291
|
-
}
|
|
5292
|
-
catch (e) {
|
|
5293
|
-
return {};
|
|
5294
|
-
}
|
|
5295
|
-
};
|
|
5296
|
-
|
|
5297
5215
|
function define(value) {
|
|
5298
5216
|
return value;
|
|
5299
5217
|
}
|
|
@@ -5428,4 +5346,4 @@ class QueryUtil {
|
|
|
5428
5346
|
|
|
5429
5347
|
const App = QueryRouterServer;
|
|
5430
5348
|
|
|
5431
|
-
export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema,
|
|
5349
|
+
export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, createSkill, define, util };
|
package/dist/router.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
|
|
3
|
+
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
1
4
|
import * as http from 'node:http';
|
|
2
5
|
import http__default, { IncomingMessage, ServerResponse } from 'node:http';
|
|
3
6
|
import https from 'node:https';
|
|
4
7
|
import http2 from 'node:http2';
|
|
5
8
|
import { EventEmitter } from 'eventemitter3';
|
|
6
9
|
import { WebSocketServer } from 'ws';
|
|
7
|
-
import { z } from 'zod';
|
|
8
10
|
import { IncomingMessage as IncomingMessage$1, ServerResponse as ServerResponse$1 } from 'http';
|
|
9
|
-
import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
|
|
10
|
-
import { Query, DataOpts, Result } from '@kevisual/query/query';
|
|
11
11
|
|
|
12
12
|
type RouterContextT = {
|
|
13
13
|
code?: number;
|
|
@@ -114,6 +114,16 @@ type RouteOpts<U = {}, T = SimpleObject$1> = {
|
|
|
114
114
|
};
|
|
115
115
|
type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'nextRoute'>;
|
|
116
116
|
declare const pickValue: readonly ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
117
|
+
type Skill<T = SimpleObject$1> = {
|
|
118
|
+
skill: string;
|
|
119
|
+
title: string;
|
|
120
|
+
summary?: string;
|
|
121
|
+
args?: {
|
|
122
|
+
[key: string]: any;
|
|
123
|
+
};
|
|
124
|
+
} & T;
|
|
125
|
+
/** */
|
|
126
|
+
declare const createSkill: <T = SimpleObject$1>(skill: Skill<T>) => Skill<T>;
|
|
117
127
|
type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
|
|
118
128
|
declare class Route<U = {
|
|
119
129
|
[key: string]: any;
|
|
@@ -371,34 +381,138 @@ declare class QueryRouterServer extends QueryRouter {
|
|
|
371
381
|
declare class Mini extends QueryRouterServer {
|
|
372
382
|
}
|
|
373
383
|
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
384
|
+
type BaseRule = {
|
|
385
|
+
value?: any;
|
|
386
|
+
required?: boolean;
|
|
387
|
+
message?: string;
|
|
388
|
+
};
|
|
389
|
+
type RuleString = {
|
|
390
|
+
type: 'string';
|
|
391
|
+
min?: number;
|
|
392
|
+
max?: number;
|
|
393
|
+
regex?: string;
|
|
394
|
+
} & BaseRule;
|
|
395
|
+
type RuleNumber = {
|
|
396
|
+
type: 'number';
|
|
397
|
+
min?: number;
|
|
398
|
+
max?: number;
|
|
399
|
+
} & BaseRule;
|
|
400
|
+
type RuleBoolean = {
|
|
401
|
+
type: 'boolean';
|
|
402
|
+
} & BaseRule;
|
|
403
|
+
type RuleArray = {
|
|
404
|
+
type: 'array';
|
|
405
|
+
items: Rule;
|
|
406
|
+
} & BaseRule;
|
|
407
|
+
type RuleObject = {
|
|
408
|
+
type: 'object';
|
|
409
|
+
properties: {
|
|
410
|
+
[key: string]: Rule;
|
|
411
|
+
};
|
|
412
|
+
} & BaseRule;
|
|
413
|
+
type RuleAny = {
|
|
414
|
+
type: 'any';
|
|
415
|
+
} & BaseRule;
|
|
416
|
+
type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
|
|
417
|
+
declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
418
|
+
|
|
419
|
+
type Schema = z.ZodType<any, any, any>;
|
|
420
|
+
|
|
421
|
+
/** 自定义错误 */
|
|
422
|
+
declare class CustomError extends Error {
|
|
423
|
+
code?: number;
|
|
424
|
+
data?: any;
|
|
425
|
+
message: string;
|
|
426
|
+
tips?: string;
|
|
427
|
+
constructor(code?: number | string, message?: string, tips?: string);
|
|
428
|
+
static fromCode(code?: number): CustomError;
|
|
429
|
+
static fromErrorData(code?: number, data?: any): CustomError;
|
|
430
|
+
static parseError(e: CustomError): {
|
|
431
|
+
code: number;
|
|
432
|
+
data: any;
|
|
433
|
+
message: string;
|
|
434
|
+
tips: string;
|
|
435
|
+
};
|
|
436
|
+
/**
|
|
437
|
+
* 判断 throw 的错误是否不是当前这个错误
|
|
438
|
+
* @param err
|
|
439
|
+
* @returns
|
|
440
|
+
*/
|
|
441
|
+
static isError(error: unknown): error is CustomError;
|
|
442
|
+
parse(e?: CustomError): {
|
|
443
|
+
code: number;
|
|
444
|
+
data: any;
|
|
445
|
+
message: string;
|
|
446
|
+
tips: string;
|
|
447
|
+
};
|
|
392
448
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
449
|
+
|
|
450
|
+
type RouteObject = {
|
|
451
|
+
[key: string]: RouteOpts$1;
|
|
452
|
+
};
|
|
453
|
+
type SimpleObject = Record<string, any>;
|
|
454
|
+
declare function define<T extends Record<string, RouteOpts$1>>(value: T): {
|
|
455
|
+
[K in keyof T]: T[K] & RouteOpts$1;
|
|
456
|
+
};
|
|
457
|
+
type RouteArray = RouteOpts$1[];
|
|
458
|
+
type ChainOptions = {
|
|
459
|
+
app: QueryRouterServer$1;
|
|
460
|
+
};
|
|
461
|
+
declare class Chain {
|
|
462
|
+
object: RouteOpts$1;
|
|
463
|
+
app?: QueryRouterServer$1;
|
|
464
|
+
constructor(object: RouteOpts$1, opts?: ChainOptions);
|
|
465
|
+
get key(): string;
|
|
466
|
+
get path(): string;
|
|
467
|
+
setDescription(desc: string): this;
|
|
468
|
+
setMeta(metadata: {
|
|
469
|
+
[key: string]: any;
|
|
470
|
+
}): this;
|
|
471
|
+
setPath(path: string): this;
|
|
472
|
+
setMiddleware(middleware: RouteMiddleware$1[]): this;
|
|
473
|
+
setKey(key: string): this;
|
|
474
|
+
setId(key: string): this;
|
|
475
|
+
setRun<U extends SimpleObject = {}>(run: Run$1<U>): this;
|
|
476
|
+
define<U extends SimpleObject = {}>(run: Run$1<U>): this;
|
|
477
|
+
createRoute(): this;
|
|
478
|
+
}
|
|
479
|
+
type QueryChainOptions = {
|
|
480
|
+
query?: Query;
|
|
481
|
+
omitKeys?: string[];
|
|
482
|
+
};
|
|
483
|
+
declare class QueryChain {
|
|
484
|
+
obj: SimpleObject;
|
|
485
|
+
query: Query;
|
|
486
|
+
omitKeys: string[];
|
|
487
|
+
constructor(value?: SimpleObject, opts?: QueryChainOptions);
|
|
488
|
+
omit(obj: SimpleObject, key?: string[]): {
|
|
489
|
+
[x: string]: any;
|
|
490
|
+
};
|
|
491
|
+
/**
|
|
492
|
+
* 生成
|
|
493
|
+
* @param queryData
|
|
494
|
+
* @returns
|
|
495
|
+
*/
|
|
496
|
+
getKey(queryData?: SimpleObject): Pick<RouteOpts$1, 'path' | 'key' | 'metadata' | 'description'>;
|
|
497
|
+
post<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
498
|
+
get<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
499
|
+
}
|
|
500
|
+
declare const util: {
|
|
501
|
+
getChain: (obj: RouteOpts$1, opts?: ChainOptions) => Chain;
|
|
502
|
+
};
|
|
503
|
+
declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
504
|
+
obj: T;
|
|
505
|
+
app: QueryRouterServer$1;
|
|
506
|
+
query: Query;
|
|
507
|
+
constructor(object: T, opts?: ChainOptions & QueryChainOptions);
|
|
508
|
+
static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions): QueryUtil<U>;
|
|
509
|
+
static create<U extends Record<string, RouteOpts$1>>(value: U, opts?: ChainOptions): QueryUtil<U>;
|
|
510
|
+
get<K extends keyof T>(key: K): RouteOpts$1;
|
|
511
|
+
chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
|
|
512
|
+
queryChain<K extends keyof T>(key: K, opts?: QueryChainOptions): QueryChain;
|
|
513
|
+
static Chain: typeof Chain;
|
|
514
|
+
static QueryChain: typeof QueryChain;
|
|
515
|
+
get routeObject(): T;
|
|
402
516
|
}
|
|
403
517
|
|
|
404
518
|
type Cors$2 = {
|
|
@@ -731,140 +845,6 @@ declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promi
|
|
|
731
845
|
token: string;
|
|
732
846
|
}>;
|
|
733
847
|
|
|
734
|
-
/** 自定义错误 */
|
|
735
|
-
declare class CustomError extends Error {
|
|
736
|
-
code?: number;
|
|
737
|
-
data?: any;
|
|
738
|
-
message: string;
|
|
739
|
-
tips?: string;
|
|
740
|
-
constructor(code?: number | string, message?: string, tips?: string);
|
|
741
|
-
static fromCode(code?: number): CustomError;
|
|
742
|
-
static fromErrorData(code?: number, data?: any): CustomError;
|
|
743
|
-
static parseError(e: CustomError): {
|
|
744
|
-
code: number;
|
|
745
|
-
data: any;
|
|
746
|
-
message: string;
|
|
747
|
-
tips: string;
|
|
748
|
-
};
|
|
749
|
-
/**
|
|
750
|
-
* 判断 throw 的错误是否不是当前这个错误
|
|
751
|
-
* @param err
|
|
752
|
-
* @returns
|
|
753
|
-
*/
|
|
754
|
-
static isError(error: unknown): error is CustomError;
|
|
755
|
-
parse(e?: CustomError): {
|
|
756
|
-
code: number;
|
|
757
|
-
data: any;
|
|
758
|
-
message: string;
|
|
759
|
-
tips: string;
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
type BaseRule = {
|
|
764
|
-
value?: any;
|
|
765
|
-
required?: boolean;
|
|
766
|
-
message?: string;
|
|
767
|
-
};
|
|
768
|
-
type RuleString = {
|
|
769
|
-
type: 'string';
|
|
770
|
-
min?: number;
|
|
771
|
-
max?: number;
|
|
772
|
-
regex?: string;
|
|
773
|
-
} & BaseRule;
|
|
774
|
-
type RuleNumber = {
|
|
775
|
-
type: 'number';
|
|
776
|
-
min?: number;
|
|
777
|
-
max?: number;
|
|
778
|
-
} & BaseRule;
|
|
779
|
-
type RuleBoolean = {
|
|
780
|
-
type: 'boolean';
|
|
781
|
-
} & BaseRule;
|
|
782
|
-
type RuleArray = {
|
|
783
|
-
type: 'array';
|
|
784
|
-
items: Rule;
|
|
785
|
-
} & BaseRule;
|
|
786
|
-
type RuleObject = {
|
|
787
|
-
type: 'object';
|
|
788
|
-
properties: {
|
|
789
|
-
[key: string]: Rule;
|
|
790
|
-
};
|
|
791
|
-
} & BaseRule;
|
|
792
|
-
type RuleAny = {
|
|
793
|
-
type: 'any';
|
|
794
|
-
} & BaseRule;
|
|
795
|
-
type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
|
|
796
|
-
declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
797
|
-
|
|
798
|
-
type Schema = z.ZodType<any, any, any>;
|
|
799
|
-
|
|
800
|
-
type RouteObject = {
|
|
801
|
-
[key: string]: RouteOpts$1;
|
|
802
|
-
};
|
|
803
|
-
type SimpleObject = Record<string, any>;
|
|
804
|
-
declare function define<T extends Record<string, RouteOpts$1>>(value: T): {
|
|
805
|
-
[K in keyof T]: T[K] & RouteOpts$1;
|
|
806
|
-
};
|
|
807
|
-
type RouteArray = RouteOpts$1[];
|
|
808
|
-
type ChainOptions = {
|
|
809
|
-
app: QueryRouterServer$1;
|
|
810
|
-
};
|
|
811
|
-
declare class Chain {
|
|
812
|
-
object: RouteOpts$1;
|
|
813
|
-
app?: QueryRouterServer$1;
|
|
814
|
-
constructor(object: RouteOpts$1, opts?: ChainOptions);
|
|
815
|
-
get key(): string;
|
|
816
|
-
get path(): string;
|
|
817
|
-
setDescription(desc: string): this;
|
|
818
|
-
setMeta(metadata: {
|
|
819
|
-
[key: string]: any;
|
|
820
|
-
}): this;
|
|
821
|
-
setPath(path: string): this;
|
|
822
|
-
setMiddleware(middleware: RouteMiddleware$1[]): this;
|
|
823
|
-
setKey(key: string): this;
|
|
824
|
-
setId(key: string): this;
|
|
825
|
-
setRun<U extends SimpleObject = {}>(run: Run$1<U>): this;
|
|
826
|
-
define<U extends SimpleObject = {}>(run: Run$1<U>): this;
|
|
827
|
-
createRoute(): this;
|
|
828
|
-
}
|
|
829
|
-
type QueryChainOptions = {
|
|
830
|
-
query?: Query;
|
|
831
|
-
omitKeys?: string[];
|
|
832
|
-
};
|
|
833
|
-
declare class QueryChain {
|
|
834
|
-
obj: SimpleObject;
|
|
835
|
-
query: Query;
|
|
836
|
-
omitKeys: string[];
|
|
837
|
-
constructor(value?: SimpleObject, opts?: QueryChainOptions);
|
|
838
|
-
omit(obj: SimpleObject, key?: string[]): {
|
|
839
|
-
[x: string]: any;
|
|
840
|
-
};
|
|
841
|
-
/**
|
|
842
|
-
* 生成
|
|
843
|
-
* @param queryData
|
|
844
|
-
* @returns
|
|
845
|
-
*/
|
|
846
|
-
getKey(queryData?: SimpleObject): Pick<RouteOpts$1, 'path' | 'key' | 'metadata' | 'description'>;
|
|
847
|
-
post<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
848
|
-
get<R = SimpleObject, P = SimpleObject>(data: P, options?: DataOpts): Promise<Result<R>>;
|
|
849
|
-
}
|
|
850
|
-
declare const util: {
|
|
851
|
-
getChain: (obj: RouteOpts$1, opts?: ChainOptions) => Chain;
|
|
852
|
-
};
|
|
853
|
-
declare class QueryUtil<T extends RouteObject = RouteObject> {
|
|
854
|
-
obj: T;
|
|
855
|
-
app: QueryRouterServer$1;
|
|
856
|
-
query: Query;
|
|
857
|
-
constructor(object: T, opts?: ChainOptions & QueryChainOptions);
|
|
858
|
-
static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions): QueryUtil<U>;
|
|
859
|
-
static create<U extends Record<string, RouteOpts$1>>(value: U, opts?: ChainOptions): QueryUtil<U>;
|
|
860
|
-
get<K extends keyof T>(key: K): RouteOpts$1;
|
|
861
|
-
chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
|
|
862
|
-
queryChain<K extends keyof T>(key: K, opts?: QueryChainOptions): QueryChain;
|
|
863
|
-
static Chain: typeof Chain;
|
|
864
|
-
static QueryChain: typeof QueryChain;
|
|
865
|
-
get routeObject(): T;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
848
|
type RouterHandle = (msg: {
|
|
869
849
|
path: string;
|
|
870
850
|
[key: string]: any;
|
|
@@ -962,5 +942,5 @@ type GlobOptions = {
|
|
|
962
942
|
};
|
|
963
943
|
declare const loadTS: (match?: string, { cwd, load }?: GlobOptions) => Promise<any[]>;
|
|
964
944
|
|
|
965
|
-
export { App,
|
|
966
|
-
export type { HttpListenerFun, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
|
|
945
|
+
export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, handleServer, loadTS, util };
|
|
946
|
+
export type { HttpListenerFun, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
|