@kevisual/router 0.0.16 → 0.0.17

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.
@@ -2,6 +2,7 @@ import { Schema } from 'zod';
2
2
  export { Schema } from 'zod';
3
3
  import * as querystring from 'querystring';
4
4
  import { IncomingMessage } from 'node:http';
5
+ import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
5
6
 
6
7
  type BaseRule = {
7
8
  value?: any;
@@ -436,5 +437,47 @@ declare const parseSearchValue: (value?: string, opts?: {
436
437
  decode?: boolean;
437
438
  }) => any;
438
439
 
439
- export { CustomError, QueryRouter, QueryRouterServer, Route, createSchema, parseBody, parseSearch, parseSearchValue };
440
- export type { RouteContext, RouteOpts, Rule, Run };
440
+ type RouteObject = {
441
+ [key: string]: RouteOpts$1;
442
+ };
443
+ declare function define<T extends Record<string, RouteOpts$1>>(value: T): {
444
+ [K in keyof T]: T[K] & RouteOpts$1;
445
+ };
446
+ type RouteArray = RouteOpts$1[];
447
+ type ChainOptions = {
448
+ app: QueryRouterServer$1;
449
+ };
450
+ declare class Chain {
451
+ object: RouteOpts$1;
452
+ app?: QueryRouterServer$1;
453
+ constructor(object: RouteOpts$1, opts?: ChainOptions);
454
+ get key(): string;
455
+ get path(): string;
456
+ setDescription(desc: string): this;
457
+ setMeta(metadata: {
458
+ [key: string]: any;
459
+ }): this;
460
+ setPath(path: string): this;
461
+ setMiddleware(middleware: RouteMiddleware$1[]): this;
462
+ setKey(key: string): this;
463
+ setId(key: string): this;
464
+ setRun(run: Run$1): this;
465
+ define(run: Run$1): this;
466
+ createRoute(): this;
467
+ }
468
+ declare const util: {
469
+ getChain: (obj: RouteOpts$1, opts?: ChainOptions) => Chain;
470
+ };
471
+ declare class QueryUtil<T extends RouteObject = RouteObject> {
472
+ routeObject: T;
473
+ app: QueryRouterServer$1;
474
+ constructor(object: T, opts?: ChainOptions);
475
+ static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions): QueryUtil<U>;
476
+ static create<U extends Record<string, RouteOpts$1>>(value: U, opts?: ChainOptions): QueryUtil<U>;
477
+ get<K extends keyof T>(key: K): RouteOpts$1;
478
+ chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
479
+ queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => RouteOpts$1;
480
+ }
481
+
482
+ export { CustomError, QueryRouter, QueryRouterServer, QueryUtil, Route, createSchema, define, parseBody, parseSearch, parseSearchValue, util };
483
+ export type { RouteArray, RouteContext, RouteObject, RouteOpts, Rule, Run };
@@ -94,7 +94,7 @@ try {
94
94
  }
95
95
  */
96
96
 
97
- var util;
97
+ var util$1;
98
98
  (function (util) {
99
99
  util.assertEqual = (val) => val;
100
100
  function assertIs(_arg) { }
@@ -156,7 +156,7 @@ var util;
156
156
  }
157
157
  return value;
158
158
  };
159
- })(util || (util = {}));
159
+ })(util$1 || (util$1 = {}));
160
160
  var objectUtil;
161
161
  (function (objectUtil) {
162
162
  objectUtil.mergeShapes = (first, second) => {
@@ -166,7 +166,7 @@ var objectUtil;
166
166
  };
167
167
  };
168
168
  })(objectUtil || (objectUtil = {}));
