@kevisual/router 0.0.77 → 0.0.79
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/app.js +14 -4
- package/dist/opencode.d.ts +3 -1
- package/dist/router-browser.d.ts +6 -2
- package/dist/router-browser.js +13 -3
- package/dist/router-define.d.ts +3 -1
- package/dist/router.d.ts +6 -2
- package/dist/router.js +13 -3
- package/dist/ws.d.ts +3 -1
- package/package.json +1 -1
- package/src/route.ts +15 -4
package/dist/app.js
CHANGED
|
@@ -16944,10 +16944,20 @@ var toJSONSchemaRoute = (route) => {
|
|
|
16944
16944
|
}
|
|
16945
16945
|
return pickValues;
|
|
16946
16946
|
};
|
|
16947
|
-
var toJSONSchema2 = (args) => {
|
|
16947
|
+
var toJSONSchema2 = (args, opts) => {
|
|
16948
|
+
const mergeObject = opts?.mergeObject ?? true;
|
|
16949
|
+
if (!args)
|
|
16950
|
+
return {};
|
|
16951
|
+
if (mergeObject) {
|
|
16952
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
16953
|
+
return args.toJSONSchema();
|
|
16954
|
+
}
|
|
16955
|
+
const schema = exports_external.object(args);
|
|
16956
|
+
return schema.toJSONSchema();
|
|
16957
|
+
}
|
|
16948
16958
|
args = extractArgs(args);
|
|
16949
16959
|
const keys = Object.keys(args);
|
|
16950
|
-
|
|
16960
|
+
let newArgs = {};
|
|
16951
16961
|
for (let key of keys) {
|
|
16952
16962
|
const item = args[key];
|
|
16953
16963
|
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
@@ -16976,7 +16986,7 @@ var fromJSONSchema2 = (args = {}, opts) => {
|
|
|
16976
16986
|
const newArgs = {};
|
|
16977
16987
|
for (let key of keys) {
|
|
16978
16988
|
const item = args[key];
|
|
16979
|
-
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
16989
|
+
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
16980
16990
|
}
|
|
16981
16991
|
resultArgs = newArgs;
|
|
16982
16992
|
}
|
|
@@ -19507,7 +19517,7 @@ app
|
|
|
19507
19517
|
10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
|
|
19508
19518
|
`;
|
|
19509
19519
|
// package.json
|
|
19510
|
-
var version2 = "0.0.
|
|
19520
|
+
var version2 = "0.0.78";
|
|
19511
19521
|
|
|
19512
19522
|
// agent/routes/route-create.ts
|
|
19513
19523
|
app.route({
|
package/dist/opencode.d.ts
CHANGED
|
@@ -348,7 +348,9 @@ declare class QueryRouter {
|
|
|
348
348
|
filter?: (route: Route) => boolean;
|
|
349
349
|
routeListMiddleware?: string[];
|
|
350
350
|
}): Promise<void>;
|
|
351
|
-
toJSONSchema: (args: any
|
|
351
|
+
toJSONSchema: (args: any, opts?: {
|
|
352
|
+
mergeObject?: boolean;
|
|
353
|
+
}) => {
|
|
352
354
|
[key: string]: any;
|
|
353
355
|
};
|
|
354
356
|
fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -209,7 +209,9 @@ declare class Route<U = {
|
|
|
209
209
|
* @param args
|
|
210
210
|
* @returns
|
|
211
211
|
*/
|
|
212
|
-
declare const toJSONSchema: (args: any
|
|
212
|
+
declare const toJSONSchema: (args: any, opts?: {
|
|
213
|
+
mergeObject?: boolean;
|
|
214
|
+
}) => {
|
|
213
215
|
[key: string]: any;
|
|
214
216
|
};
|
|
215
217
|
declare const fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
|
@@ -390,7 +392,9 @@ declare class QueryRouter {
|
|
|
390
392
|
filter?: (route: Route) => boolean;
|
|
391
393
|
routeListMiddleware?: string[];
|
|
392
394
|
}): Promise<void>;
|
|
393
|
-
toJSONSchema: (args: any
|
|
395
|
+
toJSONSchema: (args: any, opts?: {
|
|
396
|
+
mergeObject?: boolean;
|
|
397
|
+
}) => {
|
|
394
398
|
[key: string]: any;
|
|
395
399
|
};
|
|
396
400
|
fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
package/dist/router-browser.js
CHANGED
|
@@ -14108,10 +14108,20 @@ var toJSONSchemaRoute = (route) => {
|
|
|
14108
14108
|
}
|
|
14109
14109
|
return pickValues;
|
|
14110
14110
|
};
|
|
14111
|
-
var toJSONSchema2 = (args) => {
|
|
14111
|
+
var toJSONSchema2 = (args, opts) => {
|
|
14112
|
+
const mergeObject = opts?.mergeObject ?? true;
|
|
14113
|
+
if (!args)
|
|
14114
|
+
return {};
|
|
14115
|
+
if (mergeObject) {
|
|
14116
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
14117
|
+
return args.toJSONSchema();
|
|
14118
|
+
}
|
|
14119
|
+
const schema = exports_external.object(args);
|
|
14120
|
+
return schema.toJSONSchema();
|
|
14121
|
+
}
|
|
14112
14122
|
args = extractArgs(args);
|
|
14113
14123
|
const keys = Object.keys(args);
|
|
14114
|
-
|
|
14124
|
+
let newArgs = {};
|
|
14115
14125
|
for (let key of keys) {
|
|
14116
14126
|
const item = args[key];
|
|
14117
14127
|
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
@@ -14140,7 +14150,7 @@ var fromJSONSchema2 = (args = {}, opts) => {
|
|
|
14140
14150
|
const newArgs = {};
|
|
14141
14151
|
for (let key of keys) {
|
|
14142
14152
|
const item = args[key];
|
|
14143
|
-
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
14153
|
+
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
14144
14154
|
}
|
|
14145
14155
|
resultArgs = newArgs;
|
|
14146
14156
|
}
|
package/dist/router-define.d.ts
CHANGED
|
@@ -345,7 +345,9 @@ declare class QueryRouter {
|
|
|
345
345
|
filter?: (route: Route) => boolean;
|
|
346
346
|
routeListMiddleware?: string[];
|
|
347
347
|
}): Promise<void>;
|
|
348
|
-
toJSONSchema: (args: any
|
|
348
|
+
toJSONSchema: (args: any, opts?: {
|
|
349
|
+
mergeObject?: boolean;
|
|
350
|
+
}) => {
|
|
349
351
|
[key: string]: any;
|
|
350
352
|
};
|
|
351
353
|
fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
package/dist/router.d.ts
CHANGED
|
@@ -215,7 +215,9 @@ declare class Route<U = {
|
|
|
215
215
|
* @param args
|
|
216
216
|
* @returns
|
|
217
217
|
*/
|
|
218
|
-
declare const toJSONSchema: (args: any
|
|
218
|
+
declare const toJSONSchema: (args: any, opts?: {
|
|
219
|
+
mergeObject?: boolean;
|
|
220
|
+
}) => {
|
|
219
221
|
[key: string]: any;
|
|
220
222
|
};
|
|
221
223
|
declare const fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
|
@@ -396,7 +398,9 @@ declare class QueryRouter {
|
|
|
396
398
|
filter?: (route: Route) => boolean;
|
|
397
399
|
routeListMiddleware?: string[];
|
|
398
400
|
}): Promise<void>;
|
|
399
|
-
toJSONSchema: (args: any
|
|
401
|
+
toJSONSchema: (args: any, opts?: {
|
|
402
|
+
mergeObject?: boolean;
|
|
403
|
+
}) => {
|
|
400
404
|
[key: string]: any;
|
|
401
405
|
};
|
|
402
406
|
fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
package/dist/router.js
CHANGED
|
@@ -16941,10 +16941,20 @@ var toJSONSchemaRoute = (route) => {
|
|
|
16941
16941
|
}
|
|
16942
16942
|
return pickValues;
|
|
16943
16943
|
};
|
|
16944
|
-
var toJSONSchema2 = (args) => {
|
|
16944
|
+
var toJSONSchema2 = (args, opts) => {
|
|
16945
|
+
const mergeObject = opts?.mergeObject ?? true;
|
|
16946
|
+
if (!args)
|
|
16947
|
+
return {};
|
|
16948
|
+
if (mergeObject) {
|
|
16949
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
16950
|
+
return args.toJSONSchema();
|
|
16951
|
+
}
|
|
16952
|
+
const schema = exports_external.object(args);
|
|
16953
|
+
return schema.toJSONSchema();
|
|
16954
|
+
}
|
|
16945
16955
|
args = extractArgs(args);
|
|
16946
16956
|
const keys = Object.keys(args);
|
|
16947
|
-
|
|
16957
|
+
let newArgs = {};
|
|
16948
16958
|
for (let key of keys) {
|
|
16949
16959
|
const item = args[key];
|
|
16950
16960
|
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
@@ -16973,7 +16983,7 @@ var fromJSONSchema2 = (args = {}, opts) => {
|
|
|
16973
16983
|
const newArgs = {};
|
|
16974
16984
|
for (let key of keys) {
|
|
16975
16985
|
const item = args[key];
|
|
16976
|
-
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
16986
|
+
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
16977
16987
|
}
|
|
16978
16988
|
resultArgs = newArgs;
|
|
16979
16989
|
}
|
package/dist/ws.d.ts
CHANGED
|
@@ -395,7 +395,9 @@ declare class QueryRouter {
|
|
|
395
395
|
filter?: (route: Route) => boolean;
|
|
396
396
|
routeListMiddleware?: string[];
|
|
397
397
|
}): Promise<void>;
|
|
398
|
-
toJSONSchema: (args: any
|
|
398
|
+
toJSONSchema: (args: any, opts?: {
|
|
399
|
+
mergeObject?: boolean;
|
|
400
|
+
}) => {
|
|
399
401
|
[key: string]: any;
|
|
400
402
|
};
|
|
401
403
|
fromJSONSchema: <Merge extends boolean = true>(args?: any, opts?: {
|
package/package.json
CHANGED
package/src/route.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { pick } from './utils/pick.ts';
|
|
|
3
3
|
import { listenProcess, MockProcess } from './utils/listen-process.ts';
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import { randomId } from './utils/random.ts';
|
|
6
|
+
import { ar } from 'zod/v4/locales';
|
|
6
7
|
export type RouterContextT = { code?: number;[key: string]: any };
|
|
7
8
|
export type RouteContext<T = { code?: number }, S = any> = {
|
|
8
9
|
/**
|
|
@@ -245,7 +246,7 @@ export class Route<U = { [key: string]: any }, T extends SimpleObject = SimpleOb
|
|
|
245
246
|
throw new CustomError(...args);
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
|
-
|
|
249
|
+
const extractArgs = (args: any) => {
|
|
249
250
|
if (args && typeof args === 'object' && typeof args.shape === 'object') {
|
|
250
251
|
return args.shape as z.ZodRawShape;
|
|
251
252
|
}
|
|
@@ -286,11 +287,20 @@ const fromJSONSchemaRoute = (route: RouteInfo): RouteInfo => {
|
|
|
286
287
|
* @param args
|
|
287
288
|
* @returns
|
|
288
289
|
*/
|
|
289
|
-
export const toJSONSchema = (args: any): { [key: string]: any } => {
|
|
290
|
+
export const toJSONSchema = (args: any, opts?: { mergeObject?: boolean }): { [key: string]: any } => {
|
|
291
|
+
const mergeObject = opts?.mergeObject ?? true;
|
|
292
|
+
if (!args) return {};
|
|
293
|
+
if (mergeObject) {
|
|
294
|
+
if (typeof args === 'object' && typeof args.toJSONSchema === 'function') {
|
|
295
|
+
return args.toJSONSchema();
|
|
296
|
+
}
|
|
297
|
+
const schema = z.object(args);
|
|
298
|
+
return schema.toJSONSchema();
|
|
299
|
+
}
|
|
290
300
|
// 如果 args 本身是一个 zod object schema,先提取 shape
|
|
291
301
|
args = extractArgs(args);
|
|
292
302
|
const keys = Object.keys(args);
|
|
293
|
-
|
|
303
|
+
let newArgs: { [key: string]: any } = {};
|
|
294
304
|
for (let key of keys) {
|
|
295
305
|
const item = args[key] as z.ZodAny;
|
|
296
306
|
if (item && typeof item === 'object' && typeof item.toJSONSchema === 'function') {
|
|
@@ -320,7 +330,8 @@ export const fromJSONSchema = <Merge extends boolean = true>(args: any = {}, opt
|
|
|
320
330
|
const newArgs: { [key: string]: any } = {};
|
|
321
331
|
for (let key of keys) {
|
|
322
332
|
const item = args[key];
|
|
323
|
-
|
|
333
|
+
// fromJSONSchema 可能会失败,所以先 optional,等使用的时候再验证
|
|
334
|
+
newArgs[key] = z.fromJSONSchema(item).optional();
|
|
324
335
|
}
|
|
325
336
|
resultArgs = newArgs;
|
|
326
337
|
}
|