@kevisual/router 0.0.79 → 0.0.81
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 +122 -120
- package/dist/opencode.d.ts +6 -1
- package/dist/opencode.js +16 -13
- package/dist/router-browser.d.ts +18 -11
- package/dist/router-browser.js +103 -104
- package/dist/router-define.d.ts +6 -1
- package/dist/router.d.ts +18 -11
- package/dist/router.js +103 -104
- package/dist/ws.d.ts +6 -1
- package/package.json +6 -6
- package/src/result/error.ts +14 -15
- package/src/route.ts +5 -103
- package/src/validator/schema.ts +100 -0
package/dist/router-browser.js
CHANGED
|
@@ -208,18 +208,14 @@ class CustomError extends Error {
|
|
|
208
208
|
code;
|
|
209
209
|
data;
|
|
210
210
|
message;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.code = 500;
|
|
220
|
-
this.message = code;
|
|
221
|
-
}
|
|
222
|
-
this.tips = tips;
|
|
211
|
+
constructor(code, opts) {
|
|
212
|
+
let message = opts?.message || String(code);
|
|
213
|
+
const cause = opts?.cause;
|
|
214
|
+
super(message, { cause });
|
|
215
|
+
this.name = "RouterError";
|
|
216
|
+
let codeNum = opts?.code || (typeof code === "number" ? code : undefined);
|
|
217
|
+
this.code = codeNum ?? 500;
|
|
218
|
+
this.message = message;
|
|
223
219
|
Error.captureStackTrace(this, this.constructor);
|
|
224
220
|
}
|
|
225
221
|
static fromCode(code) {
|
|
@@ -234,8 +230,7 @@ class CustomError extends Error {
|
|
|
234
230
|
return {
|
|
235
231
|
code: e?.code,
|
|
236
232
|
data: e?.data,
|
|
237
|
-
message: e?.message
|
|
238
|
-
tips: e?.tips
|
|
233
|
+
message: e?.message
|
|
239
234
|
};
|
|
240
235
|
}
|
|
241
236
|
static isError(error) {
|
|
@@ -249,8 +244,7 @@ class CustomError extends Error {
|
|
|
249
244
|
return {
|
|
250
245
|
code: e2?.code,
|
|
251
246
|
data: e2?.data,
|
|
252
|
-
message: e2?.message
|
|
253
|
-
tips: e2?.tips
|
|
247
|
+
message: e2?.message
|
|
254
248
|
};
|
|
255
249
|
}
|
|
256
250
|
}
|
|
@@ -13960,6 +13954,92 @@ var randomId = (length = 8, affix = "") => {
|
|
|
13960
13954
|
return affix + nanoid3(length);
|
|
13961
13955
|
};
|
|
13962
13956
|
|
|
13957
|
+
// src/validator/schema.ts
|
|
13958
|
+
var extractArgs = (args) => {
|
|
13959
|
+
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
13960
|
+
return args.shape;
|
|
13961
|
+
}
|
|
13962
|
+
return args || {};
|
|
13963
|
+
};
|
|
13964
|
+
var toJSONSchema2 = (args, opts) => {
|
|
13965
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
13966
|
+
if (!args)
|
|
13967
|
+
return {};
|
|
13968
|
+
const _override = ({ jsonSchema, path, zodSchema }) => {
|
|
13969
|
+
if (Array.isArray(path) && path.length > 0) {
|
|
13970
|
+
return;
|
|
13971
|
+
}
|
|
13972
|
+
const isOptional = zodSchema.isOptional?.();
|
|
13973
|
+
if (isOptional) {
|
|
13974
|
+
jsonSchema.optional = true;
|
|
13975
|
+
}
|
|
13976
|
+
};
|
|
13977
|
+
const isError = (keys2) => {
|
|
13978
|
+
const errorKeys = ["toJSONSchema", "def", "type", "parse"];
|
|
13979
|
+
const hasErrorKeys = errorKeys.every((key) => keys2.includes(key));
|
|
13980
|
+
return hasErrorKeys;
|
|
13981
|
+
};
|
|
13982
|
+
const override = opts?.override || _override;
|
|
13983
|
+
if (mergeObject) {
|
|
13984
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
13985
|
+
return args.toJSONSchema();
|
|
13986
|
+
}
|
|
13987
|
+
if (isError(Object.keys(args))) {
|
|
13988
|
+
return {};
|
|
13989
|
+
}
|
|
13990
|
+
const schema = exports_external.object(args);
|
|
13991
|
+
return schema.toJSONSchema();
|
|
13992
|
+
}
|
|
13993
|
+
args = extractArgs(args);
|
|
13994
|
+
let keys = Object.keys(args);
|
|
13995
|
+
if (isError(keys)) {
|
|
13996
|
+
console.error(`[toJSONSchema error]: 解析到的 schema 可能不正确,包含了zod默认的value的schema. 请检查输入的 schema 是否正确。`);
|
|
13997
|
+
args = {};
|
|
13998
|
+
keys = [];
|
|
13999
|
+
}
|
|
14000
|
+
if (mergeObject) {}
|
|
14001
|
+
let newArgs = {};
|
|
14002
|
+
for (let key of keys) {
|
|
14003
|
+
const item = args[key];
|
|
14004
|
+
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
14005
|
+
newArgs[key] = item.toJSONSchema({ override });
|
|
14006
|
+
} else {
|
|
14007
|
+
newArgs[key] = args[key];
|
|
14008
|
+
}
|
|
14009
|
+
}
|
|
14010
|
+
return newArgs;
|
|
14011
|
+
};
|
|
14012
|
+
var fromJSONSchema2 = (args = {}, opts) => {
|
|
14013
|
+
let resultArgs = null;
|
|
14014
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
14015
|
+
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
14016
|
+
const objectSchema = exports_external.fromJSONSchema(args);
|
|
14017
|
+
const extract = extractArgs(objectSchema);
|
|
14018
|
+
const keys = Object.keys(extract);
|
|
14019
|
+
const newArgs = {};
|
|
14020
|
+
for (let key of keys) {
|
|
14021
|
+
newArgs[key] = extract[key];
|
|
14022
|
+
}
|
|
14023
|
+
resultArgs = newArgs;
|
|
14024
|
+
}
|
|
14025
|
+
if (!resultArgs) {
|
|
14026
|
+
const keys = Object.keys(args);
|
|
14027
|
+
const newArgs = {};
|
|
14028
|
+
for (let key of keys) {
|
|
14029
|
+
const item = args[key];
|
|
14030
|
+
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
14031
|
+
if (item.optional) {
|
|
14032
|
+
newArgs[key] = newArgs[key].optional();
|
|
14033
|
+
}
|
|
14034
|
+
}
|
|
14035
|
+
resultArgs = newArgs;
|
|
14036
|
+
}
|
|
14037
|
+
if (mergeObject) {
|
|
14038
|
+
resultArgs = exports_external.object(resultArgs);
|
|
14039
|
+
}
|
|
14040
|
+
return resultArgs;
|
|
14041
|
+
};
|
|
14042
|
+
|
|
13963
14043
|
// src/route.ts
|
|
13964
14044
|
var pickValue = ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
13965
14045
|
var tool = {
|
|
@@ -14083,82 +14163,15 @@ class Route {
|
|
|
14083
14163
|
throw new CustomError(...args);
|
|
14084
14164
|
}
|
|
14085
14165
|
}
|
|
14086
|
-
var extractArgs = (args) => {
|
|
14087
|
-
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
14088
|
-
return args.shape;
|
|
14089
|
-
}
|
|
14090
|
-
return args || {};
|
|
14091
|
-
};
|
|
14092
14166
|
var toJSONSchemaRoute = (route) => {
|
|
14093
14167
|
const pickValues = pick(route, pickValue);
|
|
14094
14168
|
if (pickValues?.metadata?.args) {
|
|
14095
|
-
|
|
14096
|
-
args = extractArgs(args);
|
|
14097
|
-
const keys = Object.keys(args);
|
|
14098
|
-
const newArgs = {};
|
|
14099
|
-
for (let key of keys) {
|
|
14100
|
-
const item = args[key];
|
|
14101
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
14102
|
-
newArgs[key] = item.toJSONSchema();
|
|
14103
|
-
} else {
|
|
14104
|
-
newArgs[key] = args[key];
|
|
14105
|
-
}
|
|
14106
|
-
}
|
|
14107
|
-
pickValues.metadata.args = newArgs;
|
|
14169
|
+
pickValues.metadata.args = toJSONSchema3(pickValues?.metadata?.args, { mergeObject: false });
|
|
14108
14170
|
}
|
|
14109
14171
|
return pickValues;
|
|
14110
14172
|
};
|
|
14111
|
-
var
|
|
14112
|
-
|
|
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
|
-
}
|
|
14122
|
-
args = extractArgs(args);
|
|
14123
|
-
const keys = Object.keys(args);
|
|
14124
|
-
let newArgs = {};
|
|
14125
|
-
for (let key of keys) {
|
|
14126
|
-
const item = args[key];
|
|
14127
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
14128
|
-
newArgs[key] = item.toJSONSchema();
|
|
14129
|
-
} else {
|
|
14130
|
-
newArgs[key] = args[key];
|
|
14131
|
-
}
|
|
14132
|
-
}
|
|
14133
|
-
return newArgs;
|
|
14134
|
-
};
|
|
14135
|
-
var fromJSONSchema2 = (args = {}, opts) => {
|
|
14136
|
-
let resultArgs = null;
|
|
14137
|
-
const mergeObject = opts?.mergeObject ?? true;
|
|
14138
|
-
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
14139
|
-
const objectSchema = exports_external.fromJSONSchema(args);
|
|
14140
|
-
const extract = extractArgs(objectSchema);
|
|
14141
|
-
const keys = Object.keys(extract);
|
|
14142
|
-
const newArgs = {};
|
|
14143
|
-
for (let key of keys) {
|
|
14144
|
-
newArgs[key] = extract[key];
|
|
14145
|
-
}
|
|
14146
|
-
resultArgs = newArgs;
|
|
14147
|
-
}
|
|
14148
|
-
if (!resultArgs) {
|
|
14149
|
-
const keys = Object.keys(args);
|
|
14150
|
-
const newArgs = {};
|
|
14151
|
-
for (let key of keys) {
|
|
14152
|
-
const item = args[key];
|
|
14153
|
-
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
14154
|
-
}
|
|
14155
|
-
resultArgs = newArgs;
|
|
14156
|
-
}
|
|
14157
|
-
if (mergeObject) {
|
|
14158
|
-
resultArgs = exports_external.object(resultArgs);
|
|
14159
|
-
}
|
|
14160
|
-
return resultArgs;
|
|
14161
|
-
};
|
|
14173
|
+
var toJSONSchema3 = toJSONSchema2;
|
|
14174
|
+
var fromJSONSchema3 = fromJSONSchema2;
|
|
14162
14175
|
|
|
14163
14176
|
class QueryRouter {
|
|
14164
14177
|
appId = "";
|
|
@@ -14412,20 +14425,6 @@ class QueryRouter {
|
|
|
14412
14425
|
getList(filter) {
|
|
14413
14426
|
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
14414
14427
|
const pickValues = pick(r, pickValue);
|
|
14415
|
-
if (pickValues?.metadata?.args) {
|
|
14416
|
-
const args = pickValues.metadata.args;
|
|
14417
|
-
const keys = Object.keys(args);
|
|
14418
|
-
const newArgs = {};
|
|
14419
|
-
for (let key of keys) {
|
|
14420
|
-
const item = args[key];
|
|
14421
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
14422
|
-
newArgs[key] = item.toJSONSchema();
|
|
14423
|
-
} else {
|
|
14424
|
-
newArgs[key] = args[key];
|
|
14425
|
-
}
|
|
14426
|
-
}
|
|
14427
|
-
pickValues.metadata.args = newArgs;
|
|
14428
|
-
}
|
|
14429
14428
|
return pickValues;
|
|
14430
14429
|
});
|
|
14431
14430
|
}
|
|
@@ -14513,8 +14512,8 @@ class QueryRouter {
|
|
|
14513
14512
|
}
|
|
14514
14513
|
return listenProcess({ app: this, params, ...opts });
|
|
14515
14514
|
}
|
|
14516
|
-
toJSONSchema =
|
|
14517
|
-
fromJSONSchema =
|
|
14515
|
+
toJSONSchema = toJSONSchema3;
|
|
14516
|
+
fromJSONSchema = fromJSONSchema3;
|
|
14518
14517
|
}
|
|
14519
14518
|
|
|
14520
14519
|
class QueryRouterServer extends QueryRouter {
|
|
@@ -14753,8 +14752,8 @@ var App = QueryRouterServer;
|
|
|
14753
14752
|
export {
|
|
14754
14753
|
util,
|
|
14755
14754
|
tool,
|
|
14756
|
-
|
|
14757
|
-
|
|
14755
|
+
toJSONSchema3 as toJSONSchema,
|
|
14756
|
+
fromJSONSchema3 as fromJSONSchema,
|
|
14758
14757
|
define,
|
|
14759
14758
|
createSkill,
|
|
14760
14759
|
createSchema,
|
package/dist/router-define.d.ts
CHANGED
|
@@ -347,10 +347,15 @@ declare class QueryRouter {
|
|
|
347
347
|
}): Promise<void>;
|
|
348
348
|
toJSONSchema: (args: any, opts?: {
|
|
349
349
|
mergeObject?: boolean;
|
|
350
|
+
override?: (opts: {
|
|
351
|
+
jsonSchema: any;
|
|
352
|
+
path: string[];
|
|
353
|
+
zodSchema: z.ZodTypeAny;
|
|
354
|
+
}) => void;
|
|
350
355
|
}) => {
|
|
351
356
|
[key: string]: any;
|
|
352
357
|
};
|
|
353
|
-
fromJSONSchema: <Merge extends boolean =
|
|
358
|
+
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
354
359
|
mergeObject?: boolean;
|
|
355
360
|
}) => Merge extends true ? z.ZodObject<{
|
|
356
361
|
[key: string]: any;
|
package/dist/router.d.ts
CHANGED
|
@@ -210,17 +210,17 @@ declare class Route<U = {
|
|
|
210
210
|
}, opts?: AddOpts): void;
|
|
211
211
|
throw(code?: number | string, message?: string, tips?: string): void;
|
|
212
212
|
}
|
|
213
|
-
/**
|
|
214
|
-
* 剥离第一层schema,转换为JSON Schema,无论是skill还是其他的infer比纯粹的zod object schema更合适,因为它可能包含其他的字段,而不仅仅是schema
|
|
215
|
-
* @param args
|
|
216
|
-
* @returns
|
|
217
|
-
*/
|
|
218
213
|
declare const toJSONSchema: (args: any, opts?: {
|
|
219
214
|
mergeObject?: boolean;
|
|
215
|
+
override?: (opts: {
|
|
216
|
+
jsonSchema: any;
|
|
217
|
+
path: string[];
|
|
218
|
+
zodSchema: z.ZodTypeAny;
|
|
219
|
+
}) => void;
|
|
220
220
|
}) => {
|
|
221
221
|
[key: string]: any;
|
|
222
222
|
};
|
|
223
|
-
declare const fromJSONSchema: <Merge extends boolean =
|
|
223
|
+
declare const fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
224
224
|
mergeObject?: boolean;
|
|
225
225
|
}) => Merge extends true ? z.ZodObject<{
|
|
226
226
|
[key: string]: any;
|
|
@@ -400,10 +400,15 @@ declare class QueryRouter {
|
|
|
400
400
|
}): Promise<void>;
|
|
401
401
|
toJSONSchema: (args: any, opts?: {
|
|
402
402
|
mergeObject?: boolean;
|
|
403
|
+
override?: (opts: {
|
|
404
|
+
jsonSchema: any;
|
|
405
|
+
path: string[];
|
|
406
|
+
zodSchema: z.ZodTypeAny;
|
|
407
|
+
}) => void;
|
|
403
408
|
}) => {
|
|
404
409
|
[key: string]: any;
|
|
405
410
|
};
|
|
406
|
-
fromJSONSchema: <Merge extends boolean =
|
|
411
|
+
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
407
412
|
mergeObject?: boolean;
|
|
408
413
|
}) => Merge extends true ? z.ZodObject<{
|
|
409
414
|
[key: string]: any;
|
|
@@ -499,20 +504,23 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
|
499
504
|
|
|
500
505
|
type Schema = z.ZodType<any, any, any>;
|
|
501
506
|
|
|
507
|
+
type CustomErrorOptions = {
|
|
508
|
+
cause?: Error | string;
|
|
509
|
+
code?: number;
|
|
510
|
+
message?: string;
|
|
511
|
+
};
|
|
502
512
|
/** 自定义错误 */
|
|
503
513
|
declare class CustomError extends Error {
|
|
504
514
|
code?: number;
|
|
505
515
|
data?: any;
|
|
506
516
|
message: string;
|
|
507
|
-
|
|
508
|
-
constructor(code?: number | string, message?: string, tips?: string);
|
|
517
|
+
constructor(code?: number | string, opts?: CustomErrorOptions);
|
|
509
518
|
static fromCode(code?: number): CustomError;
|
|
510
519
|
static fromErrorData(code?: number, data?: any): CustomError;
|
|
511
520
|
static parseError(e: CustomError): {
|
|
512
521
|
code: number;
|
|
513
522
|
data: any;
|
|
514
523
|
message: string;
|
|
515
|
-
tips: string;
|
|
516
524
|
};
|
|
517
525
|
/**
|
|
518
526
|
* 判断 throw 的错误是否不是当前这个错误
|
|
@@ -524,7 +532,6 @@ declare class CustomError extends Error {
|
|
|
524
532
|
code: number;
|
|
525
533
|
data: any;
|
|
526
534
|
message: string;
|
|
527
|
-
tips: string;
|
|
528
535
|
};
|
|
529
536
|
}
|
|
530
537
|
|
package/dist/router.js
CHANGED
|
@@ -3019,18 +3019,14 @@ class CustomError extends Error {
|
|
|
3019
3019
|
code;
|
|
3020
3020
|
data;
|
|
3021
3021
|
message;
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
this.code = 500;
|
|
3031
|
-
this.message = code;
|
|
3032
|
-
}
|
|
3033
|
-
this.tips = tips;
|
|
3022
|
+
constructor(code, opts) {
|
|
3023
|
+
let message = opts?.message || String(code);
|
|
3024
|
+
const cause = opts?.cause;
|
|
3025
|
+
super(message, { cause });
|
|
3026
|
+
this.name = "RouterError";
|
|
3027
|
+
let codeNum = opts?.code || (typeof code === "number" ? code : undefined);
|
|
3028
|
+
this.code = codeNum ?? 500;
|
|
3029
|
+
this.message = message;
|
|
3034
3030
|
Error.captureStackTrace(this, this.constructor);
|
|
3035
3031
|
}
|
|
3036
3032
|
static fromCode(code) {
|
|
@@ -3045,8 +3041,7 @@ class CustomError extends Error {
|
|
|
3045
3041
|
return {
|
|
3046
3042
|
code: e?.code,
|
|
3047
3043
|
data: e?.data,
|
|
3048
|
-
message: e?.message
|
|
3049
|
-
tips: e?.tips
|
|
3044
|
+
message: e?.message
|
|
3050
3045
|
};
|
|
3051
3046
|
}
|
|
3052
3047
|
static isError(error) {
|
|
@@ -3060,8 +3055,7 @@ class CustomError extends Error {
|
|
|
3060
3055
|
return {
|
|
3061
3056
|
code: e2?.code,
|
|
3062
3057
|
data: e2?.data,
|
|
3063
|
-
message: e2?.message
|
|
3064
|
-
tips: e2?.tips
|
|
3058
|
+
message: e2?.message
|
|
3065
3059
|
};
|
|
3066
3060
|
}
|
|
3067
3061
|
}
|
|
@@ -16793,6 +16787,92 @@ var randomId = (length = 8, affix = "") => {
|
|
|
16793
16787
|
return affix + nanoid3(length);
|
|
16794
16788
|
};
|
|
16795
16789
|
|
|
16790
|
+
// src/validator/schema.ts
|
|
16791
|
+
var extractArgs = (args) => {
|
|
16792
|
+
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
16793
|
+
return args.shape;
|
|
16794
|
+
}
|
|
16795
|
+
return args || {};
|
|
16796
|
+
};
|
|
16797
|
+
var toJSONSchema2 = (args, opts) => {
|
|
16798
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
16799
|
+
if (!args)
|
|
16800
|
+
return {};
|
|
16801
|
+
const _override = ({ jsonSchema, path, zodSchema }) => {
|
|
16802
|
+
if (Array.isArray(path) && path.length > 0) {
|
|
16803
|
+
return;
|
|
16804
|
+
}
|
|
16805
|
+
const isOptional = zodSchema.isOptional?.();
|
|
16806
|
+
if (isOptional) {
|
|
16807
|
+
jsonSchema.optional = true;
|
|
16808
|
+
}
|
|
16809
|
+
};
|
|
16810
|
+
const isError = (keys2) => {
|
|
16811
|
+
const errorKeys = ["toJSONSchema", "def", "type", "parse"];
|
|
16812
|
+
const hasErrorKeys = errorKeys.every((key) => keys2.includes(key));
|
|
16813
|
+
return hasErrorKeys;
|
|
16814
|
+
};
|
|
16815
|
+
const override = opts?.override || _override;
|
|
16816
|
+
if (mergeObject) {
|
|
16817
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
16818
|
+
return args.toJSONSchema();
|
|
16819
|
+
}
|
|
16820
|
+
if (isError(Object.keys(args))) {
|
|
16821
|
+
return {};
|
|
16822
|
+
}
|
|
16823
|
+
const schema = exports_external.object(args);
|
|
16824
|
+
return schema.toJSONSchema();
|
|
16825
|
+
}
|
|
16826
|
+
args = extractArgs(args);
|
|
16827
|
+
let keys = Object.keys(args);
|
|
16828
|
+
if (isError(keys)) {
|
|
16829
|
+
console.error(`[toJSONSchema error]: 解析到的 schema 可能不正确,包含了zod默认的value的schema. 请检查输入的 schema 是否正确。`);
|
|
16830
|
+
args = {};
|
|
16831
|
+
keys = [];
|
|
16832
|
+
}
|
|
16833
|
+
if (mergeObject) {}
|
|
16834
|
+
let newArgs = {};
|
|
16835
|
+
for (let key of keys) {
|
|
16836
|
+
const item = args[key];
|
|
16837
|
+
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16838
|
+
newArgs[key] = item.toJSONSchema({ override });
|
|
16839
|
+
} else {
|
|
16840
|
+
newArgs[key] = args[key];
|
|
16841
|
+
}
|
|
16842
|
+
}
|
|
16843
|
+
return newArgs;
|
|
16844
|
+
};
|
|
16845
|
+
var fromJSONSchema2 = (args = {}, opts) => {
|
|
16846
|
+
let resultArgs = null;
|
|
16847
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
16848
|
+
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
16849
|
+
const objectSchema = exports_external.fromJSONSchema(args);
|
|
16850
|
+
const extract = extractArgs(objectSchema);
|
|
16851
|
+
const keys = Object.keys(extract);
|
|
16852
|
+
const newArgs = {};
|
|
16853
|
+
for (let key of keys) {
|
|
16854
|
+
newArgs[key] = extract[key];
|
|
16855
|
+
}
|
|
16856
|
+
resultArgs = newArgs;
|
|
16857
|
+
}
|
|
16858
|
+
if (!resultArgs) {
|
|
16859
|
+
const keys = Object.keys(args);
|
|
16860
|
+
const newArgs = {};
|
|
16861
|
+
for (let key of keys) {
|
|
16862
|
+
const item = args[key];
|
|
16863
|
+
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
16864
|
+
if (item.optional) {
|
|
16865
|
+
newArgs[key] = newArgs[key].optional();
|
|
16866
|
+
}
|
|
16867
|
+
}
|
|
16868
|
+
resultArgs = newArgs;
|
|
16869
|
+
}
|
|
16870
|
+
if (mergeObject) {
|
|
16871
|
+
resultArgs = exports_external.object(resultArgs);
|
|
16872
|
+
}
|
|
16873
|
+
return resultArgs;
|
|
16874
|
+
};
|
|
16875
|
+
|
|
16796
16876
|
// src/route.ts
|
|
16797
16877
|
var pickValue = ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
16798
16878
|
var tool = {
|
|
@@ -16916,82 +16996,15 @@ class Route {
|
|
|
16916
16996
|
throw new CustomError(...args);
|
|
16917
16997
|
}
|
|
16918
16998
|
}
|
|
16919
|
-
var extractArgs = (args) => {
|
|
16920
|
-
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
16921
|
-
return args.shape;
|
|
16922
|
-
}
|
|
16923
|
-
return args || {};
|
|
16924
|
-
};
|
|
16925
16999
|
var toJSONSchemaRoute = (route) => {
|
|
16926
17000
|
const pickValues = pick(route, pickValue);
|
|
16927
17001
|
if (pickValues?.metadata?.args) {
|
|
16928
|
-
|
|
16929
|
-
args = extractArgs(args);
|
|
16930
|
-
const keys = Object.keys(args);
|
|
16931
|
-
const newArgs = {};
|
|
16932
|
-
for (let key of keys) {
|
|
16933
|
-
const item = args[key];
|
|
16934
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16935
|
-
newArgs[key] = item.toJSONSchema();
|
|
16936
|
-
} else {
|
|
16937
|
-
newArgs[key] = args[key];
|
|
16938
|
-
}
|
|
16939
|
-
}
|
|
16940
|
-
pickValues.metadata.args = newArgs;
|
|
17002
|
+
pickValues.metadata.args = toJSONSchema3(pickValues?.metadata?.args, { mergeObject: false });
|
|
16941
17003
|
}
|
|
16942
17004
|
return pickValues;
|
|
16943
17005
|
};
|
|
16944
|
-
var
|
|
16945
|
-
|
|
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
|
-
}
|
|
16955
|
-
args = extractArgs(args);
|
|
16956
|
-
const keys = Object.keys(args);
|
|
16957
|
-
let newArgs = {};
|
|
16958
|
-
for (let key of keys) {
|
|
16959
|
-
const item = args[key];
|
|
16960
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16961
|
-
newArgs[key] = item.toJSONSchema();
|
|
16962
|
-
} else {
|
|
16963
|
-
newArgs[key] = args[key];
|
|
16964
|
-
}
|
|
16965
|
-
}
|
|
16966
|
-
return newArgs;
|
|
16967
|
-
};
|
|
16968
|
-
var fromJSONSchema2 = (args = {}, opts) => {
|
|
16969
|
-
let resultArgs = null;
|
|
16970
|
-
const mergeObject = opts?.mergeObject ?? true;
|
|
16971
|
-
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
16972
|
-
const objectSchema = exports_external.fromJSONSchema(args);
|
|
16973
|
-
const extract = extractArgs(objectSchema);
|
|
16974
|
-
const keys = Object.keys(extract);
|
|
16975
|
-
const newArgs = {};
|
|
16976
|
-
for (let key of keys) {
|
|
16977
|
-
newArgs[key] = extract[key];
|
|
16978
|
-
}
|
|
16979
|
-
resultArgs = newArgs;
|
|
16980
|
-
}
|
|
16981
|
-
if (!resultArgs) {
|
|
16982
|
-
const keys = Object.keys(args);
|
|
16983
|
-
const newArgs = {};
|
|
16984
|
-
for (let key of keys) {
|
|
16985
|
-
const item = args[key];
|
|
16986
|
-
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
16987
|
-
}
|
|
16988
|
-
resultArgs = newArgs;
|
|
16989
|
-
}
|
|
16990
|
-
if (mergeObject) {
|
|
16991
|
-
resultArgs = exports_external.object(resultArgs);
|
|
16992
|
-
}
|
|
16993
|
-
return resultArgs;
|
|
16994
|
-
};
|
|
17006
|
+
var toJSONSchema3 = toJSONSchema2;
|
|
17007
|
+
var fromJSONSchema3 = fromJSONSchema2;
|
|
16995
17008
|
|
|
16996
17009
|
class QueryRouter {
|
|
16997
17010
|
appId = "";
|
|
@@ -17245,20 +17258,6 @@ class QueryRouter {
|
|
|
17245
17258
|
getList(filter) {
|
|
17246
17259
|
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
17247
17260
|
const pickValues = pick(r, pickValue);
|
|
17248
|
-
if (pickValues?.metadata?.args) {
|
|
17249
|
-
const args = pickValues.metadata.args;
|
|
17250
|
-
const keys = Object.keys(args);
|
|
17251
|
-
const newArgs = {};
|
|
17252
|
-
for (let key of keys) {
|
|
17253
|
-
const item = args[key];
|
|
17254
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
17255
|
-
newArgs[key] = item.toJSONSchema();
|
|
17256
|
-
} else {
|
|
17257
|
-
newArgs[key] = args[key];
|
|
17258
|
-
}
|
|
17259
|
-
}
|
|
17260
|
-
pickValues.metadata.args = newArgs;
|
|
17261
|
-
}
|
|
17262
17261
|
return pickValues;
|
|
17263
17262
|
});
|
|
17264
17263
|
}
|
|
@@ -17346,8 +17345,8 @@ class QueryRouter {
|
|
|
17346
17345
|
}
|
|
17347
17346
|
return listenProcess({ app: this, params, ...opts });
|
|
17348
17347
|
}
|
|
17349
|
-
toJSONSchema =
|
|
17350
|
-
fromJSONSchema =
|
|
17348
|
+
toJSONSchema = toJSONSchema3;
|
|
17349
|
+
fromJSONSchema = fromJSONSchema3;
|
|
17351
17350
|
}
|
|
17352
17351
|
|
|
17353
17352
|
class QueryRouterServer extends QueryRouter {
|
|
@@ -18545,9 +18544,9 @@ class App extends QueryRouter {
|
|
|
18545
18544
|
export {
|
|
18546
18545
|
util,
|
|
18547
18546
|
tool,
|
|
18548
|
-
|
|
18547
|
+
toJSONSchema3 as toJSONSchema,
|
|
18549
18548
|
handleServer,
|
|
18550
|
-
|
|
18549
|
+
fromJSONSchema3 as fromJSONSchema,
|
|
18551
18550
|
define,
|
|
18552
18551
|
createSkill,
|
|
18553
18552
|
createSchema,
|
package/dist/ws.d.ts
CHANGED
|
@@ -397,10 +397,15 @@ declare class QueryRouter {
|
|
|
397
397
|
}): Promise<void>;
|
|
398
398
|
toJSONSchema: (args: any, opts?: {
|
|
399
399
|
mergeObject?: boolean;
|
|
400
|
+
override?: (opts: {
|
|
401
|
+
jsonSchema: any;
|
|
402
|
+
path: string[];
|
|
403
|
+
zodSchema: z.ZodTypeAny;
|
|
404
|
+
}) => void;
|
|
400
405
|
}) => {
|
|
401
406
|
[key: string]: any;
|
|
402
407
|
};
|
|
403
|
-
fromJSONSchema: <Merge extends boolean =
|
|
408
|
+
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
404
409
|
mergeObject?: boolean;
|
|
405
410
|
}) => Merge extends true ? z.ZodObject<{
|
|
406
411
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@kevisual/router",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.81",
|
|
5
5
|
"description": "",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/router.js",
|
|
@@ -23,21 +23,21 @@
|
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@kevisual/code-builder": "^0.0.6",
|
|
26
|
-
"@kevisual/context": "^0.0.
|
|
26
|
+
"@kevisual/context": "^0.0.8",
|
|
27
27
|
"@kevisual/dts": "^0.0.4",
|
|
28
28
|
"@kevisual/js-filter": "^0.0.5",
|
|
29
29
|
"@kevisual/local-proxy": "^0.0.8",
|
|
30
|
-
"@kevisual/query": "^0.0.
|
|
30
|
+
"@kevisual/query": "^0.0.49",
|
|
31
31
|
"@kevisual/use-config": "^1.0.30",
|
|
32
|
-
"@opencode-ai/plugin": "^1.2.
|
|
32
|
+
"@opencode-ai/plugin": "^1.2.10",
|
|
33
33
|
"@types/bun": "^1.3.9",
|
|
34
|
-
"@types/node": "^25.
|
|
34
|
+
"@types/node": "^25.3.0",
|
|
35
35
|
"@types/send": "^1.2.1",
|
|
36
36
|
"@types/ws": "^8.18.1",
|
|
37
37
|
"@types/xml2js": "^0.4.14",
|
|
38
38
|
"eventemitter3": "^5.0.4",
|
|
39
39
|
"fast-glob": "^3.3.3",
|
|
40
|
-
"hono": "^4.
|
|
40
|
+
"hono": "^4.12.0",
|
|
41
41
|
"nanoid": "^5.1.6",
|
|
42
42
|
"path-to-regexp": "^8.3.0",
|
|
43
43
|
"send": "^1.2.1",
|