169
- const ZodParsedType = util.arrayToEnum([
169
+ const ZodParsedType = util$1.arrayToEnum([
170
170
  "string",
171
171
  "nan",
172
172
  "number",
@@ -233,7 +233,7 @@ const getParsedType = (data) => {
233
233
  }
234
234
  };
235
235
 
236
- const ZodIssueCode = util.arrayToEnum([
236
+ const ZodIssueCode = util$1.arrayToEnum([
237
237
  "invalid_type",
238
238
  "invalid_literal",
239
239
  "custom",
@@ -337,7 +337,7 @@ class ZodError extends Error {
337
337
  return this.message;
338
338
  }
339
339
  get message() {
340
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
340
+ return JSON.stringify(this.issues, util$1.jsonStringifyReplacer, 2);
341
341
  }
342
342
  get isEmpty() {
343
343
  return this.issues.length === 0;
@@ -377,19 +377,19 @@ const errorMap = (issue, _ctx) => {
377
377
  }
378
378
  break;
379
379
  case ZodIssueCode.invalid_literal:
380
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
380
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util$1.jsonStringifyReplacer)}`;
381
381
  break;
382
382
  case ZodIssueCode.unrecognized_keys:
383
- message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
383
+ message = `Unrecognized key(s) in object: ${util$1.joinValues(issue.keys, ", ")}`;
384
384
  break;
385
385
  case ZodIssueCode.invalid_union:
386
386
  message = `Invalid input`;
387
387
  break;
388
388
  case ZodIssueCode.invalid_union_discriminator:
389
- message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
389
+ message = `Invalid discriminator value. Expected ${util$1.joinValues(issue.options)}`;
390
390
  break;
391
391
  case ZodIssueCode.invalid_enum_value:
392
- message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
392
+ message = `Invalid enum value. Expected ${util$1.joinValues(issue.options)}, received '${issue.received}'`;
393
393
  break;
394
394
  case ZodIssueCode.invalid_arguments:
395
395
  message = `Invalid function arguments`;
@@ -415,7 +415,7 @@ const errorMap = (issue, _ctx) => {
415
415
  message = `Invalid input: must end with "${issue.validation.endsWith}"`;
416
416
  }
417
417
  else {
418
- util.assertNever(issue.validation);
418
+ util$1.assertNever(issue.validation);
419
419
  }
420
420
  }
421
421
  else if (issue.validation !== "regex") {
@@ -485,7 +485,7 @@ const errorMap = (issue, _ctx) => {
485
485
  break;
486
486
  default:
487
487
  message = _ctx.defaultError;
488
- util.assertNever(issue);
488
+ util$1.assertNever(issue);
489
489
  }
490
490
  return { message };
491
491
  };
@@ -1444,7 +1444,7 @@ class ZodString extends ZodType {
1444
1444
  }
1445
1445
  }
1446
1446
  else {
1447
- util.assertNever(check);
1447
+ util$1.assertNever(check);
1448
1448
  }
1449
1449
  }
1450
1450
  return { status: status.value, value: input.data };
@@ -1731,7 +1731,7 @@ class ZodNumber extends ZodType {
1731
1731
  const status = new ParseStatus();
1732
1732
  for (const check of this._def.checks) {
1733
1733
  if (check.kind === "int") {
1734
- if (!util.isInteger(input.data)) {
1734
+ if (!util$1.isInteger(input.data)) {
1735
1735
  ctx = this._getOrReturnCtx(input, ctx);
1736
1736
  addIssueToContext(ctx, {
1737
1737
  code: ZodIssueCode.invalid_type,
@@ -1798,7 +1798,7 @@ class ZodNumber extends ZodType {
1798
1798
  }
1799
1799
  }
1800
1800
  else {
1801
- util.assertNever(check);
1801
+ util$1.assertNever(check);
1802
1802
  }
1803
1803
  }
1804
1804
  return { status: status.value, value: input.data };
@@ -1921,7 +1921,7 @@ class ZodNumber extends ZodType {
1921
1921
  }
1922
1922
  get isInt() {
1923
1923
  return !!this._def.checks.find((ch) => ch.kind === "int" ||
1924
- (ch.kind === "multipleOf" && util.isInteger(ch.value)));
1924
+ (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1925
1925
  }
1926
1926
  get isFinite() {
1927
1927
  let max = null, min = null;
@@ -2017,7 +2017,7 @@ class ZodBigInt extends ZodType {
2017
2017
  }
2018
2018
  }
2019
2019
  else {
2020
- util.assertNever(check);
2020
+ util$1.assertNever(check);
2021
2021
  }
2022
2022
  }
2023
2023
  return { status: status.value, value: input.data };
@@ -2211,7 +2211,7 @@ class ZodDate extends ZodType {
2211
2211
  }
2212
2212
  }
2213
2213
  else {
2214
- util.assertNever(check);
2214
+ util$1.assertNever(check);
2215
2215
  }
2216
2216
  }
2217
2217
  return {
@@ -2584,7 +2584,7 @@ class ZodObject extends ZodType {
2584
2584
  if (this._cached !== null)
2585
2585
  return this._cached;
2586
2586
  const shape = this._def.shape();
2587
- const keys = util.objectKeys(shape);
2587
+ const keys = util$1.objectKeys(shape);
2588
2588
  return (this._cached = { shape, keys });
2589
2589
  }
2590
2590
  _parse(input) {
@@ -2826,7 +2826,7 @@ class ZodObject extends ZodType {
2826
2826
  }
2827
2827
  pick(mask) {
2828
2828
  const shape = {};
2829
- util.objectKeys(mask).forEach((key) => {
2829
+ util$1.objectKeys(mask).forEach((key) => {
2830
2830
  if (mask[key] && this.shape[key]) {
2831
2831
  shape[key] = this.shape[key];
2832
2832
  }
@@ -2838,7 +2838,7 @@ class ZodObject extends ZodType {
2838
2838
  }
2839
2839
  omit(mask) {
2840
2840
  const shape = {};
2841
- util.objectKeys(this.shape).forEach((key) => {
2841
+ util$1.objectKeys(this.shape).forEach((key) => {
2842
2842
  if (!mask[key]) {
2843
2843
  shape[key] = this.shape[key];
2844
2844
  }
@@ -2856,7 +2856,7 @@ class ZodObject extends ZodType {
2856
2856
  }
2857
2857
  partial(mask) {
2858
2858
  const newShape = {};
2859
- util.objectKeys(this.shape).forEach((key) => {
2859
+ util$1.objectKeys(this.shape).forEach((key) => {
2860
2860
  const fieldSchema = this.shape[key];
2861
2861
  if (mask && !mask[key]) {
2862
2862
  newShape[key] = fieldSchema;
@@ -2872,7 +2872,7 @@ class ZodObject extends ZodType {
2872
2872
  }
2873
2873
  required(mask) {
2874
2874
  const newShape = {};
2875
- util.objectKeys(this.shape).forEach((key) => {
2875
+ util$1.objectKeys(this.shape).forEach((key) => {
2876
2876
  if (mask && !mask[key]) {
2877
2877
  newShape[key] = this.shape[key];
2878
2878
  }
@@ -2891,7 +2891,7 @@ class ZodObject extends ZodType {
2891
2891
  });
2892
2892
  }
2893
2893
  keyof() {
2894
- return createZodEnum(util.objectKeys(this.shape));
2894
+ return createZodEnum(util$1.objectKeys(this.shape));
2895
2895
  }
2896
2896
  }
2897
2897
  ZodObject.create = (shape, params) => {
@@ -3039,7 +3039,7 @@ const getDiscriminator = (type) => {
3039
3039
  }
3040
3040
  else if (type instanceof ZodNativeEnum) {
3041
3041
  // eslint-disable-next-line ban/ban
3042
- return util.objectValues(type.enum);
3042
+ return util$1.objectValues(type.enum);
3043
3043
  }
3044
3044
  else if (type instanceof ZodDefault) {
3045
3045
  return getDiscriminator(type._def.innerType);
@@ -3155,8 +3155,8 @@ function mergeValues(a, b) {
3155
3155
  return { valid: true, data: a };
3156
3156
  }
3157
3157
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3158
- const bKeys = util.objectKeys(b);
3159
- const sharedKeys = util
3158
+ const bKeys = util$1.objectKeys(b);
3159
+ const sharedKeys = util$1
3160
3160
  .objectKeys(a)
3161
3161
  .filter((key) => bKeys.indexOf(key) !== -1);
3162
3162
  const newObj = { ...a, ...b };
@@ -3711,7 +3711,7 @@ class ZodEnum extends ZodType {
3711
3711
  const ctx = this._getOrReturnCtx(input);
3712
3712
  const expectedValues = this._def.values;
3713
3713
  addIssueToContext(ctx, {
3714
- expected: util.joinValues(expectedValues),
3714
+ expected: util$1.joinValues(expectedValues),
3715
3715
  received: ctx.parsedType,
3716
3716
  code: ZodIssueCode.invalid_type,
3717
3717
  });
@@ -3777,23 +3777,23 @@ class ZodNativeEnum extends ZodType {
3777
3777
  _ZodNativeEnum_cache.set(this, void 0);
3778
3778
  }
3779
3779
  _parse(input) {
3780
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
3780
+ const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
3781
3781
  const ctx = this._getOrReturnCtx(input);
3782
3782
  if (ctx.parsedType !== ZodParsedType.string &&
3783
3783
  ctx.parsedType !== ZodParsedType.number) {
3784
- const expectedValues = util.objectValues(nativeEnumValues);
3784
+ const expectedValues = util$1.objectValues(nativeEnumValues);
3785
3785
  addIssueToContext(ctx, {
3786
- expected: util.joinValues(expectedValues),
3786
+ expected: util$1.joinValues(expectedValues),
3787
3787
  received: ctx.parsedType,
3788
3788
  code: ZodIssueCode.invalid_type,
3789
3789
  });
3790
3790
  return INVALID;
3791
3791
  }
3792
3792
  if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
3793
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
3793
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$1.getValidEnumValues(this._def.values)));
3794
3794
  }
3795
3795
  if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
3796
- const expectedValues = util.objectValues(nativeEnumValues);
3796
+ const expectedValues = util$1.objectValues(nativeEnumValues);
3797
3797
  addIssueToContext(ctx, {
3798
3798
  received: ctx.data,
3799
3799
  code: ZodIssueCode.invalid_enum_value,
@@ -3976,7 +3976,7 @@ class ZodEffects extends ZodType {
3976
3976
  });
3977
3977
  }
3978
3978
  }
3979
- util.assertNever(effect);
3979
+ util$1.assertNever(effect);
3980
3980
  }
3981
3981
  }
3982
3982
  ZodEffects.create = (schema, effect, params) => {
@@ -4400,7 +4400,7 @@ var z = /*#__PURE__*/Object.freeze({
4400
4400
  isDirty: isDirty,
4401
4401
  isValid: isValid,
4402
4402
  isAsync: isAsync,
4403
- get util () { return util; },
4403
+ get util () { return util$1; },
4404
4404
  get objectUtil () { return objectUtil; },
4405
4405
  ZodParsedType: ZodParsedType,
4406
4406
  getParsedType: getParsedType,
@@ -6299,4 +6299,95 @@ const parseSearchValue = (value, opts) => {
6299
6299
  }
6300
6300
  };
6301
6301
 
6302
- export { CustomError, QueryRouter, QueryRouterServer, Route, ZodType as Schema, createSchema, parseBody, parseSearch, parseSearchValue };
6302
+ function define(value) {
6303
+ return value;
6304
+ }
6305
+ class Chain {
6306
+ object;
6307
+ app;
6308
+ constructor(object, opts) {
6309
+ this.object = object;
6310
+ this.app = opts?.app;
6311
+ }
6312
+ get key() {
6313
+ return this.object.key;
6314
+ }
6315
+ get path() {
6316
+ return this.object.path;
6317
+ }
6318
+ setDescription(desc) {
6319
+ this.object.description = desc;
6320
+ return this;
6321
+ }
6322
+ setMeta(metadata) {
6323
+ this.object.metadata = metadata;
6324
+ return this;
6325
+ }
6326
+ setPath(path) {
6327
+ this.object.path = path;
6328
+ return this;
6329
+ }
6330
+ setMiddleware(middleware) {
6331
+ this.object.middleware = middleware;
6332
+ return this;
6333
+ }
6334
+ setKey(key) {
6335
+ this.object.key = key;
6336
+ return this;
6337
+ }
6338
+ setId(key) {
6339
+ this.object.id = key;
6340
+ return this;
6341
+ }
6342
+ setRun(run) {
6343
+ this.object.run = run;
6344
+ return this;
6345
+ }
6346
+ define(run) {
6347
+ this.object.run = run;
6348
+ return this;
6349
+ }
6350
+ createRoute() {
6351
+ this.app.route(this.object).addTo(this.app);
6352
+ return this;
6353
+ }
6354
+ }
6355
+ const util = {
6356
+ getChain: (obj, opts) => {
6357
+ return new Chain(obj, opts);
6358
+ },
6359
+ };
6360
+ class QueryUtil {
6361
+ routeObject;
6362
+ app;
6363
+ constructor(object, opts) {
6364
+ this.routeObject = object;
6365
+ this.app = opts?.app;
6366
+ }
6367
+ static createFormObj(object, opts) {
6368
+ return new QueryUtil(object, opts);
6369
+ }
6370
+ static create(value, opts) {
6371
+ const obj = value;
6372
+ return new QueryUtil(obj, opts);
6373
+ }
6374
+ get(key) {
6375
+ return this.routeObject[key];
6376
+ }
6377
+ chain(key, opts) {
6378
+ const obj = this.routeObject[key];
6379
+ let newOpts = { app: this.app, ...opts };
6380
+ return new Chain(obj, newOpts);
6381
+ }
6382
+ queryChain(key) {
6383
+ const value = this.routeObject[key];
6384
+ return (queryData) => {
6385
+ return {
6386
+ ...value,
6387
+ ...queryData,
6388
+ };
6389
+ };
6390
+ }
6391
+ }
6392
+
6393
+ export { CustomError, QueryRouter, QueryRouterServer, QueryUtil, Route, ZodType as Schema, createSchema, define, parseBody, parseSearch, parseSearchValue, util };
@@ -1,398 +1,5 @@
1
- import * as node_modules_zod_lib_types_js from 'node_modules/zod/lib/types.js';
2
- import { Schema } from 'zod';
3
-
4
- type BaseRule = {
5
- value?: any;
6
- required?: boolean;
7
- message?: string;
8
- };
9
- type RuleString = {
10
- type: 'string';
11
- minLength?: number;
12
- maxLength?: number;
13
- regex?: string;
14
- } & BaseRule;
15
- type RuleNumber = {
16
- type: 'number';
17
- min?: number;
18
- max?: number;
19
- } & BaseRule;
20
- type RuleBoolean = {
21
- type: 'boolean';
22
- } & BaseRule;
23
- type RuleArray = {
24
- type: 'array';
25
- items: Rule;
26
- minItems?: number;
27
- maxItems?: number;
28
- } & BaseRule;
29
- type RuleObject = {
30
- type: 'object';
31
- properties: {
32
- [key: string]: Rule;
33
- };
34
- } & BaseRule;
35
- type RuleAny = {
36
- type: 'any';
37
- } & BaseRule;
38
- type Rule = RuleString | RuleNumber | RuleBoolean | RuleArray | RuleObject | RuleAny;
39
-
40
- type RouterContextT = {
41
- code?: number;
42
- [key: string]: any;
43
- };
44
- type RouteContext<T = {
45
- code?: number;
46
- }, S = any> = {
47
- query?: {
48
- [key: string]: any;
49
- };
50
- /** return body */
51
- body?: number | string | Object;
52
- /** return code */
53
- code?: number;
54
- /** return msg */
55
- message?: string;
56
- state?: S;
57
- /**
58
- * 当前路径
59
- */
60
- currentPath?: string;
61
- /**
62
- * 当前key
63
- */
64
- currentKey?: string;
65
- /**
66
- * 当前route
67
- */
68
- currentRoute?: Route;
69
- /**
70
- * 进度
71
- */
72
- progress?: [string, string][];
73
- nextQuery?: {
74
- [key: string]: any;
75
- };
76
- end?: boolean;
77
- /**
78
- * 请求 route的返回结果,包函ctx
79
- */
80
- queryRouter?: QueryRouter;
81
- error?: any;
82
- /** 请求 route的返回结果,包函ctx */
83
- call?: (message: {
84
- path: string;
85
- key?: string;
86
- payload?: any;
87
- [key: string]: any;
88
- } | {
89
- id: string;
90
- apyload?: any;
91
- [key: string]: any;
92
- }, ctx?: RouteContext & {
93
- [key: string]: any;
94
- }) => Promise<any>;
95
- /** 请求 route的返回结果,不包函ctx */
96
- queryRoute?: (message: {
97
- path: string;
98
- key?: string;
99
- payload?: any;
100
- }, ctx?: RouteContext & {
101
- [key: string]: any;
102
- }) => Promise<any>;
103
- index?: number;
104
- throw?: (code?: number | string, message?: string, tips?: string) => void;
105
- /** 是否需要序列化 */
106
- needSerialize?: boolean;
107
- } & T;
108
- type Run<T = any> = (ctx: RouteContext<T>) => Promise<typeof ctx | null | void>;
109
- type NextRoute = Pick<Route, 'id' | 'path' | 'key'>;
110
- type RouteMiddleware = {
111
- path: string;
112
- key?: string;
113
- id?: string;
114
- } | string;
115
- type RouteOpts = {
116
- path?: string;
117
- key?: string;
118
- id?: string;
119
- run?: Run;
120
- nextRoute?: NextRoute;
121
- description?: string;
122
- metadata?: {
123
- [key: string]: any;
124
- };
125
- middleware?: RouteMiddleware[];
126
- type?: 'route' | 'middleware';
127
- /**
128
- * validator: {
129
- * packageName: {
130
- * type: 'string',
131
- * required: true,
132
- * },
133
- * }
134
- */
135
- validator?: {
136
- [key: string]: Rule;
137
- };
138
- schema?: {
139
- [key: string]: Schema<any>;
140
- };
141
- isVerify?: boolean;
142
- verify?: (ctx?: RouteContext, dev?: boolean) => boolean;
143
- verifyKey?: (key: string, ctx?: RouteContext, dev?: boolean) => boolean;
144
- /**
145
- * $#$ will be used to split path and key
146
- */
147
- idUsePath?: boolean;
148
- /**
149
- * id 合并的分隔符,默认为 $#$
150
- */
151
- delimiter?: string;
152
- isDebug?: boolean;
153
- };
154
- type DefineRouteOpts = Omit<RouteOpts, 'idUsePath' | 'verify' | 'verifyKey' | 'nextRoute'>;
155
- declare const pickValue: readonly ["path", "key", "id", "description", "type", "validator", "middleware"];
156
- type RouteInfo = Pick<Route, (typeof pickValue)[number]>;
157
- declare class Route<U = {
158
- [key: string]: any;
159
- }> {
160
- /**
161
- * 一级路径
162
- */
163
- path?: string;
164
- /**
165
- * 二级路径
166
- */
167
- key?: string;
168
- id?: string;
169
- share?: boolean;
170
- run?: Run;
171
- nextRoute?: NextRoute;
172
- description?: string;
173
- metadata?: {
174
- [key: string]: any;
175
- };
176
- middleware?: RouteMiddleware[];
177
- type?: string;
178
- private _validator?;
179
- schema?: {
180
- [key: string]: Schema<any>;
181
- };
182
- data?: any;
183
- /**
184
- * 是否需要验证
185
- */
186
- isVerify?: boolean;
187
- /**
188
- * 是否开启debug,开启后会打印错误信息
189
- */
190
- isDebug?: boolean;
191
- constructor(path: string, key?: string, opts?: RouteOpts);
192
- private createSchema;
193
- /**
194
- * set validator and create schema
195
- * @param validator
196
- */
197
- set validator(validator: {
198
- [key: string]: Rule;
199
- });
200
- get validator(): {
201
- [key: string]: Rule;
202
- };
203
- /**
204
- * has code, body, message in ctx, return ctx if has error
205
- * @param ctx
206
- * @param dev
207
- * @returns
208
- */
209
- verify(ctx: RouteContext, dev?: boolean): void;
210
- /**
211
- * Need to manully call return ctx fn and configure body, code, message
212
- * @param key
213
- * @param ctx
214
- * @param dev
215
- * @returns
216
- */
217
- verifyKey(key: string, ctx: RouteContext, dev?: boolean): {
218
- message: string;
219
- path: string;
220
- key: string;
221
- error: any;
222
- } | {
223
- message: string;
224
- path: string;
225
- key: string;
226
- error?: undefined;
227
- };
228
- setValidator(validator: {
229
- [key: string]: Rule;
230
- }): this;
231
- define<T extends {
232
- [key: string]: any;
233
- } = RouterContextT>(opts: DefineRouteOpts): this;
234
- define<T extends {
235
- [key: string]: any;
236
- } = RouterContextT>(fn: Run<T & U>): this;
237
- define<T extends {
238
- [key: string]: any;
239
- } = RouterContextT>(key: string, fn: Run<T & U>): this;
240
- define<T extends {
241
- [key: string]: any;
242
- } = RouterContextT>(path: string, key: string, fn: Run<T & U>): this;
243
- addTo(router: QueryRouter | {
244
- add: (route: Route) => void;
245
- [key: string]: any;
246
- }): void;
247
- setData(data: any): this;
248
- throw(code?: number | string, message?: string, tips?: string): void;
249
- }
250
- declare class QueryRouter {
251
- routes: Route[];
252
- maxNextRoute: number;
253
- context?: RouteContext;
254
- constructor();
255
- add(route: Route): void;
256
- /**
257
- * remove route by path and key
258
- * @param route
259
- */
260
- remove(route: Route | {
261
- path: string;
262
- key?: string;
263
- }): void;
264
- /**
265
- * remove route by id
266
- * @param uniqueId
267
- */
268
- removeById(unique: string): void;
269
- /**
270
- * 执行route
271
- * @param path
272
- * @param key
273
- * @param ctx
274
- * @returns
275
- */
276
- runRoute(path: string, key: string, ctx?: RouteContext): any;
277
- /**
278
- * 第一次执行
279
- * @param message
280
- * @param ctx
281
- * @returns
282
- */
283
- parse(message: {
284
- path: string;
285
- key?: string;
286
- payload?: any;
287
- }, ctx?: RouteContext & {
288
- [key: string]: any;
289
- }): Promise<any>;
290
- /**
291
- * 返回的数据包含所有的context的请求返回的内容,可做其他处理
292
- * @param message
293
- * @param ctx
294
- * @returns
295
- */
296
- call(message: {
297
- id?: string;
298
- path?: string;
299
- key?: string;
300
- payload?: any;
301
- }, ctx?: RouteContext & {
302
- [key: string]: any;
303
- }): Promise<any>;
304
- /**
305
- * 请求 result 的数据
306
- * @param message
307
- * @param ctx
308
- * @returns
309
- */
310
- queryRoute(message: {
311
- path: string;
312
- key?: string;
313
- payload?: any;
314
- }, ctx?: RouteContext & {
315
- [key: string]: any;
316
- }): Promise<{
317
- code: any;
318
- data: any;
319
- message: any;
320
- }>;
321
- setContext(ctx: RouteContext): Promise<void>;
322
- getList(): RouteInfo[];
323
- /**
324
- * 获取handle函数, 这里会去执行parse函数
325
- */
326
- getHandle<T = any>(router: QueryRouter, wrapperFn?: HandleFn<T>, ctx?: RouteContext): (msg: {
327
- path: string;
328
- key?: string;
329
- [key: string]: any;
330
- }, handleContext?: RouteContext) => Promise<{
331
- [key: string]: any;
332
- code: string;
333
- data?: any;
334
- message?: string;
335
- } | {
336
- code: any;
337
- data: any;
338
- message: any;
339
- } | {
340
- code: number;
341
- message: any;
342
- data?: undefined;
343
- }>;
344
- exportRoutes(): Route<{
345
- [key: string]: any;
346
- }>[];
347
- importRoutes(routes: Route[]): void;
348
- importRouter(router: QueryRouter): void;
349
- throw(code?: number | string, message?: string, tips?: string): void;
350
- hasRoute(path: string, key?: string): Route<{
351
- [key: string]: any;
352
- }>;
353
- }
354
- type QueryRouterServerOpts = {
355
- handleFn?: HandleFn;
356
- context?: RouteContext;
357
- };
358
- interface HandleFn<T = any> {
359
- (msg: {
360
- path: string;
361
- [key: string]: any;
362
- }, ctx?: any): {
363
- code: string;
364
- data?: any;
365
- message?: string;
366
- [key: string]: any;
367
- };
368
- (res: RouteContext<T>): any;
369
- }
370
- /**
371
- * QueryRouterServer
372
- * @description 移除server相关的功能,只保留router相关的功能,和http.createServer不相关,独立
373
- */
374
- declare class QueryRouterServer extends QueryRouter {
375
- handle: any;
376
- constructor(opts?: QueryRouterServerOpts);
377
- setHandle(wrapperFn?: HandleFn, ctx?: RouteContext): void;
378
- use(path: string, fn: (ctx: any) => any, opts?: RouteOpts): void;
379
- addRoute(route: Route): void;
380
- Route: typeof Route;
381
- route(opts: RouteOpts): Route<Required<RouteContext>>;
382
- route(path: string, key?: string): Route<Required<RouteContext>>;
383
- route(path: string, opts?: RouteOpts): Route<Required<RouteContext>>;
384
- route(path: string, key?: string, opts?: RouteOpts): Route<Required<RouteContext>>;
385
- /**
386
- * 等于queryRoute,但是调用了handle
387
- * @param param0
388
- * @returns
389
- */
390
- run({ path, key, payload }: {
391
- path: string;
392
- key?: string;
393
- payload?: any;
394
- }): Promise<any>;
395
- }
1
+ import { RouteOpts, QueryRouterServer, RouteMiddleware, Run } from '@kevisual/router';
2
+ export { RouteOpts } from '@kevisual/router';
396
3
 
397
4
  type RouteObject = {
398
5
  [key: string]: RouteOpts;
@@ -433,32 +40,8 @@ declare class QueryUtil<T extends RouteObject = RouteObject> {
433
40
  static create<U extends Record<string, RouteOpts>>(value: U, opts?: ChainOptions): QueryUtil<U>;
434
41
  get<K extends keyof T>(key: K): RouteOpts;
435
42
  chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
436
- queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => {
437
- path?: string;
438
- key?: string;
439
- id?: string;
440
- run?: Run;
441
- nextRoute?: NextRoute;
442
- description?: string;
443
- metadata?: {
444
- [key: string]: any;
445
- };
446
- middleware?: RouteMiddleware[];
447
- type?: "route" | "middleware";
448
- validator?: {
449
- [key: string]: Rule;
450
- };
451
- schema?: {
452
- [key: string]: node_modules_zod_lib_types_js.ZodType<any>;
453
- };
454
- isVerify?: boolean;
455
- verify?: (ctx?: RouteContext, dev?: boolean) => boolean;
456
- verifyKey?: (key: string, ctx?: RouteContext, dev?: boolean) => boolean;
457
- idUsePath?: boolean;
458
- delimiter?: string;
459
- isDebug?: boolean;
460
- };
43
+ queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => RouteOpts;
461
44
  }
462
45
 
463
46
  export { QueryUtil, define, util };
464
- export type { RouteArray, RouteObject, RouteOpts };
47
+ export type { RouteArray, RouteObject };
package/dist/router.d.ts CHANGED
@@ -5,6 +5,7 @@ import https from 'node:https';
5
5
  import http2 from 'node:http2';
6
6
  import * as cookie from 'cookie';
7
7
  import { WebSocketServer, WebSocket } from 'ws';
8
+ import { RouteOpts as RouteOpts$1, QueryRouterServer as QueryRouterServer$1, RouteMiddleware as RouteMiddleware$1, Run as Run$1 } from '@kevisual/router';
8
9
 
9
10
  type BaseRule = {
10
11
  value?: any;
@@ -577,6 +578,48 @@ declare class WsServer extends WsServerBase {
577
578
  listen(): void;
578
579
  }
579
580
 
581
+ type RouteObject = {
582
+ [key: string]: RouteOpts$1;
583
+ };
584
+ declare function define<T extends Record<string, RouteOpts$1>>(value: T): {
585
+ [K in keyof T]: T[K] & RouteOpts$1;
586
+ };
587
+ type RouteArray = RouteOpts$1[];
588
+ type ChainOptions = {
589
+ app: QueryRouterServer$1;
590
+ };
591
+ declare class Chain {
592
+ object: RouteOpts$1;
593
+ app?: QueryRouterServer$1;
594
+ constructor(object: RouteOpts$1, opts?: ChainOptions);
595
+ get key(): string;
596
+ get path(): string;
597
+ setDescription(desc: string): this;
598
+ setMeta(metadata: {
599
+ [key: string]: any;
600
+ }): this;
601
+ setPath(path: string): this;
602
+ setMiddleware(middleware: RouteMiddleware$1[]): this;
603
+ setKey(key: string): this;
604
+ setId(key: string): this;
605
+ setRun(run: Run$1): this;
606
+ define(run: Run$1): this;
607
+ createRoute(): this;
608
+ }
609
+ declare const util: {
610
+ getChain: (obj: RouteOpts$1, opts?: ChainOptions) => Chain;
611
+ };
612
+ declare class QueryUtil<T extends RouteObject = RouteObject> {
613
+ routeObject: T;
614
+ app: QueryRouterServer$1;
615
+ constructor(object: T, opts?: ChainOptions);
616
+ static createFormObj<U extends RouteObject>(object: U, opts?: ChainOptions): QueryUtil<U>;
617
+ static create<U extends Record<string, RouteOpts$1>>(value: U, opts?: ChainOptions): QueryUtil<U>;
618
+ get<K extends keyof T>(key: K): RouteOpts$1;
619
+ chain<K extends keyof T>(key: K, opts?: ChainOptions): Chain;
620
+ queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => RouteOpts$1;
621
+ }
622
+
580
623
  type RouterHandle = (msg: {
581
624
  path: string;
582
625
  [key: string]: any;
@@ -647,5 +690,5 @@ declare class App<T = {}, U = AppReqRes> {
647
690
  throw(code?: number | string, message?: string, tips?: string): void;
648
691
  }
649
692
 
650
- export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, Route, Server, createSchema, handleServer };
651
- export type { RouteContext, RouteMiddleware, RouteOpts, Rule, Run };
693
+ export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, Server, createSchema, define, handleServer, util };
694
+ export type { RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, Rule, Run };
package/dist/router.js CHANGED
@@ -116,7 +116,7 @@ try {
116
116
  }
117
117
  */
118
118
 
119
- var util;
119
+ var util$1;
120
120
  (function (util) {
121
121
  util.assertEqual = (val) => val;
122
122
  function assertIs(_arg) { }
@@ -178,7 +178,7 @@ var util;
178
178
  }
179
179
  return value;
180
180
  };
181
- })(util || (util = {}));
181
+ })(util$1 || (util$1 = {}));
182
182
  var objectUtil;
183
183
  (function (objectUtil) {
184
184
  objectUtil.mergeShapes = (first, second) => {
@@ -188,7 +188,7 @@ var objectUtil;
188
188
  };
189
189
  };
190
190
  })(objectUtil || (objectUtil = {}));
191
- const ZodParsedType = util.arrayToEnum([
191
+ const ZodParsedType = util$1.arrayToEnum([
192
192
  "string",
193
193
  "nan",
194
194
  "number",
@@ -255,7 +255,7 @@ const getParsedType = (data) => {
255
255
  }
256
256
  };
257
257
 
258
- const ZodIssueCode = util.arrayToEnum([
258
+ const ZodIssueCode = util$1.arrayToEnum([
259
259
  "invalid_type",
260
260
  "invalid_literal",
261
261
  "custom",
@@ -359,7 +359,7 @@ class ZodError extends Error {
359
359
  return this.message;
360
360
  }
361
361
  get message() {
362
- return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
362
+ return JSON.stringify(this.issues, util$1.jsonStringifyReplacer, 2);
363
363
  }
364
364
  get isEmpty() {
365
365
  return this.issues.length === 0;
@@ -399,19 +399,19 @@ const errorMap = (issue, _ctx) => {
399
399
  }
400
400
  break;
401
401
  case ZodIssueCode.invalid_literal:
402
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
402
+ message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util$1.jsonStringifyReplacer)}`;
403
403
  break;
404
404
  case ZodIssueCode.unrecognized_keys:
405
- message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
405
+ message = `Unrecognized key(s) in object: ${util$1.joinValues(issue.keys, ", ")}`;
406
406
  break;
407
407
  case ZodIssueCode.invalid_union:
408
408
  message = `Invalid input`;
409
409
  break;
410
410
  case ZodIssueCode.invalid_union_discriminator:
411
- message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
411
+ message = `Invalid discriminator value. Expected ${util$1.joinValues(issue.options)}`;
412
412
  break;
413
413
  case ZodIssueCode.invalid_enum_value:
414
- message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
414
+ message = `Invalid enum value. Expected ${util$1.joinValues(issue.options)}, received '${issue.received}'`;
415
415
  break;
416
416
  case ZodIssueCode.invalid_arguments:
417
417
  message = `Invalid function arguments`;
@@ -437,7 +437,7 @@ const errorMap = (issue, _ctx) => {
437
437
  message = `Invalid input: must end with "${issue.validation.endsWith}"`;
438
438
  }
439
439
  else {
440
- util.assertNever(issue.validation);
440
+ util$1.assertNever(issue.validation);
441
441
  }
442
442
  }
443
443
  else if (issue.validation !== "regex") {
@@ -507,7 +507,7 @@ const errorMap = (issue, _ctx) => {
507
507
  break;
508
508
  default:
509
509
  message = _ctx.defaultError;
510
- util.assertNever(issue);
510
+ util$1.assertNever(issue);
511
511
  }
512
512
  return { message };
513
513
  };
@@ -1466,7 +1466,7 @@ class ZodString extends ZodType {
1466
1466
  }
1467
1467
  }
1468
1468
  else {
1469
- util.assertNever(check);
1469
+ util$1.assertNever(check);
1470
1470
  }
1471
1471
  }
1472
1472
  return { status: status.value, value: input.data };
@@ -1753,7 +1753,7 @@ class ZodNumber extends ZodType {
1753
1753
  const status = new ParseStatus();
1754
1754
  for (const check of this._def.checks) {
1755
1755
  if (check.kind === "int") {
1756
- if (!util.isInteger(input.data)) {
1756
+ if (!util$1.isInteger(input.data)) {
1757
1757
  ctx = this._getOrReturnCtx(input, ctx);
1758
1758
  addIssueToContext(ctx, {
1759
1759
  code: ZodIssueCode.invalid_type,
@@ -1820,7 +1820,7 @@ class ZodNumber extends ZodType {
1820
1820
  }
1821
1821
  }
1822
1822
  else {
1823
- util.assertNever(check);
1823
+ util$1.assertNever(check);
1824
1824
  }
1825
1825
  }
1826
1826
  return { status: status.value, value: input.data };
@@ -1943,7 +1943,7 @@ class ZodNumber extends ZodType {
1943
1943
  }
1944
1944
  get isInt() {
1945
1945
  return !!this._def.checks.find((ch) => ch.kind === "int" ||
1946
- (ch.kind === "multipleOf" && util.isInteger(ch.value)));
1946
+ (ch.kind === "multipleOf" && util$1.isInteger(ch.value)));
1947
1947
  }
1948
1948
  get isFinite() {
1949
1949
  let max = null, min = null;
@@ -2039,7 +2039,7 @@ class ZodBigInt extends ZodType {
2039
2039
  }
2040
2040
  }
2041
2041
  else {
2042
- util.assertNever(check);
2042
+ util$1.assertNever(check);
2043
2043
  }
2044
2044
  }
2045
2045
  return { status: status.value, value: input.data };
@@ -2233,7 +2233,7 @@ class ZodDate extends ZodType {
2233
2233
  }
2234
2234
  }
2235
2235
  else {
2236
- util.assertNever(check);
2236
+ util$1.assertNever(check);
2237
2237
  }
2238
2238
  }
2239
2239
  return {
@@ -2606,7 +2606,7 @@ class ZodObject extends ZodType {
2606
2606
  if (this._cached !== null)
2607
2607
  return this._cached;
2608
2608
  const shape = this._def.shape();
2609
- const keys = util.objectKeys(shape);
2609
+ const keys = util$1.objectKeys(shape);
2610
2610
  return (this._cached = { shape, keys });
2611
2611
  }
2612
2612
  _parse(input) {
@@ -2848,7 +2848,7 @@ class ZodObject extends ZodType {
2848
2848
  }
2849
2849
  pick(mask) {
2850
2850
  const shape = {};
2851
- util.objectKeys(mask).forEach((key) => {
2851
+ util$1.objectKeys(mask).forEach((key) => {
2852
2852
  if (mask[key] && this.shape[key]) {
2853
2853
  shape[key] = this.shape[key];
2854
2854
  }
@@ -2860,7 +2860,7 @@ class ZodObject extends ZodType {
2860
2860
  }
2861
2861
  omit(mask) {
2862
2862
  const shape = {};
2863
- util.objectKeys(this.shape).forEach((key) => {
2863
+ util$1.objectKeys(this.shape).forEach((key) => {
2864
2864
  if (!mask[key]) {
2865
2865
  shape[key] = this.shape[key];
2866
2866
  }
@@ -2878,7 +2878,7 @@ class ZodObject extends ZodType {
2878
2878
  }
2879
2879
  partial(mask) {
2880
2880
  const newShape = {};
2881
- util.objectKeys(this.shape).forEach((key) => {
2881
+ util$1.objectKeys(this.shape).forEach((key) => {
2882
2882
  const fieldSchema = this.shape[key];
2883
2883
  if (mask && !mask[key]) {
2884
2884
  newShape[key] = fieldSchema;
@@ -2894,7 +2894,7 @@ class ZodObject extends ZodType {
2894
2894
  }
2895
2895
  required(mask) {
2896
2896
  const newShape = {};
2897
- util.objectKeys(this.shape).forEach((key) => {
2897
+ util$1.objectKeys(this.shape).forEach((key) => {
2898
2898
  if (mask && !mask[key]) {
2899
2899
  newShape[key] = this.shape[key];
2900
2900
  }
@@ -2913,7 +2913,7 @@ class ZodObject extends ZodType {
2913
2913
  });
2914
2914
  }
2915
2915
  keyof() {
2916
- return createZodEnum(util.objectKeys(this.shape));
2916
+ return createZodEnum(util$1.objectKeys(this.shape));
2917
2917
  }
2918
2918
  }
2919
2919
  ZodObject.create = (shape, params) => {
@@ -3061,7 +3061,7 @@ const getDiscriminator = (type) => {
3061
3061
  }
3062
3062
  else if (type instanceof ZodNativeEnum) {
3063
3063
  // eslint-disable-next-line ban/ban
3064
- return util.objectValues(type.enum);
3064
+ return util$1.objectValues(type.enum);
3065
3065
  }
3066
3066
  else if (type instanceof ZodDefault) {
3067
3067
  return getDiscriminator(type._def.innerType);
@@ -3177,8 +3177,8 @@ function mergeValues(a, b) {
3177
3177
  return { valid: true, data: a };
3178
3178
  }
3179
3179
  else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
3180
- const bKeys = util.objectKeys(b);
3181
- const sharedKeys = util
3180
+ const bKeys = util$1.objectKeys(b);
3181
+ const sharedKeys = util$1
3182
3182
  .objectKeys(a)
3183
3183
  .filter((key) => bKeys.indexOf(key) !== -1);
3184
3184
  const newObj = { ...a, ...b };
@@ -3733,7 +3733,7 @@ class ZodEnum extends ZodType {
3733
3733
  const ctx = this._getOrReturnCtx(input);
3734
3734
  const expectedValues = this._def.values;
3735
3735
  addIssueToContext(ctx, {
3736
- expected: util.joinValues(expectedValues),
3736
+ expected: util$1.joinValues(expectedValues),
3737
3737
  received: ctx.parsedType,
3738
3738
  code: ZodIssueCode.invalid_type,
3739
3739
  });
@@ -3799,23 +3799,23 @@ class ZodNativeEnum extends ZodType {
3799
3799
  _ZodNativeEnum_cache.set(this, void 0);
3800
3800
  }
3801
3801
  _parse(input) {
3802
- const nativeEnumValues = util.getValidEnumValues(this._def.values);
3802
+ const nativeEnumValues = util$1.getValidEnumValues(this._def.values);
3803
3803
  const ctx = this._getOrReturnCtx(input);
3804
3804
  if (ctx.parsedType !== ZodParsedType.string &&
3805
3805
  ctx.parsedType !== ZodParsedType.number) {
3806
- const expectedValues = util.objectValues(nativeEnumValues);
3806
+ const expectedValues = util$1.objectValues(nativeEnumValues);
3807
3807
  addIssueToContext(ctx, {
3808
- expected: util.joinValues(expectedValues),
3808
+ expected: util$1.joinValues(expectedValues),
3809
3809
  received: ctx.parsedType,
3810
3810
  code: ZodIssueCode.invalid_type,
3811
3811
  });
3812
3812
  return INVALID;
3813
3813
  }
3814
3814
  if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache)) {
3815
- __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util.getValidEnumValues(this._def.values)));
3815
+ __classPrivateFieldSet(this, _ZodNativeEnum_cache, new Set(util$1.getValidEnumValues(this._def.values)));
3816
3816
  }
3817
3817
  if (!__classPrivateFieldGet(this, _ZodNativeEnum_cache).has(input.data)) {
3818
- const expectedValues = util.objectValues(nativeEnumValues);
3818
+ const expectedValues = util$1.objectValues(nativeEnumValues);
3819
3819
  addIssueToContext(ctx, {
3820
3820
  received: ctx.data,
3821
3821
  code: ZodIssueCode.invalid_enum_value,
@@ -3998,7 +3998,7 @@ class ZodEffects extends ZodType {
3998
3998
  });
3999
3999
  }
4000
4000
  }
4001
- util.assertNever(effect);
4001
+ util$1.assertNever(effect);
4002
4002
  }
4003
4003
  }
4004
4004
  ZodEffects.create = (schema, effect, params) => {
@@ -4422,7 +4422,7 @@ var z = /*#__PURE__*/Object.freeze({
4422
4422
  isDirty: isDirty,
4423
4423
  isValid: isValid,
4424
4424
  isAsync: isAsync,
4425
- get util () { return util; },
4425
+ get util () { return util$1; },
4426
4426
  get objectUtil () { return objectUtil; },
4427
4427
  ZodParsedType: ZodParsedType,
4428
4428
  getParsedType: getParsedType,
@@ -11938,6 +11938,97 @@ class WsServer extends WsServerBase {
11938
11938
  }
11939
11939
  }
11940
11940
 
11941
+ function define(value) {
11942
+ return value;
11943
+ }
11944
+ class Chain {
11945
+ object;
11946
+ app;
11947
+ constructor(object, opts) {
11948
+ this.object = object;
11949
+ this.app = opts?.app;
11950
+ }
11951
+ get key() {
11952
+ return this.object.key;
11953
+ }
11954
+ get path() {
11955
+ return this.object.path;
11956
+ }
11957
+ setDescription(desc) {
11958
+ this.object.description = desc;
11959
+ return this;
11960
+ }
11961
+ setMeta(metadata) {
11962
+ this.object.metadata = metadata;
11963
+ return this;
11964
+ }
11965
+ setPath(path) {
11966
+ this.object.path = path;
11967
+ return this;
11968
+ }
11969
+ setMiddleware(middleware) {
11970
+ this.object.middleware = middleware;
11971
+ return this;
11972
+ }
11973
+ setKey(key) {
11974
+ this.object.key = key;
11975
+ return this;
11976
+ }
11977
+ setId(key) {
11978
+ this.object.id = key;
11979
+ return this;
11980
+ }
11981
+ setRun(run) {
11982
+ this.object.run = run;
11983
+ return this;
11984
+ }
11985
+ define(run) {
11986
+ this.object.run = run;
11987
+ return this;
11988
+ }
11989
+ createRoute() {
11990
+ this.app.route(this.object).addTo(this.app);
11991
+ return this;
11992
+ }
11993
+ }
11994
+ const util = {
11995
+ getChain: (obj, opts) => {
11996
+ return new Chain(obj, opts);
11997
+ },
11998
+ };
11999
+ class QueryUtil {
12000
+ routeObject;
12001
+ app;
12002
+ constructor(object, opts) {
12003
+ this.routeObject = object;
12004
+ this.app = opts?.app;
12005
+ }
12006
+ static createFormObj(object, opts) {
12007
+ return new QueryUtil(object, opts);
12008
+ }
12009
+ static create(value, opts) {
12010
+ const obj = value;
12011
+ return new QueryUtil(obj, opts);
12012
+ }
12013
+ get(key) {
12014
+ return this.routeObject[key];
12015
+ }
12016
+ chain(key, opts) {
12017
+ const obj = this.routeObject[key];
12018
+ let newOpts = { app: this.app, ...opts };
12019
+ return new Chain(obj, newOpts);
12020
+ }
12021
+ queryChain(key) {
12022
+ const value = this.routeObject[key];
12023
+ return (queryData) => {
12024
+ return {
12025
+ ...value,
12026
+ ...queryData,
12027
+ };
12028
+ };
12029
+ }
12030
+ }
12031
+
11941
12032
  /**
11942
12033
  * 封装了 Router 和 Server 的 App 模块,处理http的请求和响应,内置了 Cookie 和 Token 和 res 的处理
11943
12034
  */
@@ -12010,4 +12101,4 @@ class App {
12010
12101
  }
12011
12102
  }
12012
12103
 
12013
- export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, Route, ZodType as Schema, Server, createSchema, handleServer };
12104
+ export { App, Connect, CustomError, QueryConnect, QueryRouter, QueryRouterServer, QueryUtil, Route, ZodType as Schema, Server, createSchema, define, handleServer, util };
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.16",
4
+ "version": "0.0.17",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
package/src/browser.ts CHANGED
@@ -9,3 +9,5 @@ export type { Run } from './route.ts';
9
9
  export { CustomError } from './result/error.ts';
10
10
 
11
11
  export * from './server/parse-body.ts';
12
+
13
+ export * from './router-define.ts';
package/src/index.ts CHANGED
@@ -14,3 +14,5 @@ export { CustomError } from './result/error.ts';
14
14
  export { Rule, Schema, createSchema } from './validator/index.ts';
15
15
 
16
16
  export { App } from './app.ts';
17
+
18
+ export * from './router-define.ts';
@@ -1,5 +1,4 @@
1
- // import type { QueryRouterServer, Route, RouteOpts, Run } from '@kevisual/router';
2
- import type { QueryRouterServer, RouteOpts, Run, RouteMiddleware } from './index.ts';
1
+ import type { QueryRouterServer, RouteOpts, Run, RouteMiddleware } from '@kevisual/router';
3
2
 
4
3
  // export type RouteObject<T extends readonly string[]> = {
5
4
  // [K in T[number]]: RouteOpts;
@@ -99,8 +98,8 @@ export class QueryUtil<T extends RouteObject = RouteObject> {
99
98
  let newOpts = { app: this.app, ...opts };
100
99
  return new Chain(obj, newOpts);
101
100
  }
102
- queryChain<K extends keyof T>(key: K) {
103
- const value = this.routeObject[key] as RouteOpts;
101
+ queryChain<K extends keyof T>(key: K): (queryData?: Record<string, any>) => RouteOpts {
102
+ const value = this.routeObject[key];
104
103
  return (queryData?: Record<string, any>) => {
105
104
  return {
106
105
  ...value,