@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/app.js
CHANGED
|
@@ -2316,9 +2316,9 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
2316
2316
|
emitErrorAndClose(websocket, err);
|
|
2317
2317
|
});
|
|
2318
2318
|
req.on("response", (res) => {
|
|
2319
|
-
const
|
|
2319
|
+
const location2 = res.headers.location;
|
|
2320
2320
|
const statusCode = res.statusCode;
|
|
2321
|
-
if (
|
|
2321
|
+
if (location2 && opts.followRedirects && statusCode >= 300 && statusCode < 400) {
|
|
2322
2322
|
if (++websocket._redirects > opts.maxRedirects) {
|
|
2323
2323
|
abortHandshake(websocket, req, "Maximum redirects exceeded");
|
|
2324
2324
|
return;
|
|
@@ -2326,9 +2326,9 @@ var require_websocket = __commonJS((exports, module) => {
|
|
|
2326
2326
|
req.abort();
|
|
2327
2327
|
let addr;
|
|
2328
2328
|
try {
|
|
2329
|
-
addr = new URL2(
|
|
2329
|
+
addr = new URL2(location2, address);
|
|
2330
2330
|
} catch (e) {
|
|
2331
|
-
const err = new SyntaxError(`Invalid URL: ${
|
|
2331
|
+
const err = new SyntaxError(`Invalid URL: ${location2}`);
|
|
2332
2332
|
emitErrorAndClose(websocket, err);
|
|
2333
2333
|
return;
|
|
2334
2334
|
}
|
|
@@ -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
|
}
|
|
@@ -16796,6 +16790,92 @@ var randomId = (length = 8, affix = "") => {
|
|
|
16796
16790
|
return affix + nanoid3(length);
|
|
16797
16791
|
};
|
|
16798
16792
|
|
|
16793
|
+
// src/validator/schema.ts
|
|
16794
|
+
var extractArgs = (args) => {
|
|
16795
|
+
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
16796
|
+
return args.shape;
|
|
16797
|
+
}
|
|
16798
|
+
return args || {};
|
|
16799
|
+
};
|
|
16800
|
+
var toJSONSchema2 = (args, opts) => {
|
|
16801
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
16802
|
+
if (!args)
|
|
16803
|
+
return {};
|
|
16804
|
+
const _override = ({ jsonSchema, path, zodSchema }) => {
|
|
16805
|
+
if (Array.isArray(path) && path.length > 0) {
|
|
16806
|
+
return;
|
|
16807
|
+
}
|
|
16808
|
+
const isOptional = zodSchema.isOptional?.();
|
|
16809
|
+
if (isOptional) {
|
|
16810
|
+
jsonSchema.optional = true;
|
|
16811
|
+
}
|
|
16812
|
+
};
|
|
16813
|
+
const isError = (keys2) => {
|
|
16814
|
+
const errorKeys = ["toJSONSchema", "def", "type", "parse"];
|
|
16815
|
+
const hasErrorKeys = errorKeys.every((key) => keys2.includes(key));
|
|
16816
|
+
return hasErrorKeys;
|
|
16817
|
+
};
|
|
16818
|
+
const override = opts?.override || _override;
|
|
16819
|
+
if (mergeObject) {
|
|
16820
|
+
if (typeof args === "object" && typeof args.toJSONSchema === "function") {
|
|
16821
|
+
return args.toJSONSchema();
|
|
16822
|
+
}
|
|
16823
|
+
if (isError(Object.keys(args))) {
|
|
16824
|
+
return {};
|
|
16825
|
+
}
|
|
16826
|
+
const schema = exports_external.object(args);
|
|
16827
|
+
return schema.toJSONSchema();
|
|
16828
|
+
}
|
|
16829
|
+
args = extractArgs(args);
|
|
16830
|
+
let keys = Object.keys(args);
|
|
16831
|
+
if (isError(keys)) {
|
|
16832
|
+
console.error(`[toJSONSchema error]: 解析到的 schema 可能不正确,包含了zod默认的value的schema. 请检查输入的 schema 是否正确。`);
|
|
16833
|
+
args = {};
|
|
16834
|
+
keys = [];
|
|
16835
|
+
}
|
|
16836
|
+
if (mergeObject) {}
|
|
16837
|
+
let newArgs = {};
|
|
16838
|
+
for (let key of keys) {
|
|
16839
|
+
const item = args[key];
|
|
16840
|
+
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16841
|
+
newArgs[key] = item.toJSONSchema({ override });
|
|
16842
|
+
} else {
|
|
16843
|
+
newArgs[key] = args[key];
|
|
16844
|
+
}
|
|
16845
|
+
}
|
|
16846
|
+
return newArgs;
|
|
16847
|
+
};
|
|
16848
|
+
var fromJSONSchema2 = (args = {}, opts) => {
|
|
16849
|
+
let resultArgs = null;
|
|
16850
|
+
const mergeObject = opts?.mergeObject ?? false;
|
|
16851
|
+
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
16852
|
+
const objectSchema = exports_external.fromJSONSchema(args);
|
|
16853
|
+
const extract = extractArgs(objectSchema);
|
|
16854
|
+
const keys = Object.keys(extract);
|
|
16855
|
+
const newArgs = {};
|
|
16856
|
+
for (let key of keys) {
|
|
16857
|
+
newArgs[key] = extract[key];
|
|
16858
|
+
}
|
|
16859
|
+
resultArgs = newArgs;
|
|
16860
|
+
}
|
|
16861
|
+
if (!resultArgs) {
|
|
16862
|
+
const keys = Object.keys(args);
|
|
16863
|
+
const newArgs = {};
|
|
16864
|
+
for (let key of keys) {
|
|
16865
|
+
const item = args[key];
|
|
16866
|
+
newArgs[key] = exports_external.fromJSONSchema(item);
|
|
16867
|
+
if (item.optional) {
|
|
16868
|
+
newArgs[key] = newArgs[key].optional();
|
|
16869
|
+
}
|
|
16870
|
+
}
|
|
16871
|
+
resultArgs = newArgs;
|
|
16872
|
+
}
|
|
16873
|
+
if (mergeObject) {
|
|
16874
|
+
resultArgs = exports_external.object(resultArgs);
|
|
16875
|
+
}
|
|
16876
|
+
return resultArgs;
|
|
16877
|
+
};
|
|
16878
|
+
|
|
16799
16879
|
// src/route.ts
|
|
16800
16880
|
var pickValue = ["path", "key", "id", "description", "type", "middleware", "metadata"];
|
|
16801
16881
|
var tool = {
|
|
@@ -16919,82 +16999,15 @@ class Route {
|
|
|
16919
16999
|
throw new CustomError(...args);
|
|
16920
17000
|
}
|
|
16921
17001
|
}
|
|
16922
|
-
var extractArgs = (args) => {
|
|
16923
|
-
if (args && typeof args === "object" && typeof args.shape === "object") {
|
|
16924
|
-
return args.shape;
|
|
16925
|
-
}
|
|
16926
|
-
return args || {};
|
|
16927
|
-
};
|
|
16928
17002
|
var toJSONSchemaRoute = (route) => {
|
|
16929
17003
|
const pickValues = pick(route, pickValue);
|
|
16930
17004
|
if (pickValues?.metadata?.args) {
|
|
16931
|
-
|
|
16932
|
-
args = extractArgs(args);
|
|
16933
|
-
const keys = Object.keys(args);
|
|
16934
|
-
const newArgs = {};
|
|
16935
|
-
for (let key of keys) {
|
|
16936
|
-
const item = args[key];
|
|
16937
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16938
|
-
newArgs[key] = item.toJSONSchema();
|
|
16939
|
-
} else {
|
|
16940
|
-
newArgs[key] = args[key];
|
|
16941
|
-
}
|
|
16942
|
-
}
|
|
16943
|
-
pickValues.metadata.args = newArgs;
|
|
17005
|
+
pickValues.metadata.args = toJSONSchema3(pickValues?.metadata?.args, { mergeObject: false });
|
|
16944
17006
|
}
|
|
16945
17007
|
return pickValues;
|
|
16946
17008
|
};
|
|
16947
|
-
var
|
|
16948
|
-
|
|
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
|
-
}
|
|
16958
|
-
args = extractArgs(args);
|
|
16959
|
-
const keys = Object.keys(args);
|
|
16960
|
-
let newArgs = {};
|
|
16961
|
-
for (let key of keys) {
|
|
16962
|
-
const item = args[key];
|
|
16963
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
16964
|
-
newArgs[key] = item.toJSONSchema();
|
|
16965
|
-
} else {
|
|
16966
|
-
newArgs[key] = args[key];
|
|
16967
|
-
}
|
|
16968
|
-
}
|
|
16969
|
-
return newArgs;
|
|
16970
|
-
};
|
|
16971
|
-
var fromJSONSchema2 = (args = {}, opts) => {
|
|
16972
|
-
let resultArgs = null;
|
|
16973
|
-
const mergeObject = opts?.mergeObject ?? true;
|
|
16974
|
-
if (args["$schema"] || args.type === "object" && args.properties && typeof args.properties === "object") {
|
|
16975
|
-
const objectSchema = exports_external.fromJSONSchema(args);
|
|
16976
|
-
const extract = extractArgs(objectSchema);
|
|
16977
|
-
const keys = Object.keys(extract);
|
|
16978
|
-
const newArgs = {};
|
|
16979
|
-
for (let key of keys) {
|
|
16980
|
-
newArgs[key] = extract[key];
|
|
16981
|
-
}
|
|
16982
|
-
resultArgs = newArgs;
|
|
16983
|
-
}
|
|
16984
|
-
if (!resultArgs) {
|
|
16985
|
-
const keys = Object.keys(args);
|
|
16986
|
-
const newArgs = {};
|
|
16987
|
-
for (let key of keys) {
|
|
16988
|
-
const item = args[key];
|
|
16989
|
-
newArgs[key] = exports_external.fromJSONSchema(item).optional();
|
|
16990
|
-
}
|
|
16991
|
-
resultArgs = newArgs;
|
|
16992
|
-
}
|
|
16993
|
-
if (mergeObject) {
|
|
16994
|
-
resultArgs = exports_external.object(resultArgs);
|
|
16995
|
-
}
|
|
16996
|
-
return resultArgs;
|
|
16997
|
-
};
|
|
17009
|
+
var toJSONSchema3 = toJSONSchema2;
|
|
17010
|
+
var fromJSONSchema3 = fromJSONSchema2;
|
|
16998
17011
|
|
|
16999
17012
|
class QueryRouter {
|
|
17000
17013
|
appId = "";
|
|
@@ -17248,20 +17261,6 @@ class QueryRouter {
|
|
|
17248
17261
|
getList(filter) {
|
|
17249
17262
|
return this.routes.filter(filter || (() => true)).map((r) => {
|
|
17250
17263
|
const pickValues = pick(r, pickValue);
|
|
17251
|
-
if (pickValues?.metadata?.args) {
|
|
17252
|
-
const args = pickValues.metadata.args;
|
|
17253
|
-
const keys = Object.keys(args);
|
|
17254
|
-
const newArgs = {};
|
|
17255
|
-
for (let key of keys) {
|
|
17256
|
-
const item = args[key];
|
|
17257
|
-
if (item && typeof item === "object" && typeof item.toJSONSchema === "function") {
|
|
17258
|
-
newArgs[key] = item.toJSONSchema();
|
|
17259
|
-
} else {
|
|
17260
|
-
newArgs[key] = args[key];
|
|
17261
|
-
}
|
|
17262
|
-
}
|
|
17263
|
-
pickValues.metadata.args = newArgs;
|
|
17264
|
-
}
|
|
17265
17264
|
return pickValues;
|
|
17266
17265
|
});
|
|
17267
17266
|
}
|
|
@@ -17349,8 +17348,8 @@ class QueryRouter {
|
|
|
17349
17348
|
}
|
|
17350
17349
|
return listenProcess({ app: this, params, ...opts });
|
|
17351
17350
|
}
|
|
17352
|
-
toJSONSchema =
|
|
17353
|
-
fromJSONSchema =
|
|
17351
|
+
toJSONSchema = toJSONSchema3;
|
|
17352
|
+
fromJSONSchema = fromJSONSchema3;
|
|
17354
17353
|
}
|
|
17355
17354
|
|
|
17356
17355
|
// src/server/server.ts
|
|
@@ -18316,7 +18315,8 @@ class App extends QueryRouter {
|
|
|
18316
18315
|
}
|
|
18317
18316
|
}
|
|
18318
18317
|
|
|
18319
|
-
// node_modules/.pnpm/@kevisual+context@0.0.
|
|
18318
|
+
// node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
|
|
18319
|
+
var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
18320
18320
|
function getDefaultExportFromCjs(x) {
|
|
18321
18321
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
18322
18322
|
}
|
|
@@ -18780,7 +18780,7 @@ var useEnv = (initEnv, initKey = "config", isOverwrite) => {
|
|
|
18780
18780
|
}
|
|
18781
18781
|
return gt[initKey];
|
|
18782
18782
|
};
|
|
18783
|
-
var useEnvKey = (key, init, initKey = "config") => {
|
|
18783
|
+
var useEnvKey = (key, init, initKey = "config", opts = {}) => {
|
|
18784
18784
|
const _env = useEnv({}, initKey);
|
|
18785
18785
|
if (key && typeof _env[key] !== "undefined") {
|
|
18786
18786
|
return _env[key];
|
|
@@ -18806,12 +18806,13 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
18806
18806
|
const voidFn = async () => {
|
|
18807
18807
|
return _env[key];
|
|
18808
18808
|
};
|
|
18809
|
+
const timeout = opts.timeout || 5 * 60 * 1000;
|
|
18809
18810
|
const checkFn = async () => {
|
|
18810
18811
|
const loadRes = await baseLoad.load(voidFn, {
|
|
18811
18812
|
key,
|
|
18812
18813
|
isReRun: true,
|
|
18813
18814
|
checkSuccess: () => _env[key],
|
|
18814
|
-
timeout
|
|
18815
|
+
timeout,
|
|
18815
18816
|
interval: 1000
|
|
18816
18817
|
});
|
|
18817
18818
|
if (loadRes.code !== 200) {
|
|
@@ -18827,27 +18828,28 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
18827
18828
|
};
|
|
18828
18829
|
var useEnvKeyNew = (key, initKey = "config", opts) => {
|
|
18829
18830
|
const _env = useEnv({}, initKey);
|
|
18831
|
+
const timeout = opts?.timeout;
|
|
18830
18832
|
if (key) {
|
|
18831
18833
|
delete _env[key];
|
|
18832
18834
|
}
|
|
18833
18835
|
if (opts?.getNew && opts.init) {
|
|
18834
|
-
return useEnvKey(key, opts.init, initKey);
|
|
18836
|
+
return useEnvKey(key, opts.init, initKey, { timeout });
|
|
18835
18837
|
} else if (opts?.getNew) {
|
|
18836
|
-
return useEnvKey(key, null, initKey);
|
|
18838
|
+
return useEnvKey(key, null, initKey, { timeout });
|
|
18837
18839
|
}
|
|
18838
18840
|
};
|
|
18839
|
-
var useContextKey = (key, init,
|
|
18840
|
-
if (isNew) {
|
|
18841
|
-
return useEnvKeyNew(key, "context", { getNew: true, init });
|
|
18841
|
+
var useContextKey = (key, init, opts) => {
|
|
18842
|
+
if (opts?.isNew) {
|
|
18843
|
+
return useEnvKeyNew(key, "context", { getNew: true, init, ...opts });
|
|
18842
18844
|
}
|
|
18843
|
-
return useEnvKey(key, init, "context");
|
|
18845
|
+
return useEnvKey(key, init, "context", opts);
|
|
18844
18846
|
};
|
|
18845
18847
|
var use = useContextKey;
|
|
18846
|
-
var useConfigKey = (key, init,
|
|
18847
|
-
if (isNew) {
|
|
18848
|
-
return useEnvKeyNew(key, "config", { getNew: true, init });
|
|
18848
|
+
var useConfigKey = (key, init, opts) => {
|
|
18849
|
+
if (opts?.isNew) {
|
|
18850
|
+
return useEnvKeyNew(key, "config", { getNew: true, init, ...opts });
|
|
18849
18851
|
}
|
|
18850
|
-
return useEnvKey(key, init, "config");
|
|
18852
|
+
return useEnvKey(key, init, "config", opts);
|
|
18851
18853
|
};
|
|
18852
18854
|
|
|
18853
18855
|
class InitEnv {
|
|
@@ -19517,7 +19519,7 @@ app
|
|
|
19517
19519
|
10. **中间件找不到会返回 404**,错误信息中会包含找不到的中间件列表。
|
|
19518
19520
|
`;
|
|
19519
19521
|
// package.json
|
|
19520
|
-
var version2 = "0.0.
|
|
19522
|
+
var version2 = "0.0.81";
|
|
19521
19523
|
|
|
19522
19524
|
// agent/routes/route-create.ts
|
|
19523
19525
|
app.route({
|
package/dist/opencode.d.ts
CHANGED
|
@@ -350,10 +350,15 @@ declare class QueryRouter {
|
|
|
350
350
|
}): Promise<void>;
|
|
351
351
|
toJSONSchema: (args: any, opts?: {
|
|
352
352
|
mergeObject?: boolean;
|
|
353
|
+
override?: (opts: {
|
|
354
|
+
jsonSchema: any;
|
|
355
|
+
path: string[];
|
|
356
|
+
zodSchema: z.ZodTypeAny;
|
|
357
|
+
}) => void;
|
|
353
358
|
}) => {
|
|
354
359
|
[key: string]: any;
|
|
355
360
|
};
|
|
356
|
-
fromJSONSchema: <Merge extends boolean =
|
|
361
|
+
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
357
362
|
mergeObject?: boolean;
|
|
358
363
|
}) => Merge extends true ? z.ZodObject<{
|
|
359
364
|
[key: string]: any;
|
package/dist/opencode.js
CHANGED
|
@@ -203,7 +203,8 @@ var require_eventemitter3 = __commonJS((exports, module) => {
|
|
|
203
203
|
}
|
|
204
204
|
});
|
|
205
205
|
|
|
206
|
-
// node_modules/.pnpm/@kevisual+context@0.0.
|
|
206
|
+
// node_modules/.pnpm/@kevisual+context@0.0.8/node_modules/@kevisual/context/dist/app.js
|
|
207
|
+
var isBrowser2 = typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
207
208
|
function getDefaultExportFromCjs(x) {
|
|
208
209
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
209
210
|
}
|
|
@@ -667,7 +668,7 @@ var useEnv = (initEnv, initKey = "config", isOverwrite) => {
|
|
|
667
668
|
}
|
|
668
669
|
return gt[initKey];
|
|
669
670
|
};
|
|
670
|
-
var useEnvKey = (key, init, initKey = "config") => {
|
|
671
|
+
var useEnvKey = (key, init, initKey = "config", opts = {}) => {
|
|
671
672
|
const _env = useEnv({}, initKey);
|
|
672
673
|
if (key && typeof _env[key] !== "undefined") {
|
|
673
674
|
return _env[key];
|
|
@@ -693,12 +694,13 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
693
694
|
const voidFn = async () => {
|
|
694
695
|
return _env[key];
|
|
695
696
|
};
|
|
697
|
+
const timeout = opts.timeout || 5 * 60 * 1000;
|
|
696
698
|
const checkFn = async () => {
|
|
697
699
|
const loadRes = await baseLoad.load(voidFn, {
|
|
698
700
|
key,
|
|
699
701
|
isReRun: true,
|
|
700
702
|
checkSuccess: () => _env[key],
|
|
701
|
-
timeout
|
|
703
|
+
timeout,
|
|
702
704
|
interval: 1000
|
|
703
705
|
});
|
|
704
706
|
if (loadRes.code !== 200) {
|
|
@@ -714,27 +716,28 @@ var useEnvKey = (key, init, initKey = "config") => {
|
|
|
714
716
|
};
|
|
715
717
|
var useEnvKeyNew = (key, initKey = "config", opts) => {
|
|
716
718
|
const _env = useEnv({}, initKey);
|
|
719
|
+
const timeout = opts?.timeout;
|
|
717
720
|
if (key) {
|
|
718
721
|
delete _env[key];
|
|
719
722
|
}
|
|
720
723
|
if (opts?.getNew && opts.init) {
|
|
721
|
-
return useEnvKey(key, opts.init, initKey);
|
|
724
|
+
return useEnvKey(key, opts.init, initKey, { timeout });
|
|
722
725
|
} else if (opts?.getNew) {
|
|
723
|
-
return useEnvKey(key, null, initKey);
|
|
726
|
+
return useEnvKey(key, null, initKey, { timeout });
|
|
724
727
|
}
|
|
725
728
|
};
|
|
726
|
-
var useContextKey = (key, init,
|
|
727
|
-
if (isNew) {
|
|
728
|
-
return useEnvKeyNew(key, "context", { getNew: true, init });
|
|
729
|
+
var useContextKey = (key, init, opts) => {
|
|
730
|
+
if (opts?.isNew) {
|
|
731
|
+
return useEnvKeyNew(key, "context", { getNew: true, init, ...opts });
|
|
729
732
|
}
|
|
730
|
-
return useEnvKey(key, init, "context");
|
|
733
|
+
return useEnvKey(key, init, "context", opts);
|
|
731
734
|
};
|
|
732
735
|
var use = useContextKey;
|
|
733
|
-
var useConfigKey = (key, init,
|
|
734
|
-
if (isNew) {
|
|
735
|
-
return useEnvKeyNew(key, "config", { getNew: true, init });
|
|
736
|
+
var useConfigKey = (key, init, opts) => {
|
|
737
|
+
if (opts?.isNew) {
|
|
738
|
+
return useEnvKeyNew(key, "config", { getNew: true, init, ...opts });
|
|
736
739
|
}
|
|
737
|
-
return useEnvKey(key, init, "config");
|
|
740
|
+
return useEnvKey(key, init, "config", opts);
|
|
738
741
|
};
|
|
739
742
|
|
|
740
743
|
class InitEnv {
|
package/dist/router-browser.d.ts
CHANGED
|
@@ -204,17 +204,17 @@ declare class Route<U = {
|
|
|
204
204
|
}, opts?: AddOpts): void;
|
|
205
205
|
throw(code?: number | string, message?: string, tips?: string): void;
|
|
206
206
|
}
|
|
207
|
-
/**
|
|
208
|
-
* 剥离第一层schema,转换为JSON Schema,无论是skill还是其他的infer比纯粹的zod object schema更合适,因为它可能包含其他的字段,而不仅仅是schema
|
|
209
|
-
* @param args
|
|
210
|
-
* @returns
|
|
211
|
-
*/
|
|
212
207
|
declare const toJSONSchema: (args: any, opts?: {
|
|
213
208
|
mergeObject?: boolean;
|
|
209
|
+
override?: (opts: {
|
|
210
|
+
jsonSchema: any;
|
|
211
|
+
path: string[];
|
|
212
|
+
zodSchema: z.ZodTypeAny;
|
|
213
|
+
}) => void;
|
|
214
214
|
}) => {
|
|
215
215
|
[key: string]: any;
|
|
216
216
|
};
|
|
217
|
-
declare const fromJSONSchema: <Merge extends boolean =
|
|
217
|
+
declare const fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
218
218
|
mergeObject?: boolean;
|
|
219
219
|
}) => Merge extends true ? z.ZodObject<{
|
|
220
220
|
[key: string]: any;
|
|
@@ -394,10 +394,15 @@ declare class QueryRouter {
|
|
|
394
394
|
}): Promise<void>;
|
|
395
395
|
toJSONSchema: (args: any, opts?: {
|
|
396
396
|
mergeObject?: boolean;
|
|
397
|
+
override?: (opts: {
|
|
398
|
+
jsonSchema: any;
|
|
399
|
+
path: string[];
|
|
400
|
+
zodSchema: z.ZodTypeAny;
|
|
401
|
+
}) => void;
|
|
397
402
|
}) => {
|
|
398
403
|
[key: string]: any;
|
|
399
404
|
};
|
|
400
|
-
fromJSONSchema: <Merge extends boolean =
|
|
405
|
+
fromJSONSchema: <Merge extends boolean = false>(args?: any, opts?: {
|
|
401
406
|
mergeObject?: boolean;
|
|
402
407
|
}) => Merge extends true ? z.ZodObject<{
|
|
403
408
|
[key: string]: any;
|
|
@@ -493,20 +498,23 @@ declare const createSchema: (rule: Rule) => z.ZodType<any, any, any>;
|
|
|
493
498
|
|
|
494
499
|
type Schema = z.ZodType<any, any, any>;
|
|
495
500
|
|
|
501
|
+
type CustomErrorOptions = {
|
|
502
|
+
cause?: Error | string;
|
|
503
|
+
code?: number;
|
|
504
|
+
message?: string;
|
|
505
|
+
};
|
|
496
506
|
/** 自定义错误 */
|
|
497
507
|
declare class CustomError extends Error {
|
|
498
508
|
code?: number;
|
|
499
509
|
data?: any;
|
|
500
510
|
message: string;
|
|
501
|
-
|
|
502
|
-
constructor(code?: number | string, message?: string, tips?: string);
|
|
511
|
+
constructor(code?: number | string, opts?: CustomErrorOptions);
|
|
503
512
|
static fromCode(code?: number): CustomError;
|
|
504
513
|
static fromErrorData(code?: number, data?: any): CustomError;
|
|
505
514
|
static parseError(e: CustomError): {
|
|
506
515
|
code: number;
|
|
507
516
|
data: any;
|
|
508
517
|
message: string;
|
|
509
|
-
tips: string;
|
|
510
518
|
};
|
|
511
519
|
/**
|
|
512
520
|
* 判断 throw 的错误是否不是当前这个错误
|
|
@@ -518,7 +526,6 @@ declare class CustomError extends Error {
|
|
|
518
526
|
code: number;
|
|
519
527
|
data: any;
|
|
520
528
|
message: string;
|
|
521
|
-
tips: string;
|
|
522
529
|
};
|
|
523
530
|
}
|
|
524
531
|
|