@kevisual/router 0.0.70 → 0.0.71

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.
@@ -32,6 +32,9 @@ type RouteContext<T = {
32
32
  query?: {
33
33
  [key: string]: any;
34
34
  };
35
+ args?: {
36
+ [key: string]: any;
37
+ };
35
38
  /** return body */
36
39
  body?: number | string | Object;
37
40
  forward?: (response: {
package/dist/opencode.js CHANGED
@@ -1,3 +1,5 @@
1
+ import 'es-toolkit';
2
+
1
3
  // src/utils/path-key.ts
2
4
 
3
5
  // ../../node_modules/.pnpm/@kevisual+load@0.0.6/node_modules/@kevisual/load/dist/load.js
@@ -47,6 +47,9 @@ type RouteContext<T = {
47
47
  query?: {
48
48
  [key: string]: any;
49
49
  };
50
+ args?: {
51
+ [key: string]: any;
52
+ };
50
53
  /** return body */
51
54
  body?: number | string | Object;
52
55
  forward?: (response: {
@@ -1,3 +1,5 @@
1
+ import { merge as merge$1 } from 'es-toolkit';
2
+
1
3
  const urlAlphabet =
2
4
  'useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict';
3
5
 
@@ -453,52 +455,6 @@ function requireEventemitter3 () {
453
455
  var eventemitter3Exports = requireEventemitter3();
454
456
  var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
455
457
 
456
- function isPlainObject$1(value) {
457
- if (!value || typeof value !== 'object') {
458
- return false;
459
- }
460
- const proto = Object.getPrototypeOf(value);
461
- const hasObjectPrototype = proto === null ||
462
- proto === Object.prototype ||
463
- Object.getPrototypeOf(proto) === null;
464
- if (!hasObjectPrototype) {
465
- return false;
466
- }
467
- return Object.prototype.toString.call(value) === '[object Object]';
468
- }
469
-
470
- function isUnsafeProperty(key) {
471
- return key === '__proto__';
472
- }
473
-
474
- function merge$1(target, source) {
475
- const sourceKeys = Object.keys(source);
476
- for (let i = 0; i < sourceKeys.length; i++) {
477
- const key = sourceKeys[i];
478
- if (isUnsafeProperty(key)) {
479
- continue;
480
- }
481
- const sourceValue = source[key];
482
- const targetValue = target[key];
483
- if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) {
484
- target[key] = merge$1(targetValue, sourceValue);
485
- }
486
- else if (Array.isArray(sourceValue)) {
487
- target[key] = merge$1([], sourceValue);
488
- }
489
- else if (isPlainObject$1(sourceValue)) {
490
- target[key] = merge$1({}, sourceValue);
491
- }
492
- else if (targetValue === undefined || sourceValue !== undefined) {
493
- target[key] = sourceValue;
494
- }
495
- }
496
- return target;
497
- }
498
- function isMergeableValue(value) {
499
- return isPlainObject$1(value) || Array.isArray(value);
500
- }
501
-
502
458
  class MockProcess {
503
459
  emitter;
504
460
  process;
@@ -15256,7 +15212,6 @@ class QueryRouter {
15256
15212
  console.error('=====debug====:middlerware error');
15257
15213
  console.error('=====debug====:', e);
15258
15214
  console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
15259
- console.error('=====debug====:', e.message);
15260
15215
  }
15261
15216
  if (e instanceof CustomError || e?.code) {
15262
15217
  ctx.code = e.code;
@@ -15264,8 +15219,9 @@ class QueryRouter {
15264
15219
  ctx.body = null;
15265
15220
  }
15266
15221
  else {
15267
- console.error(`fn:${route.path}-${route.key}:${route.id}`);
15268
- console.error(`middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
15222
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
15223
+ console.error(`[router error] middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
15224
+ console.error(e);
15269
15225
  ctx.code = 500;
15270
15226
  ctx.message = 'Internal Server Error';
15271
15227
  ctx.body = null;
@@ -15284,15 +15240,17 @@ class QueryRouter {
15284
15240
  }
15285
15241
  catch (e) {
15286
15242
  if (route?.isDebug) {
15287
- console.error('=====debug====:', 'router run error:', e.message);
15243
+ console.error('=====debug====:route error');
15244
+ console.error('=====debug====:', e);
15245
+ console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
15288
15246
  }
15289
15247
  if (e instanceof CustomError) {
15290
15248
  ctx.code = e.code;
15291
15249
  ctx.message = e.message;
15292
15250
  }
15293
15251
  else {
15294
- console.error(`[error]fn:${route.path}-${route.key}:${route.id}`);
15295
- console.error('error', e.message);
15252
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
15253
+ console.error(`[router error] error`, e);
15296
15254
  ctx.code = 500;
15297
15255
  ctx.message = 'Internal Server Error';
15298
15256
  }
@@ -15323,6 +15281,7 @@ class QueryRouter {
15323
15281
  return ctx;
15324
15282
  }
15325
15283
  ctx.query = { ...ctx.query, ...ctx.nextQuery };
15284
+ ctx.args = ctx.query;
15326
15285
  ctx.nextQuery = {};
15327
15286
  return await this.runRoute(path, key, ctx);
15328
15287
  }
@@ -15352,6 +15311,7 @@ class QueryRouter {
15352
15311
  const { path, key = '', payload = {}, ...query } = message;
15353
15312
  ctx = ctx || {};
15354
15313
  ctx.query = { ...ctx.query, ...query, ...payload };
15314
+ ctx.args = ctx.query;
15355
15315
  ctx.state = { ...ctx?.state };
15356
15316
  ctx.throw = this.throw;
15357
15317
  ctx.app = this;
package/dist/router.d.ts CHANGED
@@ -53,6 +53,9 @@ type RouteContext<T = {
53
53
  query?: {
54
54
  [key: string]: any;
55
55
  };
56
+ args?: {
57
+ [key: string]: any;
58
+ };
56
59
  /** return body */
57
60
  body?: number | string | Object;
58
61
  forward?: (response: {
package/dist/router.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import require$$1, { webcrypto } from 'node:crypto';
2
+ import { merge as merge$1 } from 'es-toolkit';
2
3
  import require$$2 from 'node:http';
3
4
  import require$$1$1 from 'node:https';
4
5
  import http2 from 'node:http2';
@@ -477,52 +478,6 @@ function requireEventemitter3 () {
477
478
  var eventemitter3Exports = requireEventemitter3();
478
479
  var EventEmitter = /*@__PURE__*/getDefaultExportFromCjs(eventemitter3Exports);
479
480
 
480
- function isPlainObject$1(value) {
481
- if (!value || typeof value !== 'object') {
482
- return false;
483
- }
484
- const proto = Object.getPrototypeOf(value);
485
- const hasObjectPrototype = proto === null ||
486
- proto === Object.prototype ||
487
- Object.getPrototypeOf(proto) === null;
488
- if (!hasObjectPrototype) {
489
- return false;
490
- }
491
- return Object.prototype.toString.call(value) === '[object Object]';
492
- }
493
-
494
- function isUnsafeProperty(key) {
495
- return key === '__proto__';
496
- }
497
-
498
- function merge$1(target, source) {
499
- const sourceKeys = Object.keys(source);
500
- for (let i = 0; i < sourceKeys.length; i++) {
501
- const key = sourceKeys[i];
502
- if (isUnsafeProperty(key)) {
503
- continue;
504
- }
505
- const sourceValue = source[key];
506
- const targetValue = target[key];
507
- if (isMergeableValue(sourceValue) && isMergeableValue(targetValue)) {
508
- target[key] = merge$1(targetValue, sourceValue);
509
- }
510
- else if (Array.isArray(sourceValue)) {
511
- target[key] = merge$1([], sourceValue);
512
- }
513
- else if (isPlainObject$1(sourceValue)) {
514
- target[key] = merge$1({}, sourceValue);
515
- }
516
- else if (targetValue === undefined || sourceValue !== undefined) {
517
- target[key] = sourceValue;
518
- }
519
- }
520
- return target;
521
- }
522
- function isMergeableValue(value) {
523
- return isPlainObject$1(value) || Array.isArray(value);
524
- }
525
-
526
481
  class MockProcess {
527
482
  emitter;
528
483
  process;
@@ -15280,7 +15235,6 @@ class QueryRouter {
15280
15235
  console.error('=====debug====:middlerware error');
15281
15236
  console.error('=====debug====:', e);
15282
15237
  console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
15283
- console.error('=====debug====:', e.message);
15284
15238
  }
15285
15239
  if (e instanceof CustomError || e?.code) {
15286
15240
  ctx.code = e.code;
@@ -15288,8 +15242,9 @@ class QueryRouter {
15288
15242
  ctx.body = null;
15289
15243
  }
15290
15244
  else {
15291
- console.error(`fn:${route.path}-${route.key}:${route.id}`);
15292
- console.error(`middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
15245
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
15246
+ console.error(`[router error] middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
15247
+ console.error(e);
15293
15248
  ctx.code = 500;
15294
15249
  ctx.message = 'Internal Server Error';
15295
15250
  ctx.body = null;
@@ -15308,15 +15263,17 @@ class QueryRouter {
15308
15263
  }
15309
15264
  catch (e) {
15310
15265
  if (route?.isDebug) {
15311
- console.error('=====debug====:', 'router run error:', e.message);
15266
+ console.error('=====debug====:route error');
15267
+ console.error('=====debug====:', e);
15268
+ console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
15312
15269
  }
15313
15270
  if (e instanceof CustomError) {
15314
15271
  ctx.code = e.code;
15315
15272
  ctx.message = e.message;
15316
15273
  }
15317
15274
  else {
15318
- console.error(`[error]fn:${route.path}-${route.key}:${route.id}`);
15319
- console.error('error', e.message);
15275
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
15276
+ console.error(`[router error] error`, e);
15320
15277
  ctx.code = 500;
15321
15278
  ctx.message = 'Internal Server Error';
15322
15279
  }
@@ -15347,6 +15304,7 @@ class QueryRouter {
15347
15304
  return ctx;
15348
15305
  }
15349
15306
  ctx.query = { ...ctx.query, ...ctx.nextQuery };
15307
+ ctx.args = ctx.query;
15350
15308
  ctx.nextQuery = {};
15351
15309
  return await this.runRoute(path, key, ctx);
15352
15310
  }
@@ -15376,6 +15334,7 @@ class QueryRouter {
15376
15334
  const { path, key = '', payload = {}, ...query } = message;
15377
15335
  ctx = ctx || {};
15378
15336
  ctx.query = { ...ctx.query, ...query, ...payload };
15337
+ ctx.args = ctx.query;
15379
15338
  ctx.state = { ...ctx?.state };
15380
15339
  ctx.throw = this.throw;
15381
15340
  ctx.app = this;
package/dist/ws.d.ts CHANGED
@@ -79,6 +79,9 @@ type RouteContext<T = {
79
79
  query?: {
80
80
  [key: string]: any;
81
81
  };
82
+ args?: {
83
+ [key: string]: any;
84
+ };
82
85
  /** return body */
83
86
  body?: number | string | Object;
84
87
  forward?: (response: {
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.70",
4
+ "version": "0.0.71",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
package/src/route.ts CHANGED
@@ -3,7 +3,6 @@ import { CustomError } from './result/error.ts';
3
3
  import { pick } from './utils/pick.ts';
4
4
  import { listenProcess, MockProcess } from './utils/listen-process.ts';
5
5
  import { z } from 'zod';
6
- import { filter } from '@kevisual/js-filter'
7
6
 
8
7
  export type RouterContextT = { code?: number;[key: string]: any };
9
8
  export type RouteContext<T = { code?: number }, S = any> = {
@@ -14,6 +13,7 @@ export type RouteContext<T = { code?: number }, S = any> = {
14
13
  appId?: string;
15
14
  // run first
16
15
  query?: { [key: string]: any };
16
+ args?: { [key: string]: any };
17
17
  // response body
18
18
  /** return body */
19
19
  body?: number | string | Object;
@@ -405,15 +405,15 @@ export class QueryRouter {
405
405
  console.error('=====debug====:middlerware error');
406
406
  console.error('=====debug====:', e);
407
407
  console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
408
- console.error('=====debug====:', e.message);
409
408
  }
410
409
  if (e instanceof CustomError || e?.code) {
411
410
  ctx.code = e.code;
412
411
  ctx.message = e.message;
413
412
  ctx.body = null;
414
413
  } else {
415
- console.error(`fn:${route.path}-${route.key}:${route.id}`);
416
- console.error(`middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
414
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
415
+ console.error(`[router error] middleware:${middleware.path}-${middleware.key}:${middleware.id}`);
416
+ console.error(e)
417
417
  ctx.code = 500;
418
418
  ctx.message = 'Internal Server Error';
419
419
  ctx.body = null;
@@ -432,14 +432,16 @@ export class QueryRouter {
432
432
  await route.run(ctx as Required<RouteContext>);
433
433
  } catch (e) {
434
434
  if (route?.isDebug) {
435
- console.error('=====debug====:', 'router run error:', e.message);
435
+ console.error('=====debug====:route error');
436
+ console.error('=====debug====:', e);
437
+ console.error('=====debug====:[path:key]:', `${route.path}-${route.key}`);
436
438
  }
437
439
  if (e instanceof CustomError) {
438
440
  ctx.code = e.code;
439
441
  ctx.message = e.message;
440
442
  } else {
441
- console.error(`[error]fn:${route.path}-${route.key}:${route.id}`);
442
- console.error('error', e.message);
443
+ console.error(`[router error] fn:${route.path}-${route.key}:${route.id}`);
444
+ console.error(`[router error] error`, e);
443
445
  ctx.code = 500;
444
446
  ctx.message = 'Internal Server Error';
445
447
  }
@@ -469,6 +471,7 @@ export class QueryRouter {
469
471
  return ctx;
470
472
  }
471
473
  ctx.query = { ...ctx.query, ...ctx.nextQuery };
474
+ ctx.args = ctx.query;
472
475
  ctx.nextQuery = {};
473
476
  return await this.runRoute(path, key, ctx);
474
477
  }
@@ -496,6 +499,7 @@ export class QueryRouter {
496
499
  const { path, key = '', payload = {}, ...query } = message;
497
500
  ctx = ctx || {};
498
501
  ctx.query = { ...ctx.query, ...query, ...payload };
502
+ ctx.args = ctx.query;
499
503
  ctx.state = { ...ctx?.state };
500
504
  ctx.throw = this.throw;
501
505
  ctx.app = this;