@kevisual/router 0.2.5 → 0.2.7

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.
@@ -30,7 +30,7 @@ var __toESM = (mod, isNodeMode, target) => {
30
30
  };
31
31
  var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
32
32
 
33
- // ../../node_modules/.pnpm/path-to-regexp@8.4.0/node_modules/path-to-regexp/dist/index.js
33
+ // ../../node_modules/.pnpm/path-to-regexp@8.4.2/node_modules/path-to-regexp/dist/index.js
34
34
  var require_dist = __commonJS((exports) => {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.PathError = exports.TokenData = undefined;
@@ -44,7 +44,6 @@ var require_dist = __commonJS((exports) => {
44
44
  var ID_START = /^[$_\p{ID_Start}]$/u;
45
45
  var ID_CONTINUE = /^[$\u200c\u200d\p{ID_Continue}]$/u;
46
46
  var ID = /^[$_\p{ID_Start}][$\u200c\u200d\p{ID_Continue}]*$/u;
47
- var SIMPLE_TOKENS = "{}()[]+?!";
48
47
  function escapeText(str) {
49
48
  return str.replace(/[{}()\[\]+?!:*\\]/g, "\\$&");
50
49
  }
@@ -74,96 +73,90 @@ var require_dist = __commonJS((exports) => {
74
73
  function parse(str, options = {}) {
75
74
  const { encodePath = NOOP_VALUE } = options;
76
75
  const chars = [...str];
77
- const tokens = [];
78
76
  let index = 0;
79
- let pos = 0;
80
- function name() {
81
- let value = "";
82
- if (ID_START.test(chars[index])) {
83
- do {
84
- value += chars[index++];
85
- } while (ID_CONTINUE.test(chars[index]));
86
- } else if (chars[index] === '"') {
87
- let quoteStart = index;
88
- while (index < chars.length) {
89
- if (chars[++index] === '"') {
90
- index++;
91
- quoteStart = 0;
92
- break;
93
- }
94
- if (chars[index] === "\\")
95
- index++;
96
- value += chars[index];
97
- }
98
- if (quoteStart) {
99
- throw new PathError(`Unterminated quote at index ${quoteStart}`, str);
100
- }
101
- }
102
- if (!value) {
103
- throw new PathError(`Missing parameter name at index ${index}`, str);
104
- }
105
- return value;
106
- }
107
- while (index < chars.length) {
108
- const value = chars[index++];
109
- if (SIMPLE_TOKENS.includes(value)) {
110
- tokens.push({ type: value, index, value });
111
- } else if (value === "\\") {
112
- tokens.push({ type: "escape", index, value: chars[index++] });
113
- } else if (value === ":") {
114
- tokens.push({ type: "param", index, value: name() });
115
- } else if (value === "*") {
116
- tokens.push({ type: "wildcard", index, value: name() });
117
- } else {
118
- tokens.push({ type: "char", index, value });
119
- }
120
- }
121
- tokens.push({ type: "end", index, value: "" });
122
- function consumeUntil(endType) {
77
+ function consumeUntil(end) {
123
78
  const output = [];
124
- while (true) {
125
- const token = tokens[pos++];
126
- if (token.type === endType)
127
- break;
128
- if (token.type === "char" || token.type === "escape") {
129
- let path = token.value;
130
- let cur = tokens[pos];
131
- while (cur.type === "char" || cur.type === "escape") {
132
- path += cur.value;
133
- cur = tokens[++pos];
79
+ let path = "";
80
+ function writePath() {
81
+ if (!path)
82
+ return;
83
+ output.push({
84
+ type: "text",
85
+ value: encodePath(path)
86
+ });
87
+ path = "";
88
+ }
89
+ while (index < chars.length) {
90
+ const value = chars[index++];
91
+ if (value === end) {
92
+ writePath();
93
+ return output;
94
+ }
95
+ if (value === "\\") {
96
+ if (index === chars.length) {
97
+ throw new PathError(`Unexpected end after \\ at index ${index}`, str);
134
98
  }
135
- output.push({
136
- type: "text",
137
- value: encodePath(path)
138
- });
99
+ path += chars[index++];
139
100
  continue;
140
101
  }
141
- if (token.type === "param" || token.type === "wildcard") {
142
- output.push({
143
- type: token.type,
144
- name: token.value
145
- });
102
+ if (value === ":" || value === "*") {
103
+ const type = value === ":" ? "param" : "wildcard";
104
+ let name = "";
105
+ if (ID_START.test(chars[index])) {
106
+ do {
107
+ name += chars[index++];
108
+ } while (ID_CONTINUE.test(chars[index]));
109
+ } else if (chars[index] === '"') {
110
+ let quoteStart = index;
111
+ while (index < chars.length) {
112
+ if (chars[++index] === '"') {
113
+ index++;
114
+ quoteStart = 0;
115
+ break;
116
+ }
117
+ if (chars[index] === "\\")
118
+ index++;
119
+ name += chars[index];
120
+ }
121
+ if (quoteStart) {
122
+ throw new PathError(`Unterminated quote at index ${quoteStart}`, str);
123
+ }
124
+ }
125
+ if (!name) {
126
+ throw new PathError(`Missing parameter name at index ${index}`, str);
127
+ }
128
+ writePath();
129
+ output.push({ type, name });
146
130
  continue;
147
131
  }
148
- if (token.type === "{") {
132
+ if (value === "{") {
133
+ writePath();
149
134
  output.push({
150
135
  type: "group",
151
136
  tokens: consumeUntil("}")
152
137
  });
153
138
  continue;
154
139
  }
155
- throw new PathError(`Unexpected ${token.type} at index ${token.index}, expected ${endType}`, str);
140
+ if (value === "}" || value === "(" || value === ")" || value === "[" || value === "]" || value === "+" || value === "?" || value === "!") {
141
+ throw new PathError(`Unexpected ${value} at index ${index - 1}`, str);
142
+ }
143
+ path += value;
156
144
  }
145
+ if (end) {
146
+ throw new PathError(`Unexpected end at index ${index}, expected ${end}`, str);
147
+ }
148
+ writePath();
157
149
  return output;
158
150
  }
159
- return new TokenData(consumeUntil("end"), str);
151
+ return new TokenData(consumeUntil(""), str);
160
152
  }
161
153
  function compile(path, options = {}) {
162
154
  const { encode = encodeURIComponent, delimiter = DEFAULT_DELIMITER } = options;
163
155
  const data = typeof path === "object" ? path : parse(path, options);
164
156
  const fn = tokensToFunction(data.tokens, delimiter, encode);
165
157
  return function path2(params = {}) {
166
- const [path3, ...missing] = fn(params);
158
+ const missing = [];
159
+ const path3 = fn(params, missing);
167
160
  if (missing.length) {
168
161
  throw new TypeError(`Missing parameters: ${missing.join(", ")}`);
169
162
  }
@@ -172,55 +165,61 @@ var require_dist = __commonJS((exports) => {
172
165
  }
173
166
  function tokensToFunction(tokens, delimiter, encode) {
174
167
  const encoders = tokens.map((token) => tokenToFunction(token, delimiter, encode));
175
- return (data) => {
176
- const result = [""];
168
+ return (data, missing) => {
169
+ let result = "";
177
170
  for (const encoder of encoders) {
178
- const [value, ...extras] = encoder(data);
179
- result[0] += value;
180
- result.push(...extras);
171
+ result += encoder(data, missing);
181
172
  }
182
173
  return result;
183
174
  };
184
175
  }
185
176
  function tokenToFunction(token, delimiter, encode) {
186
177
  if (token.type === "text")
187
- return () => [token.value];
178
+ return () => token.value;
188
179
  if (token.type === "group") {
189
180
  const fn = tokensToFunction(token.tokens, delimiter, encode);
190
- return (data) => {
191
- const [value, ...missing] = fn(data);
192
- if (!missing.length)
193
- return [value];
194
- return [""];
181
+ return (data, missing) => {
182
+ const len = missing.length;
183
+ const value = fn(data, missing);
184
+ if (missing.length === len)
185
+ return value;
186
+ missing.length = len;
187
+ return "";
195
188
  };
196
189
  }
197
190
  const encodeValue = encode || NOOP_VALUE;
198
191
  if (token.type === "wildcard" && encode !== false) {
199
- return (data) => {
192
+ return (data, missing) => {
200
193
  const value = data[token.name];
201
- if (value == null)
202
- return ["", token.name];
194
+ if (value == null) {
195
+ missing.push(token.name);
196
+ return "";
197
+ }
203
198
  if (!Array.isArray(value) || value.length === 0) {
204
199
  throw new TypeError(`Expected "${token.name}" to be a non-empty array`);
205
200
  }
206
- return [
207
- value.map((value2, index) => {
208
- if (typeof value2 !== "string") {
209
- throw new TypeError(`Expected "${token.name}/${index}" to be a string`);
210
- }
211
- return encodeValue(value2);
212
- }).join(delimiter)
213
- ];
201
+ let result = "";
202
+ for (let i = 0;i < value.length; i++) {
203
+ if (typeof value[i] !== "string") {
204
+ throw new TypeError(`Expected "${token.name}/${i}" to be a string`);
205
+ }
206
+ if (i > 0)
207
+ result += delimiter;
208
+ result += encodeValue(value[i]);
209
+ }
210
+ return result;
214
211
  };
215
212
  }
216
- return (data) => {
213
+ return (data, missing) => {
217
214
  const value = data[token.name];
218
- if (value == null)
219
- return ["", token.name];
215
+ if (value == null) {
216
+ missing.push(token.name);
217
+ return "";
218
+ }
220
219
  if (typeof value !== "string") {
221
220
  throw new TypeError(`Expected "${token.name}" to be a string`);
222
221
  }
223
- return [encodeValue(value)];
222
+ return encodeValue(value);
224
223
  };
225
224
  }
226
225
  function match(path, options = {}) {
@@ -251,67 +250,48 @@ var require_dist = __commonJS((exports) => {
251
250
  }
252
251
  function pathToRegexp(path, options = {}) {
253
252
  const { delimiter = DEFAULT_DELIMITER, end = true, sensitive = false, trailing = true } = options;
254
- const root = new SourceNode("^");
255
- const paths = [path];
253
+ const keys = [];
254
+ let source = "";
256
255
  let combinations = 0;
257
- while (paths.length) {
258
- const path2 = paths.shift();
256
+ function process2(path2) {
259
257
  if (Array.isArray(path2)) {
260
- paths.push(...path2);
261
- continue;
258
+ for (const p of path2)
259
+ process2(p);
260
+ return;
262
261
  }
263
262
  const data = typeof path2 === "object" ? path2 : parse(path2, options);
264
263
  flatten(data.tokens, 0, [], (tokens) => {
265
- if (combinations++ >= 256) {
264
+ if (combinations >= 256) {
266
265
  throw new PathError("Too many path combinations", data.originalPath);
267
266
  }
268
- let node = root;
269
- for (const part of toRegExpSource(tokens, delimiter, data.originalPath)) {
270
- node = node.add(part.source, part.key);
271
- }
272
- node.add("");
267
+ if (combinations > 0)
268
+ source += "|";
269
+ source += toRegExpSource(tokens, delimiter, keys, data.originalPath);
270
+ combinations++;
273
271
  });
274
272
  }
275
- const keys = [];
276
- let pattern = toRegExp(root, keys);
273
+ process2(path);
274
+ let pattern = `^(?:${source})`;
277
275
  if (trailing)
278
276
  pattern += "(?:" + escape(delimiter) + "$)?";
279
277
  pattern += end ? "$" : "(?=" + escape(delimiter) + "|$)";
280
278
  return { regexp: new RegExp(pattern, sensitive ? "" : "i"), keys };
281
279
  }
282
- function toRegExp(node, keys) {
283
- if (node.key)
284
- keys.push(node.key);
285
- const children = Object.keys(node.children);
286
- const text = children.map((id) => toRegExp(node.children[id], keys)).join("|");
287
- return node.source + (children.length < 2 ? text : `(?:${text})`);
288
- }
289
-
290
- class SourceNode {
291
- constructor(source, key) {
292
- this.source = source;
293
- this.key = key;
294
- this.children = Object.create(null);
295
- }
296
- add(source, key) {
297
- var _a;
298
- const id = source + ":" + (key ? key.name : "");
299
- return (_a = this.children)[id] || (_a[id] = new SourceNode(source, key));
300
- }
301
- }
302
280
  function flatten(tokens, index, result, callback) {
303
281
  while (index < tokens.length) {
304
282
  const token = tokens[index++];
305
283
  if (token.type === "group") {
306
- flatten(token.tokens, 0, result.slice(), (seq) => flatten(tokens, index, seq, callback));
284
+ const len = result.length;
285
+ flatten(token.tokens, 0, result, (seq) => flatten(tokens, index, seq, callback));
286
+ result.length = len;
307
287
  continue;
308
288
  }
309
289
  result.push(token);
310
290
  }
311
291
  callback(result);
312
292
  }
313
- function toRegExpSource(tokens, delimiter, originalPath) {
314
- let result = [];
293
+ function toRegExpSource(tokens, delimiter, keys, originalPath) {
294
+ let result = "";
315
295
  let backtrack = "";
316
296
  let wildcardBacktrack = "";
317
297
  let prevCaptureType = 0;
@@ -342,7 +322,7 @@ var require_dist = __commonJS((exports) => {
342
322
  while (index < tokens.length) {
343
323
  const token = tokens[index++];
344
324
  if (token.type === "text") {
345
- result.push({ source: escape(token.value) });
325
+ result += escape(token.value);
346
326
  backtrack += token.value;
347
327
  if (prevCaptureType === 2)
348
328
  wildcardBacktrack += token.value;
@@ -355,19 +335,14 @@ var require_dist = __commonJS((exports) => {
355
335
  throw new PathError(`Missing text before "${token.name}" ${token.type}`, originalPath);
356
336
  }
357
337
  if (token.type === "param") {
358
- result.push({
359
- source: hasSegmentCapture ? `(${negate(delimiter, backtrack)}+?)` : hasInSegment(index, "wildcard") ? `(${negate(delimiter, peekText(index))}+?)` : `(${negate(delimiter, "")}+?)`,
360
- key: token
361
- });
338
+ result += hasSegmentCapture & 2 ? `(${negate(delimiter, backtrack)}+)` : hasInSegment(index, "wildcard") ? `(${negate(delimiter, peekText(index))}+)` : hasSegmentCapture & 1 ? `(${negate(delimiter, backtrack)}+|${escape(backtrack)})` : `(${negate(delimiter, "")}+)`;
362
339
  hasSegmentCapture |= prevCaptureType = 1;
363
340
  } else {
364
- result.push({
365
- source: hasSegmentCapture & 2 ? `(${negate(backtrack, "")}+?)` : hasSegmentCapture & 1 ? `(${negate(wildcardBacktrack, "")}+?)` : wildcardBacktrack ? `(${negate(wildcardBacktrack, "")}+?|${negate(delimiter, "")}+?)` : `([^]+?)`,
366
- key: token
367
- });
341
+ result += hasSegmentCapture & 2 ? `(${negate(backtrack, "")}+)` : wildcardBacktrack ? `(${negate(wildcardBacktrack, "")}+|${negate(delimiter, "")}+)` : `([^]+)`;
368
342
  wildcardBacktrack = "";
369
343
  hasSegmentCapture |= prevCaptureType = 2;
370
344
  }
345
+ keys.push(token);
371
346
  backtrack = "";
372
347
  continue;
373
348
  }
@@ -725,7 +700,7 @@ class HttpChain {
725
700
  setInterval(() => {
726
701
  res.write(`
727
702
  `);
728
- }, 3000);
703
+ }, 3000).unref?.();
729
704
  req.on("close", () => {
730
705
  clearInterval(intervalId);
731
706
  res.end();
package/dist/router.d.ts CHANGED
@@ -22,7 +22,7 @@ declare class CustomError extends Error {
22
22
  static fromCode(code?: number): CustomError;
23
23
  static fromErrorData(code?: number, data?: any): CustomError;
24
24
  static parseError(e: CustomError): {
25
- code: number | undefined;
25
+ code: number;
26
26
  data: any;
27
27
  message: string;
28
28
  };
@@ -36,7 +36,7 @@ declare class CustomError extends Error {
36
36
  static throw(code?: number | string, opts?: CustomErrorOptions): void;
37
37
  static throw(opts?: CustomErrorOptions): void;
38
38
  parse(e?: CustomError): {
39
- code: number | undefined;
39
+ code: number;
40
40
  data: any;
41
41
  message: string;
42
42
  };
@@ -59,22 +59,6 @@ declare class MockProcess {
59
59
  on(fn: (msg?: any) => any): void;
60
60
  desctroy(): void;
61
61
  }
62
- type ListenProcessParams = {
63
- message?: RunMessage;
64
- context?: any;
65
- };
66
- type ListenProcessResponse = {
67
- success?: boolean;
68
- data?: {
69
- code?: number;
70
- data?: any;
71
- message?: string;
72
- [key: string]: any;
73
- };
74
- error?: any;
75
- timestamp?: string;
76
- [key: string]: any;
77
- };
78
62
 
79
63
  type RouterContextT = {
80
64
  code?: number;
@@ -232,7 +216,7 @@ declare class Route<M extends SimpleObject$1 = SimpleObject$1, U extends SimpleO
232
216
  description?: string;
233
217
  metadata?: M;
234
218
  middleware?: RouteMiddleware[];
235
- type?: string | undefined;
219
+ type?: string;
236
220
  /**
237
221
  * 是否开启debug,开启后会打印错误信息
238
222
  */
@@ -325,6 +309,7 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
325
309
  path: string;
326
310
  key?: string;
327
311
  payload?: any;
312
+ args?: any;
328
313
  }, ctx?: RouteContext<T> & {
329
314
  [key: string]: any;
330
315
  }): Promise<RouteContext<T, {}, {
@@ -341,13 +326,14 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
341
326
  path?: string;
342
327
  key?: string;
343
328
  payload?: any;
329
+ args?: any;
344
330
  }, ctx?: RouteContext<T> & {
345
331
  [key: string]: any;
346
332
  }): Promise<RouteContext<T, {}, {
347
333
  [key: string]: any;
348
334
  }> | {
349
335
  code: number;
350
- body: null;
336
+ body: any;
351
337
  message: string;
352
338
  }>;
353
339
  /**
@@ -362,12 +348,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
362
348
  path: string;
363
349
  key?: string;
364
350
  payload?: any;
351
+ args?: any;
365
352
  }, ctx?: RouteContext & {
366
353
  [key: string]: any;
367
354
  }): Promise<{
368
- code: number | undefined;
369
- data: string | number | Object | null | undefined;
370
- message: string | undefined;
355
+ code: number;
356
+ data: any;
357
+ message: string;
371
358
  }>;
372
359
  /**
373
360
  * Router Run获取数据
@@ -380,12 +367,13 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
380
367
  path?: string;
381
368
  key?: string;
382
369
  payload?: any;
370
+ args?: any;
383
371
  }, ctx?: RouteContext<T> & {
384
372
  [key: string]: any;
385
373
  }): Promise<{
386
- code: number | undefined;
387
- data: string | number | Object | null | undefined;
388
- message: string | undefined;
374
+ code: number;
375
+ data: any;
376
+ message: string;
389
377
  }>;
390
378
  /**
391
379
  * 设置上下文
@@ -420,12 +408,12 @@ declare class QueryRouter<T extends SimpleObject$1 = SimpleObject$1> implements
420
408
  importRoutes(routes: Route[]): void;
421
409
  importRouter(router: QueryRouter): void;
422
410
  throw(...args: any[]): void;
423
- hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1> | undefined;
411
+ hasRoute(path: string, key?: string): Route<SimpleObject$1, SimpleObject$1>;
424
412
  findRoute(opts?: {
425
413
  path?: string;
426
414
  key?: string;
427
415
  rid?: string;
428
- }): Route<SimpleObject$1, SimpleObject$1> | undefined;
416
+ }): Route<SimpleObject$1, SimpleObject$1>;
429
417
  createRouteList(opts?: {
430
418
  force?: boolean;
431
419
  filter?: (route: Route) => boolean;
@@ -519,6 +507,21 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
519
507
  path?: string;
520
508
  key?: string;
521
509
  payload?: any;
510
+ args?: any;
511
+ token?: string;
512
+ data?: any;
513
+ }, ctx?: Partial<RouteContext<C>>): Promise<any>;
514
+ /**
515
+ * 调用了handle
516
+ * @param param0
517
+ * @returns
518
+ */
519
+ runLocal(msg: {
520
+ rid?: string;
521
+ path?: string;
522
+ key?: string;
523
+ payload?: any;
524
+ args?: any;
522
525
  token?: string;
523
526
  data?: any;
524
527
  }, ctx?: Partial<RouteContext<C>>): Promise<any>;
@@ -534,7 +537,9 @@ declare class QueryRouterServer<C extends SimpleObject$1 = SimpleObject$1> exten
534
537
  * 创建认证相关的中间件,默认是 auth, auth-admin, auth-can 三个中间件
535
538
  * @param fun 认证函数,接收 RouteContext 和认证类型
536
539
  */
537
- createAuth(fun: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any): Promise<void>;
540
+ createAuth(fun?: (ctx: RouteContext<C>, type?: 'auth' | 'auth-admin' | 'auth-can') => any, opts?: {
541
+ overwrite?: boolean;
542
+ }): Promise<void>;
538
543
  }
539
544
  declare class Mini extends QueryRouterServer {
540
545
  }
@@ -628,8 +633,8 @@ declare class Chain {
628
633
  object: RouteOpts;
629
634
  app?: QueryRouterServer;
630
635
  constructor(object: RouteOpts, opts?: ChainOptions);
631
- get key(): string | undefined;
632
- get path(): string | undefined;
636
+ get key(): string;
637
+ get path(): string;
633
638
  setDescription(desc: string): this;
634
639
  setMeta(metadata: {
635
640
  [key: string]: any;
@@ -1031,7 +1036,10 @@ declare class ServerNode extends ServerBase implements ServerType {
1031
1036
  * @param res
1032
1037
  * @returns
1033
1038
  */
1034
- declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promise<any>;
1039
+ declare const handleServer: (req: IncomingMessage, res: ServerResponse) => Promise<{
1040
+ cookies: Record<string, string>;
1041
+ token: string;
1042
+ }>;
1035
1043
 
1036
1044
  type RouterHandle = (msg: {
1037
1045
  path: string;
@@ -1073,9 +1081,12 @@ declare class App<U = {}> extends QueryRouterServer<AppRouteContext<U>> {
1073
1081
  listen(handle: any, backlog?: number, listeningListener?: () => void): void;
1074
1082
  listen(handle: any, listeningListener?: () => void): void;
1075
1083
  Route: typeof Route;
1076
- static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<any>;
1084
+ static handleRequest(req: IncomingMessage$1, res: ServerResponse$1): Promise<{
1085
+ cookies: Record<string, string>;
1086
+ token: string;
1087
+ }>;
1077
1088
  onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
1078
1089
  }
1079
1090
 
1080
- export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
1081
- export type { HttpListenerFun, ListenProcessParams, ListenProcessResponse, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
1091
+ export { App, CustomError, Mini, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
1092
+ export type { HttpListenerFun, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteInfo, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
package/dist/router.js CHANGED
@@ -3691,7 +3691,7 @@ var listenProcess = async ({ app, mockProcess, params = {}, timeout: timeout2 =
3691
3691
  const ctx = mergeParams?.context || {};
3692
3692
  if (!msg.path && !msg.id) {
3693
3693
  const route = app.routes.find((r) => r.path !== "router");
3694
- msg.id = route?.id;
3694
+ msg.id = route?.rid;
3695
3695
  }
3696
3696
  const result = await app.run(msg, ctx);
3697
3697
  const response = {
@@ -17704,9 +17704,9 @@ class QueryRouter {
17704
17704
  if (!message?.path) {
17705
17705
  return Promise.resolve({ code: 404, body: null, message: "Not found path" });
17706
17706
  }
17707
- const { path, key = "", payload = {}, ...query } = message;
17707
+ const { path, key = "", payload = {}, args = {}, ...query } = message;
17708
17708
  ctx = ctx || {};
17709
- ctx.query = { ...ctx.query, ...query, ...payload };
17709
+ ctx.query = { ...ctx.query, ...query, ...payload, ...args };
17710
17710
  ctx.args = ctx.query;
17711
17711
  ctx.state = { ...ctx?.state };
17712
17712
  ctx.throw = this.throw;
@@ -17912,11 +17912,15 @@ class QueryRouterServer extends QueryRouter {
17912
17912
  }
17913
17913
  return super.run(msg, ctx);
17914
17914
  }
17915
+ async runLocal(msg, ctx) {
17916
+ return this.run(msg, { ...ctx, appId: this.appId });
17917
+ }
17915
17918
  async runAction(api2, payload, ctx) {
17916
17919
  const { path, key, rid } = api2;
17917
17920
  return this.run({ path, key, rid, payload }, ctx);
17918
17921
  }
17919
- async createAuth(fun) {
17922
+ async createAuth(fun, opts) {
17923
+ const overwrite = opts?.overwrite ?? false;
17920
17924
  this.route({
17921
17925
  path: "auth",
17922
17926
  key: "auth",
@@ -17926,7 +17930,7 @@ class QueryRouterServer extends QueryRouter {
17926
17930
  if (fun) {
17927
17931
  await fun(ctx, "auth");
17928
17932
  }
17929
- }).addTo(this, { overwrite: false });
17933
+ }).addTo(this, { overwrite });
17930
17934
  this.route({
17931
17935
  path: "auth-admin",
17932
17936
  key: "auth-admin",
@@ -17937,7 +17941,7 @@ class QueryRouterServer extends QueryRouter {
17937
17941
  if (fun) {
17938
17942
  await fun(ctx, "auth-admin");
17939
17943
  }
17940
- }).addTo(this, { overwrite: false });
17944
+ }).addTo(this, { overwrite });
17941
17945
  this.route({
17942
17946
  path: "auth-can",
17943
17947
  key: "auth-can",
@@ -17947,7 +17951,7 @@ class QueryRouterServer extends QueryRouter {
17947
17951
  if (fun) {
17948
17952
  await fun(ctx, "auth-can");
17949
17953
  }
17950
- }).addTo(this, { overwrite: false });
17954
+ }).addTo(this, { overwrite });
17951
17955
  }
17952
17956
  }
17953
17957
 
@@ -19085,7 +19089,6 @@ export {
19085
19089
  QueryUtil,
19086
19090
  QueryRouterServer,
19087
19091
  QueryRouter,
19088
- MockProcess,
19089
19092
  Mini,
19090
19093
  CustomError,
19091
19094
  App