@kevisual/router 0.0.32 → 0.0.34

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/router.js CHANGED
@@ -119,21 +119,30 @@ try {
119
119
  /** A special constant with type `never` */
120
120
  function $constructor(name, initializer, params) {
121
121
  function init(inst, def) {
122
- var _a;
123
- Object.defineProperty(inst, "_zod", {
124
- value: inst._zod ?? {},
125
- enumerable: false,
126
- });
127
- (_a = inst._zod).traits ?? (_a.traits = new Set());
122
+ if (!inst._zod) {
123
+ Object.defineProperty(inst, "_zod", {
124
+ value: {
125
+ def,
126
+ constr: _,
127
+ traits: new Set(),
128
+ },
129
+ enumerable: false,
130
+ });
131
+ }
132
+ if (inst._zod.traits.has(name)) {
133
+ return;
134
+ }
128
135
  inst._zod.traits.add(name);
129
136
  initializer(inst, def);
130
137
  // support prototype modifications
131
- for (const k in _.prototype) {
132
- if (!(k in inst))
133
- Object.defineProperty(inst, k, { value: _.prototype[k].bind(inst) });
138
+ const proto = _.prototype;
139
+ const keys = Object.keys(proto);
140
+ for (let i = 0; i < keys.length; i++) {
141
+ const k = keys[i];
142
+ if (!(k in inst)) {
143
+ inst[k] = proto[k].bind(inst);
144
+ }
134
145
  }
135
- inst._zod.constr = _;
136
- inst._zod.def = def;
137
146
  }
138
147
  // doesn't work if Parent has a constructor with arguments
139
148
  const Parent = params?.Parent ?? Object;
@@ -268,6 +277,14 @@ function mergeDefs(...defs) {
268
277
  function esc(str) {
269
278
  return JSON.stringify(str);
270
279
  }
280
+ function slugify(input) {
281
+ return input
282
+ .toLowerCase()
283
+ .trim()
284
+ .replace(/[^\w\s-]/g, "")
285
+ .replace(/[\s_-]+/g, "-")
286
+ .replace(/^-+|-+$/g, "");
287
+ }
271
288
  const captureStackTrace = ("captureStackTrace" in Error ? Error.captureStackTrace : (..._args) => { });
272
289
  function isObject$1(data) {
273
290
  return typeof data === "object" && data !== null && !Array.isArray(data);
@@ -293,6 +310,8 @@ function isPlainObject(o) {
293
310
  const ctor = o.constructor;
294
311
  if (ctor === undefined)
295
312
  return true;
313
+ if (typeof ctor !== "function")
314
+ return true;
296
315
  // modified prototype
297
316
  const prot = ctor.prototype;
298
317
  if (isObject$1(prot) === false)
@@ -756,9 +775,6 @@ const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?:
756
775
  // https://stackoverflow.com/questions/7860392/determine-if-string-is-in-base64-using-javascript
757
776
  const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
758
777
  const base64url = /^[A-Za-z0-9_-]*$/;
759
- // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
760
- // export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
761
- const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
762
778
  // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
763
779
  const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
764
780
  // const dateSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
@@ -1249,7 +1265,7 @@ class Doc {
1249
1265
  const version = {
1250
1266
  major: 4,
1251
1267
  minor: 1,
1252
- patch: 12,
1268
+ patch: 13,
1253
1269
  };
1254
1270
 
1255
1271
  const $ZodType = /*@__PURE__*/ $constructor("$ZodType", (inst, def) => {
@@ -1452,7 +1468,7 @@ const $ZodURL = /*@__PURE__*/ $constructor("$ZodURL", (inst, def) => {
1452
1468
  code: "invalid_format",
1453
1469
  format: "url",
1454
1470
  note: "Invalid hostname",
1455
- pattern: hostname.source,
1471
+ pattern: def.hostname.source,
1456
1472
  input: payload.value,
1457
1473
  inst,
1458
1474
  continue: !def.abort,
@@ -1542,18 +1558,12 @@ const $ZodISODuration = /*@__PURE__*/ $constructor("$ZodISODuration", (inst, def
1542
1558
  const $ZodIPv4 = /*@__PURE__*/ $constructor("$ZodIPv4", (inst, def) => {
1543
1559
  def.pattern ?? (def.pattern = ipv4);
1544
1560
  $ZodStringFormat.init(inst, def);
1545
- inst._zod.onattach.push((inst) => {
1546
- const bag = inst._zod.bag;
1547
- bag.format = `ipv4`;
1548
- });
1561
+ inst._zod.bag.format = `ipv4`;
1549
1562
  });
1550
1563
  const $ZodIPv6 = /*@__PURE__*/ $constructor("$ZodIPv6", (inst, def) => {
1551
1564
  def.pattern ?? (def.pattern = ipv6);
1552
1565
  $ZodStringFormat.init(inst, def);
1553
- inst._zod.onattach.push((inst) => {
1554
- const bag = inst._zod.bag;
1555
- bag.format = `ipv6`;
1556
- });
1566
+ inst._zod.bag.format = `ipv6`;
1557
1567
  inst._zod.check = (payload) => {
1558
1568
  try {
1559
1569
  // @ts-ignore
@@ -1623,9 +1633,7 @@ function isValidBase64(data) {
1623
1633
  const $ZodBase64 = /*@__PURE__*/ $constructor("$ZodBase64", (inst, def) => {
1624
1634
  def.pattern ?? (def.pattern = base64);
1625
1635
  $ZodStringFormat.init(inst, def);
1626
- inst._zod.onattach.push((inst) => {
1627
- inst._zod.bag.contentEncoding = "base64";
1628
- });
1636
+ inst._zod.bag.contentEncoding = "base64";
1629
1637
  inst._zod.check = (payload) => {
1630
1638
  if (isValidBase64(payload.value))
1631
1639
  return;
@@ -1649,9 +1657,7 @@ function isValidBase64URL(data) {
1649
1657
  const $ZodBase64URL = /*@__PURE__*/ $constructor("$ZodBase64URL", (inst, def) => {
1650
1658
  def.pattern ?? (def.pattern = base64url);
1651
1659
  $ZodStringFormat.init(inst, def);
1652
- inst._zod.onattach.push((inst) => {
1653
- inst._zod.bag.contentEncoding = "base64url";
1654
- });
1660
+ inst._zod.bag.contentEncoding = "base64url";
1655
1661
  inst._zod.check = (payload) => {
1656
1662
  if (isValidBase64URL(payload.value))
1657
1663
  return;
@@ -1735,9 +1741,9 @@ const $ZodNumber = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
1735
1741
  return payload;
1736
1742
  };
1737
1743
  });
1738
- const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumber", (inst, def) => {
1744
+ const $ZodNumberFormat = /*@__PURE__*/ $constructor("$ZodNumberFormat", (inst, def) => {
1739
1745
  $ZodCheckNumberFormat.init(inst, def);
1740
- $ZodNumber.init(inst, def); // no format checksp
1746
+ $ZodNumber.init(inst, def); // no format checks
1741
1747
  });
1742
1748
  const $ZodBoolean = /*@__PURE__*/ $constructor("$ZodBoolean", (inst, def) => {
1743
1749
  $ZodType.init(inst, def);
@@ -1855,7 +1861,7 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
1855
1861
  const keySet = def.keySet;
1856
1862
  const _catchall = def.catchall._zod;
1857
1863
  const t = _catchall.def.type;
1858
- for (const key of Object.keys(input)) {
1864
+ for (const key in input) {
1859
1865
  if (keySet.has(key))
1860
1866
  continue;
1861
1867
  if (t === "never") {
@@ -2409,8 +2415,8 @@ const $ZodReadonly = /*@__PURE__*/ $constructor("$ZodReadonly", (inst, def) => {
2409
2415
  $ZodType.init(inst, def);
2410
2416
  defineLazy(inst._zod, "propValues", () => def.innerType._zod.propValues);
2411
2417
  defineLazy(inst._zod, "values", () => def.innerType._zod.values);
2412
- defineLazy(inst._zod, "optin", () => def.innerType._zod.optin);
2413
- defineLazy(inst._zod, "optout", () => def.innerType._zod.optout);
2418
+ defineLazy(inst._zod, "optin", () => def.innerType?._zod?.optin);
2419
+ defineLazy(inst._zod, "optout", () => def.innerType?._zod?.optout);
2414
2420
  inst._zod.parse = (payload, ctx) => {
2415
2421
  if (ctx.direction === "backward") {
2416
2422
  return def.innerType._zod.run(payload, ctx);
@@ -2458,6 +2464,7 @@ function handleRefineResult(result, payload, input, inst) {
2458
2464
  }
2459
2465
  }
2460
2466
 
2467
+ var _a;
2461
2468
  class $ZodRegistry {
2462
2469
  constructor() {
2463
2470
  this._map = new WeakMap();
@@ -2507,7 +2514,8 @@ class $ZodRegistry {
2507
2514
  function registry() {
2508
2515
  return new $ZodRegistry();
2509
2516
  }
2510
- const globalRegistry = /*@__PURE__*/ registry();
2517
+ (_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
2518
+ const globalRegistry = globalThis.__zod_globalRegistry;
2511
2519
 
2512
2520
  function _string(Class, params) {
2513
2521
  return new Class({
@@ -2919,6 +2927,10 @@ function _toLowerCase() {
2919
2927
  function _toUpperCase() {
2920
2928
  return _overwrite((input) => input.toUpperCase());
2921
2929
  }
2930
+ // slugify
2931
+ function _slugify() {
2932
+ return _overwrite((input) => slugify(input));
2933
+ }
2922
2934
  function _array(Class, element, params) {
2923
2935
  return new Class({
2924
2936
  type: "array",
@@ -3162,6 +3174,7 @@ const _ZodString = /*@__PURE__*/ $constructor("_ZodString", (inst, def) => {
3162
3174
  inst.normalize = (...args) => inst.check(_normalize(...args));
3163
3175
  inst.toLowerCase = () => inst.check(_toLowerCase());
3164
3176
  inst.toUpperCase = () => inst.check(_toUpperCase());
3177
+ inst.slugify = () => inst.check(_slugify());
3165
3178
  });
3166
3179
  const ZodString = /*@__PURE__*/ $constructor("ZodString", (inst, def) => {
3167
3180
  $ZodString.init(inst, def);
@@ -4821,7 +4834,6 @@ class Route {
4821
4834
  */
4822
4835
  key;
4823
4836
  id;
4824
- share = false;
4825
4837
  run;
4826
4838
  nextRoute; // route to run after this route
4827
4839
  description;
@@ -5298,9 +5310,7 @@ class QueryRouter {
5298
5310
  ctx.query = { ...ctx.query, ...query, ...payload };
5299
5311
  ctx.state = { ...ctx?.state };
5300
5312
  ctx.throw = this.throw;
5301
- // put queryRouter to ctx
5302
- // TODO: 是否需要queryRouter,函数内部处理router路由执行,这应该是避免去内部去包含的功能过
5303
- ctx.queryRouter = this;
5313
+ ctx.app = this;
5304
5314
  ctx.call = this.call.bind(this);
5305
5315
  ctx.queryRoute = this.queryRoute.bind(this);
5306
5316
  ctx.index = 0;
@@ -5321,7 +5331,11 @@ class QueryRouter {
5321
5331
  async call(message, ctx) {
5322
5332
  let path = message.path;
5323
5333
  let key = message.key;
5324
- if (message.id) {
5334
+ // 优先 path + key
5335
+ if (path) {
5336
+ return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
5337
+ }
5338
+ else if (message.id) {
5325
5339
  const route = this.routes.find((r) => r.id === message.id);
5326
5340
  if (route) {
5327
5341
  path = route.path;
@@ -5332,9 +5346,6 @@ class QueryRouter {
5332
5346
  }
5333
5347
  return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
5334
5348
  }
5335
- else if (path) {
5336
- return await this.parse({ ...message, path, key }, { ...this.context, ...ctx });
5337
- }
5338
5349
  else {
5339
5350
  return { code: 404, body: null, message: 'Not found path' };
5340
5351
  }
@@ -5346,7 +5357,7 @@ class QueryRouter {
5346
5357
  * @returns
5347
5358
  */
5348
5359
  async queryRoute(message, ctx) {
5349
- const res = await this.parse(message, { ...this.context, ...ctx });
5360
+ const res = await this.call(message, { ...this.context, ...ctx });
5350
5361
  return {
5351
5362
  code: res.code,
5352
5363
  data: res.body,
@@ -5416,6 +5427,19 @@ class QueryRouter {
5416
5427
  hasRoute(path, key = '') {
5417
5428
  return this.routes.find((r) => r.path === path && r.key === key);
5418
5429
  }
5430
+ createRouteList(force = false) {
5431
+ const hasListRoute = this.hasRoute('route', 'list');
5432
+ if (!hasListRoute || force) {
5433
+ const listRoute = new Route('route', 'list', {
5434
+ description: '列出当前应用下的所有的路由信息',
5435
+ run: async (ctx) => {
5436
+ const list = this.getList();
5437
+ ctx.body = list;
5438
+ },
5439
+ });
5440
+ this.add(listRoute);
5441
+ }
5442
+ }
5419
5443
  /**
5420
5444
  * 等待程序运行, 获取到message的数据,就执行
5421
5445
  *
@@ -5425,6 +5449,10 @@ class QueryRouter {
5425
5449
  * -- .send
5426
5450
  */
5427
5451
  wait(params, opts) {
5452
+ const getList = opts?.getList ?? true;
5453
+ if (getList) {
5454
+ this.createRouteList();
5455
+ }
5428
5456
  return listenProcess({ app: this, params, ...opts });
5429
5457
  }
5430
5458
  }
@@ -5688,8 +5716,14 @@ function requireDist () {
5688
5716
  if (hasRequiredDist) return dist;
5689
5717
  hasRequiredDist = 1;
5690
5718
  Object.defineProperty(dist, "__esModule", { value: true });
5691
- dist.parse = parse;
5692
- dist.serialize = serialize;
5719
+ dist.parseCookie = parseCookie;
5720
+ dist.parse = parseCookie;
5721
+ dist.stringifyCookie = stringifyCookie;
5722
+ dist.stringifySetCookie = stringifySetCookie;
5723
+ dist.serialize = stringifySetCookie;
5724
+ dist.parseSetCookie = parseSetCookie;
5725
+ dist.stringifySetCookie = stringifySetCookie;
5726
+ dist.serialize = stringifySetCookie;
5693
5727
  /**
5694
5728
  * RegExp to match cookie-name in RFC 6265 sec 4.1.1
5695
5729
  * This refers out to the obsoleted definition of token in RFC 2616 sec 2.2
@@ -5750,6 +5784,10 @@ function requireDist () {
5750
5784
  * ; defined in RFC 5234 appendix B.1
5751
5785
  */
5752
5786
  const pathValueRegExp = /^[\u0020-\u003A\u003D-\u007E]*$/;
5787
+ /**
5788
+ * RegExp to match max-age-value in RFC 6265 sec 5.6.2
5789
+ */
5790
+ const maxAgeRegExp = /^-?\d+$/;
5753
5791
  const __toString = Object.prototype.toString;
5754
5792
  const NullObject = /* @__PURE__ */ (() => {
5755
5793
  const C = function () { };
@@ -5757,12 +5795,12 @@ function requireDist () {
5757
5795
  return C;
5758
5796
  })();
5759
5797
  /**
5760
- * Parse a cookie header.
5798
+ * Parse a `Cookie` header.
5761
5799
  *
5762
5800
  * Parse the given cookie header string into an object
5763
5801
  * The object has the various cookies as keys(names) => values
5764
5802
  */
5765
- function parse(str, options) {
5803
+ function parseCookie(str, options) {
5766
5804
  const obj = new NullObject();
5767
5805
  const len = str.length;
5768
5806
  // RFC 6265 sec 4.1.1, RFC 2616 2.2 defines a cookie name consists of one char minimum, plus '='.
@@ -5771,104 +5809,95 @@ function requireDist () {
5771
5809
  const dec = options?.decode || decode;
5772
5810
  let index = 0;
5773
5811
  do {
5774
- const eqIdx = str.indexOf("=", index);
5812
+ const eqIdx = eqIndex(str, index, len);
5775
5813
  if (eqIdx === -1)
5776
5814
  break; // No more cookie pairs.
5777
- const colonIdx = str.indexOf(";", index);
5778
- const endIdx = colonIdx === -1 ? len : colonIdx;
5815
+ const endIdx = endIndex(str, index, len);
5779
5816
  if (eqIdx > endIdx) {
5780
5817
  // backtrack on prior semicolon
5781
5818
  index = str.lastIndexOf(";", eqIdx - 1) + 1;
5782
5819
  continue;
5783
5820
  }
5784
- const keyStartIdx = startIndex(str, index, eqIdx);
5785
- const keyEndIdx = endIndex(str, eqIdx, keyStartIdx);
5786
- const key = str.slice(keyStartIdx, keyEndIdx);
5821
+ const key = valueSlice(str, index, eqIdx);
5787
5822
  // only assign once
5788
5823
  if (obj[key] === undefined) {
5789
- let valStartIdx = startIndex(str, eqIdx + 1, endIdx);
5790
- let valEndIdx = endIndex(str, endIdx, valStartIdx);
5791
- const value = dec(str.slice(valStartIdx, valEndIdx));
5792
- obj[key] = value;
5824
+ obj[key] = dec(valueSlice(str, eqIdx + 1, endIdx));
5793
5825
  }
5794
5826
  index = endIdx + 1;
5795
5827
  } while (index < len);
5796
5828
  return obj;
5797
5829
  }
5798
- function startIndex(str, index, max) {
5799
- do {
5800
- const code = str.charCodeAt(index);
5801
- if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
5802
- return index;
5803
- } while (++index < max);
5804
- return max;
5805
- }
5806
- function endIndex(str, index, min) {
5807
- while (index > min) {
5808
- const code = str.charCodeAt(--index);
5809
- if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
5810
- return index + 1;
5811
- }
5812
- return min;
5813
- }
5814
5830
  /**
5815
- * Serialize data into a cookie header.
5816
- *
5817
- * Serialize a name value pair into a cookie string suitable for
5818
- * http headers. An optional options object specifies cookie parameters.
5819
- *
5820
- * serialize('foo', 'bar', { httpOnly: true })
5821
- * => "foo=bar; httpOnly"
5831
+ * Stringifies an object into an HTTP `Cookie` header.
5822
5832
  */
5823
- function serialize(name, val, options) {
5833
+ function stringifyCookie(cookie, options) {
5834
+ const enc = options?.encode || encodeURIComponent;
5835
+ const cookieStrings = [];
5836
+ for (const name of Object.keys(cookie)) {
5837
+ const val = cookie[name];
5838
+ if (val === undefined)
5839
+ continue;
5840
+ if (!cookieNameRegExp.test(name)) {
5841
+ throw new TypeError(`cookie name is invalid: ${name}`);
5842
+ }
5843
+ const value = enc(val);
5844
+ if (!cookieValueRegExp.test(value)) {
5845
+ throw new TypeError(`cookie val is invalid: ${val}`);
5846
+ }
5847
+ cookieStrings.push(`${name}=${value}`);
5848
+ }
5849
+ return cookieStrings.join("; ");
5850
+ }
5851
+ function stringifySetCookie(_name, _val, _opts) {
5852
+ const cookie = typeof _name === "object"
5853
+ ? _name
5854
+ : { ..._opts, name: _name, value: String(_val) };
5855
+ const options = typeof _val === "object" ? _val : _opts;
5824
5856
  const enc = options?.encode || encodeURIComponent;
5825
- if (!cookieNameRegExp.test(name)) {
5826
- throw new TypeError(`argument name is invalid: ${name}`);
5857
+ if (!cookieNameRegExp.test(cookie.name)) {
5858
+ throw new TypeError(`argument name is invalid: ${cookie.name}`);
5827
5859
  }
5828
- const value = enc(val);
5860
+ const value = cookie.value ? enc(cookie.value) : "";
5829
5861
  if (!cookieValueRegExp.test(value)) {
5830
- throw new TypeError(`argument val is invalid: ${val}`);
5862
+ throw new TypeError(`argument val is invalid: ${cookie.value}`);
5831
5863
  }
5832
- let str = name + "=" + value;
5833
- if (!options)
5834
- return str;
5835
- if (options.maxAge !== undefined) {
5836
- if (!Number.isInteger(options.maxAge)) {
5837
- throw new TypeError(`option maxAge is invalid: ${options.maxAge}`);
5864
+ let str = cookie.name + "=" + value;
5865
+ if (cookie.maxAge !== undefined) {
5866
+ if (!Number.isInteger(cookie.maxAge)) {
5867
+ throw new TypeError(`option maxAge is invalid: ${cookie.maxAge}`);
5838
5868
  }
5839
- str += "; Max-Age=" + options.maxAge;
5869
+ str += "; Max-Age=" + cookie.maxAge;
5840
5870
  }
5841
- if (options.domain) {
5842
- if (!domainValueRegExp.test(options.domain)) {
5843
- throw new TypeError(`option domain is invalid: ${options.domain}`);
5871
+ if (cookie.domain) {
5872
+ if (!domainValueRegExp.test(cookie.domain)) {
5873
+ throw new TypeError(`option domain is invalid: ${cookie.domain}`);
5844
5874
  }
5845
- str += "; Domain=" + options.domain;
5875
+ str += "; Domain=" + cookie.domain;
5846
5876
  }
5847
- if (options.path) {
5848
- if (!pathValueRegExp.test(options.path)) {
5849
- throw new TypeError(`option path is invalid: ${options.path}`);
5877
+ if (cookie.path) {
5878
+ if (!pathValueRegExp.test(cookie.path)) {
5879
+ throw new TypeError(`option path is invalid: ${cookie.path}`);
5850
5880
  }
5851
- str += "; Path=" + options.path;
5881
+ str += "; Path=" + cookie.path;
5852
5882
  }
5853
- if (options.expires) {
5854
- if (!isDate(options.expires) ||
5855
- !Number.isFinite(options.expires.valueOf())) {
5856
- throw new TypeError(`option expires is invalid: ${options.expires}`);
5883
+ if (cookie.expires) {
5884
+ if (!isDate(cookie.expires) || !Number.isFinite(cookie.expires.valueOf())) {
5885
+ throw new TypeError(`option expires is invalid: ${cookie.expires}`);
5857
5886
  }
5858
- str += "; Expires=" + options.expires.toUTCString();
5887
+ str += "; Expires=" + cookie.expires.toUTCString();
5859
5888
  }
5860
- if (options.httpOnly) {
5889
+ if (cookie.httpOnly) {
5861
5890
  str += "; HttpOnly";
5862
5891
  }
5863
- if (options.secure) {
5892
+ if (cookie.secure) {
5864
5893
  str += "; Secure";
5865
5894
  }
5866
- if (options.partitioned) {
5895
+ if (cookie.partitioned) {
5867
5896
  str += "; Partitioned";
5868
5897
  }
5869
- if (options.priority) {
5870
- const priority = typeof options.priority === "string"
5871
- ? options.priority.toLowerCase()
5898
+ if (cookie.priority) {
5899
+ const priority = typeof cookie.priority === "string"
5900
+ ? cookie.priority.toLowerCase()
5872
5901
  : undefined;
5873
5902
  switch (priority) {
5874
5903
  case "low":
@@ -5881,13 +5910,13 @@ function requireDist () {
5881
5910
  str += "; Priority=High";
5882
5911
  break;
5883
5912
  default:
5884
- throw new TypeError(`option priority is invalid: ${options.priority}`);
5913
+ throw new TypeError(`option priority is invalid: ${cookie.priority}`);
5885
5914
  }
5886
5915
  }
5887
- if (options.sameSite) {
5888
- const sameSite = typeof options.sameSite === "string"
5889
- ? options.sameSite.toLowerCase()
5890
- : options.sameSite;
5916
+ if (cookie.sameSite) {
5917
+ const sameSite = typeof cookie.sameSite === "string"
5918
+ ? cookie.sameSite.toLowerCase()
5919
+ : cookie.sameSite;
5891
5920
  switch (sameSite) {
5892
5921
  case true:
5893
5922
  case "strict":
@@ -5900,11 +5929,121 @@ function requireDist () {
5900
5929
  str += "; SameSite=None";
5901
5930
  break;
5902
5931
  default:
5903
- throw new TypeError(`option sameSite is invalid: ${options.sameSite}`);
5932
+ throw new TypeError(`option sameSite is invalid: ${cookie.sameSite}`);
5904
5933
  }
5905
5934
  }
5906
5935
  return str;
5907
5936
  }
5937
+ /**
5938
+ * Deserialize a `Set-Cookie` header into an object.
5939
+ *
5940
+ * deserialize('foo=bar; httpOnly')
5941
+ * => { name: 'foo', value: 'bar', httpOnly: true }
5942
+ */
5943
+ function parseSetCookie(str, options) {
5944
+ const dec = options?.decode || decode;
5945
+ const len = str.length;
5946
+ const endIdx = endIndex(str, 0, len);
5947
+ const eqIdx = eqIndex(str, 0, endIdx);
5948
+ const setCookie = eqIdx === -1
5949
+ ? { name: "", value: dec(valueSlice(str, 0, endIdx)) }
5950
+ : {
5951
+ name: valueSlice(str, 0, eqIdx),
5952
+ value: dec(valueSlice(str, eqIdx + 1, endIdx)),
5953
+ };
5954
+ let index = endIdx + 1;
5955
+ while (index < len) {
5956
+ const endIdx = endIndex(str, index, len);
5957
+ const eqIdx = eqIndex(str, index, endIdx);
5958
+ const attr = eqIdx === -1
5959
+ ? valueSlice(str, index, endIdx)
5960
+ : valueSlice(str, index, eqIdx);
5961
+ const val = eqIdx === -1 ? undefined : valueSlice(str, eqIdx + 1, endIdx);
5962
+ switch (attr.toLowerCase()) {
5963
+ case "httponly":
5964
+ setCookie.httpOnly = true;
5965
+ break;
5966
+ case "secure":
5967
+ setCookie.secure = true;
5968
+ break;
5969
+ case "partitioned":
5970
+ setCookie.partitioned = true;
5971
+ break;
5972
+ case "domain":
5973
+ setCookie.domain = val;
5974
+ break;
5975
+ case "path":
5976
+ setCookie.path = val;
5977
+ break;
5978
+ case "max-age":
5979
+ if (val && maxAgeRegExp.test(val))
5980
+ setCookie.maxAge = Number(val);
5981
+ break;
5982
+ case "expires":
5983
+ if (!val)
5984
+ break;
5985
+ const date = new Date(val);
5986
+ if (Number.isFinite(date.valueOf()))
5987
+ setCookie.expires = date;
5988
+ break;
5989
+ case "priority":
5990
+ if (!val)
5991
+ break;
5992
+ const priority = val.toLowerCase();
5993
+ if (priority === "low" ||
5994
+ priority === "medium" ||
5995
+ priority === "high") {
5996
+ setCookie.priority = priority;
5997
+ }
5998
+ break;
5999
+ case "samesite":
6000
+ if (!val)
6001
+ break;
6002
+ const sameSite = val.toLowerCase();
6003
+ if (sameSite === "lax" ||
6004
+ sameSite === "strict" ||
6005
+ sameSite === "none") {
6006
+ setCookie.sameSite = sameSite;
6007
+ }
6008
+ break;
6009
+ }
6010
+ index = endIdx + 1;
6011
+ }
6012
+ return setCookie;
6013
+ }
6014
+ /**
6015
+ * Find the `;` character between `min` and `len` in str.
6016
+ */
6017
+ function endIndex(str, min, len) {
6018
+ const index = str.indexOf(";", min);
6019
+ return index === -1 ? len : index;
6020
+ }
6021
+ /**
6022
+ * Find the `=` character between `min` and `max` in str.
6023
+ */
6024
+ function eqIndex(str, min, max) {
6025
+ const index = str.indexOf("=", min);
6026
+ return index < max ? index : -1;
6027
+ }
6028
+ /**
6029
+ * Slice out a value between startPod to max.
6030
+ */
6031
+ function valueSlice(str, min, max) {
6032
+ let start = min;
6033
+ let end = max;
6034
+ do {
6035
+ const code = str.charCodeAt(start);
6036
+ if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
6037
+ break;
6038
+ } while (++start < end);
6039
+ while (end > start) {
6040
+ const code = str.charCodeAt(end - 1);
6041
+ if (code !== 0x20 /* */ && code !== 0x09 /* \t */)
6042
+ break;
6043
+ end--;
6044
+ }
6045
+ return str.slice(start, end);
6046
+ }
5908
6047
  /**
5909
6048
  * URL-decode string value. Optimized to skip native call when no %.
5910
6049
  */
@@ -5928,7 +6067,7 @@ function requireDist () {
5928
6067
  return dist;
5929
6068
  }
5930
6069
 
5931
- var distExports = requireDist();
6070
+ var distExports = /*@__PURE__*/ requireDist();
5932
6071
 
5933
6072
  // 实现函数
5934
6073
  function createHandleCtx(req, res) {
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.32",
4
+ "version": "0.0.34",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -21,8 +21,8 @@
21
21
  "author": "abearxiong",
22
22
  "license": "MIT",
23
23
  "devDependencies": {
24
- "@kevisual/local-proxy": "^0.0.6",
25
- "@kevisual/query": "^0.0.29",
24
+ "@kevisual/local-proxy": "^0.0.8",
25
+ "@kevisual/query": "^0.0.31",
26
26
  "@rollup/plugin-alias": "^6.0.0",
27
27
  "@rollup/plugin-commonjs": "29.0.0",
28
28
  "@rollup/plugin-node-resolve": "^16.0.3",
@@ -32,18 +32,18 @@
32
32
  "@types/send": "^1.2.1",
33
33
  "@types/ws": "^8.18.1",
34
34
  "@types/xml2js": "^0.4.14",
35
- "cookie": "^1.0.2",
35
+ "cookie": "^1.1.1",
36
36
  "lodash-es": "^4.17.21",
37
37
  "nanoid": "^5.1.6",
38
- "rollup": "^4.53.2",
39
- "rollup-plugin-dts": "^6.2.3",
38
+ "rollup": "^4.53.3",
39
+ "rollup-plugin-dts": "^6.3.0",
40
40
  "ts-loader": "^9.5.4",
41
41
  "ts-node": "^10.9.2",
42
42
  "tslib": "^2.8.1",
43
43
  "typescript": "^5.9.3",
44
44
  "ws": "npm:@kevisual/ws",
45
45
  "xml2js": "^0.6.2",
46
- "zod": "^4.1.12"
46
+ "zod": "^4.1.13"
47
47
  },
48
48
  "repository": {
49
49
  "type": "git",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "dependencies": {
53
53
  "path-to-regexp": "^8.3.0",
54
- "selfsigned": "^4.0.0",
54
+ "selfsigned": "^5.2.0",
55
55
  "send": "^1.2.0"
56
56
  },
57
57
  "publishConfig": {